diff --git a/WinFormsApp1/DrawningObjectTraktor.cs b/WinFormsApp1/DrawningObjectTraktor.cs index 66c5490..6fee5da 100644 --- a/WinFormsApp1/DrawningObjectTraktor.cs +++ b/WinFormsApp1/DrawningObjectTraktor.cs @@ -42,5 +42,31 @@ namespace WinFormsApp1 { _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; + } } } diff --git a/WinFormsApp1/IDrawningObject.cs b/WinFormsApp1/IDrawningObject.cs index 06e1b86..531997b 100644 --- a/WinFormsApp1/IDrawningObject.cs +++ b/WinFormsApp1/IDrawningObject.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace WinFormsApp1 { - interface IDrawningObject + interface IDrawningObject : IEquatable { /// Шаг перемещения объекта public float Step { get; } diff --git a/WinFormsApp1/MapWithSetTraktorGeneric.cs b/WinFormsApp1/MapWithSetTraktorGeneric.cs index e7ebc34..6238ee5 100644 --- a/WinFormsApp1/MapWithSetTraktorGeneric.cs +++ b/WinFormsApp1/MapWithSetTraktorGeneric.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace WinFormsApp1 { internal class MapWithSetTraktorGeneric - where T : class, IDrawningObject + where T : class, IDrawningObject, IEquatable where U : AbstractMap { private readonly int _pictureWidth; diff --git a/WinFormsApp1/SetTraktorGeneric.cs b/WinFormsApp1/SetTraktorGeneric.cs index 87dcc16..cc72f1a 100644 --- a/WinFormsApp1/SetTraktorGeneric.cs +++ b/WinFormsApp1/SetTraktorGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace WinFormsApp1 { internal class SetTraktorGeneric - where T : class + where T : class, IEquatable { private readonly List _places; public int Count => _places.Count;