From 94a7aca855f5c8969daaedbbc680b470eb64e4f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Tue, 13 Dec 2022 17:12:38 +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 --- AirBomber/AirBomber/DrawningObjectBomber.cs | 31 +++++++++++++++++++ AirBomber/AirBomber/IDrawningObject.cs | 2 +- .../AirBomber/MapWithSetAirBomberGeneric.cs | 2 +- AirBomber/AirBomber/SetAirBomberGeneric.cs | 3 +- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/AirBomber/AirBomber/DrawningObjectBomber.cs b/AirBomber/AirBomber/DrawningObjectBomber.cs index b49ee71..e1d1679 100644 --- a/AirBomber/AirBomber/DrawningObjectBomber.cs +++ b/AirBomber/AirBomber/DrawningObjectBomber.cs @@ -40,5 +40,36 @@ namespace AirBomber public string GetInfo() => _airBomber?.GetDataForSave(); public static IDrawningObject Create(string data) => new DrawningObjectBomber(data.CreateDrawningAirBomber()); + + public bool Equals(IDrawningObject? other) + { + if (other == null) + { + return false; + } + var otherBomber = other as DrawningObjectBomber; + if (otherBomber == null) + { + return false; + } + var airBomber = _airBomber.AirBomber; + var otherBomberBomber = otherBomber._airBomber.AirBomber; + if (airBomber.Speed != otherBomberBomber.Speed) + { + return false; + } + if (airBomber.Weight != otherBomberBomber.Weight) + { + return false; + } + if (airBomber.BodyColor != otherBomberBomber.BodyColor) + { + return false; + } + + //TODO + + return true; + } } } diff --git a/AirBomber/AirBomber/IDrawningObject.cs b/AirBomber/AirBomber/IDrawningObject.cs index a32cb67..222f745 100644 --- a/AirBomber/AirBomber/IDrawningObject.cs +++ b/AirBomber/AirBomber/IDrawningObject.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AirBomber { - internal interface IDrawningObject + internal interface IDrawningObject : IEquatable { public float Step { get; } diff --git a/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs b/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs index 8e9e2ef..33bd31d 100644 --- a/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirBomberGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace AirBomber { internal class MapWithSetAirBomberGeneric - where T : class, IDrawningObject + where T : class, IDrawningObject, IEquatable where U : AbstractMap { private readonly int _pictureWidth; diff --git a/AirBomber/AirBomber/SetAirBomberGeneric.cs b/AirBomber/AirBomber/SetAirBomberGeneric.cs index 4cac74d..283664e 100644 --- a/AirBomber/AirBomber/SetAirBomberGeneric.cs +++ b/AirBomber/AirBomber/SetAirBomberGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace AirBomber { internal class SetAirBomberGeneric - where T : class + where T : class, IEquatable { private readonly List _places; @@ -28,6 +28,7 @@ namespace AirBomber public int Insert(T airBomber, int position) { + //TODO проверка на уникальность if (_places.Count >= _maxCount) { throw new StorageOverflowException(_maxCount);