From e27ebecf0ebb0c8a5a4c0f5e3f221bcc6e186349 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Wed, 30 Nov 2022 17:36:00 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20=D1=88?= =?UTF-8?q?=D0=B0=D0=B3:=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D1=83=D0=BD=D0=B8=D0=BA=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D0=B8=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs | 52 ++++++++++++++++++- ArmoredCar/ArmoredCar/IDrawningObject.cs | 2 +- .../MapWithSetArmoredCarsGeneric.cs | 2 +- .../ArmoredCar/SetArmoredCarsGeneric.cs | 10 +++- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs b/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs index 22effca..87f94bf 100644 --- a/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs +++ b/ArmoredCar/ArmoredCar/DrawningObjectArmCar.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.DirectoryServices.ActiveDirectory; using System.Drawing; using System.Linq; using System.Text; @@ -34,7 +35,54 @@ namespace ArmoredCar _armCar.DrawTransport(g); } public string GetInfo() => _armCar?.GetDataForSave(); - public static IDrawningObject Create(string data) => new - DrawningObjectArmCar(data.CreateDrawningArmoredCar()); + public static IDrawningObject Create(string data) => new DrawningObjectArmCar(data.CreateDrawningArmoredCar()); + + public bool Equals(IDrawningObject? other) + { + if (other == null) + { + return false; + } + var otherCar = other as DrawningObjectArmCar; + if (otherCar == null) + { + return false; + } + var car = _armCar.ArmoredCar; + var otherCarCar = otherCar._armCar.ArmoredCar; + + if (car.GetType() != otherCarCar.GetType()) + return false; + + if (car.Speed != otherCarCar.Speed) + { + return false; + } + if (car.Weight != otherCarCar.Weight) + { + return false; + } + if (car.BodyColor != otherCarCar.BodyColor) + { + return false; + } + if (car is EntityTank tank && otherCarCar is EntityTank otherTank) + { + if (tank.DopColor != otherTank.DopColor) + { + return false; + } + if (tank.TowerWeapon != otherTank.TowerWeapon) + { + return false; + } + if (tank.AMachineGun != otherTank.AMachineGun) + { + return false; + } + } + return true; + } + } } diff --git a/ArmoredCar/ArmoredCar/IDrawningObject.cs b/ArmoredCar/ArmoredCar/IDrawningObject.cs index 4e97bfa..d7ae519 100644 --- a/ArmoredCar/ArmoredCar/IDrawningObject.cs +++ b/ArmoredCar/ArmoredCar/IDrawningObject.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace ArmoredCar { - internal interface IDrawningObject + internal interface IDrawningObject : IEquatable { /// /// Шаг перемещения объекта diff --git a/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs b/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs index e4a7e64..db64685 100644 --- a/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs +++ b/ArmoredCar/ArmoredCar/MapWithSetArmoredCarsGeneric.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace ArmoredCar { internal class MapWithSetArmoredCarsGeneric - where T : class, IDrawningObject + where T : class, IDrawningObject, IEquatable where U : AbstractMap { /// diff --git a/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs b/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs index 6d63325..1aef614 100644 --- a/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs +++ b/ArmoredCar/ArmoredCar/SetArmoredCarsGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace ArmoredCar { internal class SetArmoredCarsGeneric - where T : class + where T : class, IEquatable { /// /// Список объектов, которые храним @@ -43,13 +43,19 @@ namespace ArmoredCar /// Позиция /// public int Insert(T armoredCar, int position) - { + { if (Count >= _maxCount) throw new StorageOverflowException(Count); if (position < 0 || position >= _maxCount) return -1; + // проверка на уникальность + if (_places.Contains(armoredCar)) + { + return -1; + } + _places.Insert(position, armoredCar); return position; }