From 6008fd74ab49e22c32c61a49650b80d3fd8dc9bb Mon Sep 17 00:00:00 2001 From: Anastasia Date: Mon, 12 Dec 2022 14:59:18 +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 --- .../DrawingObjectAirplane.cs | 43 +++++++++++++++++++ .../AirplaneWithRadar/IDrawingObject.cs | 2 +- .../MapWithSetAirplanesGeneric.cs | 2 +- .../AirplaneWithRadar/SetAirplanesGeneric.cs | 6 ++- 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs index 252c1bd..c3765ed 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs @@ -33,5 +33,48 @@ namespace AirplaneWithRadar public string GetInfo() => _airplane?.GetDataForSave(); public static IDrawingObject Create(string data) => new DrawingObjectAirplane(data.CreateDrawingAirplane()); + public bool Equals(IDrawingObject? other) + { + if (other == null) + { + return false; + } + var otherAirplane = other as DrawingObjectAirplane; + if (otherAirplane == null) + { + return false; + } + var airplane = _airplane.Airplane; + var otherAirplaneAirplane = otherAirplane._airplane.Airplane; + if (airplane.Speed != otherAirplaneAirplane.Speed) + { + return false; + } + if (airplane.Weight != otherAirplaneAirplane.Weight) + { + return false; + } + if (airplane.BodyColor != otherAirplaneAirplane.BodyColor) + { + return false; + } + // TODO доделать проверки в случае продвинутого объекта + if (airplane is EntityAirplaneWithRadar airpl && otherAirplaneAirplane is EntityAirplaneWithRadar otherAirpl) + { + if (airpl.DopColor != otherAirpl.DopColor) + { + return false; + } + if (airpl.Radar != otherAirpl.Radar) + { + return false; + } + if (airpl.ExtraFuelTank != otherAirpl.ExtraFuelTank) + { + return false; + } + } + return true; + } } } diff --git a/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs b/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs index 35c63ab..36a1535 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs @@ -3,7 +3,7 @@ /// /// Интерфейс для работы с объектом, прорисовываемым на форме /// - internal interface IDrawingObject + internal interface IDrawingObject : IEquatable { /// /// Шаг перемещения объекта diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs index 20d539d..fbe21f0 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs @@ -13,7 +13,7 @@ namespace AirplaneWithRadar /// /// internal class MapWithSetAirplanesGeneric - where T : class, IDrawingObject + where T : class, IDrawingObject, IEquatable where U : AbstractMap { /// diff --git a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs index 43b5ce2..9b0fc52 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs @@ -11,7 +11,7 @@ namespace AirplaneWithRadar /// /// internal class SetAirplanesGeneric - where T : class + where T : class, IEquatable { /// /// Список объектов, которые храним @@ -59,6 +59,10 @@ namespace AirplaneWithRadar { // TODO проверка позиции // TODO вставка по позиции + if (_places.Contains(airplane)) + { + throw new ArgumentException($"Данный объект ({airplane}) уже есть в наборе"); + } if (position < 0 || position >= _maxCount) { throw new StorageOverflowException(_maxCount);