сравнение обьектов
This commit is contained in:
parent
931ccb2599
commit
baf7a2c1b3
@ -42,5 +42,31 @@ namespace WinFormsApp1
|
|||||||
{
|
{
|
||||||
_tractor.DrawEntity(g);
|
_tractor.DrawEntity(g);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Equals(IDrawningObject? other)
|
||||||
|
{
|
||||||
|
if (other is not DrawningObjectTractor otherTraktor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var entity = _tractor.Tractor;
|
||||||
|
var otherEntity = otherTraktor._tractor.Tractor;
|
||||||
|
if (entity.GetType() != otherEntity.GetType() ||
|
||||||
|
entity.Speed != otherEntity.Speed ||
|
||||||
|
entity.Weight != otherEntity.Weight ||
|
||||||
|
entity.BodyColor != otherEntity.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (entity is MultiTraktor entityTraktorDOP &&
|
||||||
|
otherEntity is MultiTraktor otherEntityTraktorDOP && (
|
||||||
|
entityTraktorDOP.dopAhead != otherEntityTraktorDOP.dopAhead ||
|
||||||
|
entityTraktorDOP.DopColor != otherEntityTraktorDOP.DopColor ||
|
||||||
|
entityTraktorDOP.dopBehind != otherEntityTraktorDOP.dopBehind))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace WinFormsApp1
|
namespace WinFormsApp1
|
||||||
{
|
{
|
||||||
interface IDrawningObject
|
interface IDrawningObject : IEquatable<IDrawningObject>
|
||||||
{
|
{
|
||||||
/// Шаг перемещения объекта
|
/// Шаг перемещения объекта
|
||||||
public float Step { get; }
|
public float Step { get; }
|
||||||
|
@ -8,7 +8,7 @@ using System.Threading.Tasks;
|
|||||||
namespace WinFormsApp1
|
namespace WinFormsApp1
|
||||||
{
|
{
|
||||||
internal class MapWithSetTraktorGeneric<T, U>
|
internal class MapWithSetTraktorGeneric<T, U>
|
||||||
where T : class, IDrawningObject
|
where T : class, IDrawningObject, IEquatable<T>
|
||||||
where U : AbstractMap
|
where U : AbstractMap
|
||||||
{
|
{
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
namespace WinFormsApp1
|
namespace WinFormsApp1
|
||||||
{
|
{
|
||||||
internal class SetTraktorGeneric<T>
|
internal class SetTraktorGeneric<T>
|
||||||
where T : class
|
where T : class, IEquatable<T>
|
||||||
{
|
{
|
||||||
private readonly List<T> _places;
|
private readonly List<T> _places;
|
||||||
public int Count => _places.Count;
|
public int Count => _places.Count;
|
||||||
|
Loading…
Reference in New Issue
Block a user