From 6a6abe240fe1eb741d7a9d4999d9fb4e5e295ddb Mon Sep 17 00:00:00 2001 From: crum61kg Date: Tue, 14 Feb 2023 23:21:28 +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 --- WarmlyShip/WarmlyShip/DrawningObjectShip.cs | 30 +++++++++++++++++++ WarmlyShip/WarmlyShip/IDrawningObject.cs | 2 +- .../WarmlyShip/MapWithSetWarmlyShipGeneric.cs | 2 +- WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs | 4 ++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/WarmlyShip/WarmlyShip/DrawningObjectShip.cs b/WarmlyShip/WarmlyShip/DrawningObjectShip.cs index 24e6ff5..80b06bb 100644 --- a/WarmlyShip/WarmlyShip/DrawningObjectShip.cs +++ b/WarmlyShip/WarmlyShip/DrawningObjectShip.cs @@ -41,5 +41,35 @@ namespace WarmlyShip public static IDrawningObject Create(string data) => new DrawningObjectShip(data.CreateDrawningShip()); + + public bool Equals(IDrawningObject? other) + { + if (other == null) + { + return false; + } + var otherShip = other as DrawningObjectShip; + if (otherShip == null) + { + return false; + } + var ship = _ship.Ship; + var otherShipShip = otherShip._ship.Ship; + if (ship.Speed != otherShipShip.Speed) + { + return false; + } + if (ship.Weight != otherShipShip.Weight) + { + return false; + } + if (ship.BodyColor != otherShipShip.BodyColor) + { + return false; + } + // TODO доделать проверки в случае продвинутого объекта + return true; + + } } } diff --git a/WarmlyShip/WarmlyShip/IDrawningObject.cs b/WarmlyShip/WarmlyShip/IDrawningObject.cs index cbbd689..c7ea0dd 100644 --- a/WarmlyShip/WarmlyShip/IDrawningObject.cs +++ b/WarmlyShip/WarmlyShip/IDrawningObject.cs @@ -9,7 +9,7 @@ namespace WarmlyShip /// /// Интерфейс для работы с объектом, прорисовываемым на форме /// - internal interface IDrawningObject + internal interface IDrawningObject : IEquatable { /// /// Шаг перемещения объекта diff --git a/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs index 9a6e6b3..abf3dbb 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs @@ -12,7 +12,7 @@ namespace WarmlyShip /// /// internal class MapWithSetWarmlyShipGeneric - where T : class, IDrawningObject + where T : class, IDrawningObject, IEnumerable where U : AbstractMap { /// diff --git a/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs b/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs index 6bdff72..c5cfa3a 100644 --- a/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs @@ -11,7 +11,7 @@ namespace WarmlyShip /// /// internal class SetWarmlyShipGeneric - where T : class + where T : class, IEnumerable { /// /// Список объектов, которые храним @@ -51,6 +51,8 @@ namespace WarmlyShip /// public int Insert(T ship, int position) { + //TODO проверка на уникальность + if (Count >= _maxCount) { throw new StorageOverflowException(Count);