diff --git a/GasolineTanker/GasolineTanker/DrawningObjectTanker.cs b/GasolineTanker/GasolineTanker/DrawningObjectTanker.cs index 54c33fe..cf69564 100644 --- a/GasolineTanker/GasolineTanker/DrawningObjectTanker.cs +++ b/GasolineTanker/GasolineTanker/DrawningObjectTanker.cs @@ -38,5 +38,58 @@ namespace GasolineTanker } public string GetInfo() => _Tanker?.GetDataForSave(); public static IDrawningObject Create(string data) => new DrawningObjectTanker(data.CreateDrawningTanker()); + + public bool Equals(IDrawningObject? other) + { + { + if (other == null) + { + return false; + } + var otherTanker = other as DrawningObjectTanker; + if (otherTanker == null) + { + return false; + } + var tanker = _Tanker.Tanker; + var otherTankerTanker = otherTanker._Tanker.Tanker; + if (tanker.GetType().Name != otherTankerTanker.GetType().Name) + { + return false; + } + if (tanker.Speed != otherTankerTanker.Speed) + { + return false; + } + if (tanker.Weight != otherTankerTanker.Weight) + { + return false; + } + if (tanker.BodyColor != otherTankerTanker.BodyColor) + { + return false; + } + if (tanker is EntityGasolineTanker gasolinetanker && otherTankerTanker is EntityGasolineTanker otherGasolineTanker) + { + if (gasolinetanker.DopColor != otherGasolineTanker.DopColor) + { + return false; + } + if (gasolinetanker.Cabin != otherGasolineTanker.Cabin) + { + return false; + } + if (gasolinetanker.Signal != otherGasolineTanker.Signal) + { + return false; + } + if (gasolinetanker.BenzoBack != otherGasolineTanker.BenzoBack) + { + return false; + } + } + return true; + } + } } } diff --git a/GasolineTanker/GasolineTanker/IDrawningObject.cs b/GasolineTanker/GasolineTanker/IDrawningObject.cs index 569abab..7c0bcc7 100644 --- a/GasolineTanker/GasolineTanker/IDrawningObject.cs +++ b/GasolineTanker/GasolineTanker/IDrawningObject.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace GasolineTanker { - internal interface IDrawningObject + internal interface IDrawningObject : IEquatable { /// /// Шаг перемещения объекта diff --git a/GasolineTanker/GasolineTanker/MapWithSetTankersGeneric.cs b/GasolineTanker/GasolineTanker/MapWithSetTankersGeneric.cs index aa02826..60b9fcd 100644 --- a/GasolineTanker/GasolineTanker/MapWithSetTankersGeneric.cs +++ b/GasolineTanker/GasolineTanker/MapWithSetTankersGeneric.cs @@ -1,7 +1,7 @@ namespace GasolineTanker { internal class MapWithSetTankersGeneric - where T : class, IDrawningObject + where T : class, IDrawningObject,IEquatable where U : AbstractMap { private readonly int _pictureWidth; diff --git a/GasolineTanker/GasolineTanker/SetTankersGeneric.cs b/GasolineTanker/GasolineTanker/SetTankersGeneric.cs index b575010..c1bb1f7 100644 --- a/GasolineTanker/GasolineTanker/SetTankersGeneric.cs +++ b/GasolineTanker/GasolineTanker/SetTankersGeneric.cs @@ -1,7 +1,7 @@ namespace GasolineTanker { internal class SetTankersGeneric - where T : class + where T : class, IEquatable { private readonly List _places; public int Count => _places.Count; @@ -20,6 +20,10 @@ public int Insert(T tanker, int position) { + if (_places.Contains(tanker)) + { + return -1; + } if (Count == _maxCount) { throw new StorageOverflowException(_maxCount);