From a145a52010275dab54995fbb7bdd08ac47abde2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Fri, 2 Dec 2022 20:40:53 +0300 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 --- .../AirPlaneWithRadar/DrawingObjectPlane.cs | 30 +++++++++++++++++++ .../AirPlaneWithRadar/IDrawingObject.cs | 2 +- .../MapWithSetPlainGeneric.cs | 2 +- .../AirPlaneWithRadar/SetPlaneGeneric.cs | 3 +- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs index 775f898..d448c49 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/DrawingObjectPlane.cs @@ -39,5 +39,35 @@ namespace AirPlaneWithRadar { _plain.setPosition(x, y, width, height); } + + public bool Equals(IDrawingObject? other) + { + if (other == null) + { + return false; + } + var otherPlain = other as DrawingObjectPlane; + if (otherPlain == null) + { + return false; + } + var plain = _plain.Plain; + var otherPlainPlain = otherPlain._plain.Plain; + + if (plain.Speed != otherPlainPlain.Speed) + { + return false; + } + if (plain.Weight != otherPlainPlain.Weight) + { + return false; + } + if (plain.BodyColor != otherPlainPlain.BodyColor) + { + return false; + } + + return true; + } } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs b/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs index f635355..5cd8596 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/IDrawingObject.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AirPlaneWithRadar { - internal interface IDrawingObject + internal interface IDrawingObject : IEquatable { public float Step { get; } void SetObject(int x, int y, int width, int height); diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs index 7ad30c9..f7db018 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs @@ -8,7 +8,7 @@ namespace AirPlaneWithRadar { internal class MapWithSetPlainGeneric - where T : class, IDrawingObject + where T : class, IDrawingObject, IEquatable where U : AbstractMap { private readonly int _pictureWidth; diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs index bc20ae1..3d0bee2 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace AirPlaneWithRadar { internal class SetPlaneGeneric - where T : class + where T : class, IEquatable { private readonly List _places; @@ -26,6 +26,7 @@ namespace AirPlaneWithRadar } public int Insert(T plain, int position) { + ///// if (_places.Count == _maxCount) { throw new StorageOverFullException(_maxCount);