From e1515f7771916881fa7eafe51fd99a4b4e28f0a1 Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Fri, 2 Dec 2022 12:58:56 +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?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/DrawningObjectPlane.cs | 36 ++++++++++++++++++++++++ Airbus/Airbus/IDrawningObject.cs | 2 +- Airbus/Airbus/MapWithSetPlanesGeneric.cs | 2 +- Airbus/Airbus/SetPlanesGeneric.cs | 4 ++- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/Airbus/Airbus/DrawningObjectPlane.cs b/Airbus/Airbus/DrawningObjectPlane.cs index 695be57..a694d2d 100644 --- a/Airbus/Airbus/DrawningObjectPlane.cs +++ b/Airbus/Airbus/DrawningObjectPlane.cs @@ -46,5 +46,41 @@ namespace Airbus public static IDrawningObject Create(string data) => new DrawningObjectPlane(data.CreateDrawningPlane()); + public bool Equals(IDrawningObject? other) + { + if(other == null) + { + return false; + } + + var otherPlane = other as DrawningObjectPlane; + + if(otherPlane == null) + { + return false; + } + + var plane = _airbus.Airbus; + var otherPlanePlane = otherPlane._airbus.Airbus; + + if(plane.Speed != otherPlanePlane.Speed) + { + return false; + } + + if(plane.Weight != otherPlanePlane.Weight) + { + return false; + } + + if(plane.CorpusColor != otherPlanePlane.CorpusColor) + { + return false; + } + + //TODO доделать проверки на случай продвинутого объекта + + return true; + } } } diff --git a/Airbus/Airbus/IDrawningObject.cs b/Airbus/Airbus/IDrawningObject.cs index ae2dff5..076a89c 100644 --- a/Airbus/Airbus/IDrawningObject.cs +++ b/Airbus/Airbus/IDrawningObject.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Airbus { - internal interface IDrawningObject + internal interface IDrawningObject : IEquatable { //шаг перемещения объекта public float Step { get; } diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 4917a05..d72eb6d 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -10,7 +10,7 @@ namespace Airbus { //карта с набором объектов под неё internal class MapWithSetPlanesGeneric - where T : class, IDrawningObject + where T : class, IDrawningObject, IEquatable where U : AbstractMap { //ширина окна отрисовки diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 70d5559..8c8edac 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace Airbus { internal class SetPlanesGeneric - where T: class + where T: class, IEquatable { //список объектов, которые храним private readonly List _places; @@ -29,6 +29,8 @@ namespace Airbus //добавление объекта в набор public int Insert(T plane) { + //TODO проверка на уникальность элемента в списке, делаем перед сообщением о переполнении + if (Count == _maxCount) { throw new StorageOverflowException(_maxCount);