From aa244afca71e7fa77a65cfafe9612366100b7360 Mon Sep 17 00:00:00 2001 From: Semka Date: Mon, 12 Dec 2022 23:46:17 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GasolineTanker/DrawningObjectTanker.cs | 53 +++++++++++++++++++ .../GasolineTanker/IDrawningObject.cs | 2 +- .../MapWithSetTankersGeneric.cs | 2 +- .../GasolineTanker/SetTankersGeneric.cs | 6 ++- 4 files changed, 60 insertions(+), 3 deletions(-) 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);