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);