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