From 165d0d1392a93d0556d94b7e0914506b76723235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Sat, 17 Dec 2022 17:57:44 +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?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Stormtrooper/DrawningObjectStorm.cs | 55 +++++++++++++++++++ Stormtrooper/Stormtrooper/IDrawningObject.cs | 2 +- .../Stormtrooper/SetStormtroopersGeneric.cs | 19 ++++++- 3 files changed, 74 insertions(+), 2 deletions(-) diff --git a/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs b/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs index 16e65bd..7ad63c4 100644 --- a/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs +++ b/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs @@ -14,6 +14,7 @@ namespace Stormtrooper _storm = storm; } public float Step => _storm?.Storm?.Step ?? 0; + public Drawning GetStormtrooper => _storm; public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { return _storm?.GetCurrentPosition() ?? default; @@ -35,5 +36,59 @@ namespace Stormtrooper public string GetInfo() => _storm?.GetDataForSave(); public static IDrawningObject Create(string data) => new DrawningObjectStorm(data.CreateDrawningStormtrooper()); + public bool Equals(IDrawningObject? other) + { + if (other == null) + { + return false; + } + var otherStorm = other as DrawningObjectStorm; + if (otherStorm == null) + { + return false; + } + var storm = _storm.Storm; + var otherStormStorm = otherStorm._storm.Storm; + if (storm.Speed != otherStormStorm.Speed) + { + return false; + } + if (storm.Weight != otherStormStorm.Weight) + { + return false; + } + if (storm.BodyColor != otherStormStorm.BodyColor) + { + return false; + } + if (storm is EntityMilitaryStormtrooper milstorm) + { + if (other is not EntityMilitaryStormtrooper othermilstorm) + { + return false; + } + + if (milstorm.DopColor != othermilstorm.DopColor) + { + return false; + } + + if (milstorm.BodyKit != othermilstorm.BodyKit) + { + return false; + } + + if (milstorm.Rocket != othermilstorm.Rocket) + { + return false; + } + + if (milstorm.SportLine != othermilstorm.SportLine) + { + return false; + } + } + return true; + } } } diff --git a/Stormtrooper/Stormtrooper/IDrawningObject.cs b/Stormtrooper/Stormtrooper/IDrawningObject.cs index 539dbd0..37c828c 100644 --- a/Stormtrooper/Stormtrooper/IDrawningObject.cs +++ b/Stormtrooper/Stormtrooper/IDrawningObject.cs @@ -9,7 +9,7 @@ namespace Stormtrooper /// /// Интерфейс для работы с объектом, прорисовываемым на форме /// - internal interface IDrawningObject + internal interface IDrawningObject : IEquatable { /// /// Шаг перемещения объекта diff --git a/Stormtrooper/Stormtrooper/SetStormtroopersGeneric.cs b/Stormtrooper/Stormtrooper/SetStormtroopersGeneric.cs index 35dc27a..a746fd6 100644 --- a/Stormtrooper/Stormtrooper/SetStormtroopersGeneric.cs +++ b/Stormtrooper/Stormtrooper/SetStormtroopersGeneric.cs @@ -11,7 +11,7 @@ namespace Stormtrooper /// /// internal class SetStormtroopersGeneric - where T : class + where T : class, IEquatable { /// /// Список объектов, которые храним @@ -49,6 +49,10 @@ namespace Stormtrooper /// public int Insert(T stormtrooper, int position) { + if (_places.Contains(stormtrooper)) + { + throw new ArgumentException("Такой самолёт уже есть"); + } if (position < 0 || position >= _maxCount) throw new StorageOverflowException(_maxCount); if (_places.Count >= _maxCount) throw new StorageOverflowException(_maxCount); @@ -105,5 +109,18 @@ namespace Stormtrooper } } } + /// + /// Сортировка набора объектов + /// + /// + public void SortSet(IComparer comparer) + { + if (comparer == null) + { + return; + } + _places.Sort(comparer); + } + } }