diff --git a/Warship/Warship/DrawingObjectWarship.cs b/Warship/Warship/DrawingObjectWarship.cs
index 05fedb7..c9e162c 100644
--- a/Warship/Warship/DrawingObjectWarship.cs
+++ b/Warship/Warship/DrawingObjectWarship.cs
@@ -33,5 +33,32 @@ namespace AircraftCarrier
}
public string GetInfo() => _warship?.GetDataForSave();
public static IDrawingObject Create(string data) => new DrawingObjectWarship(data.CreateDrawingWarship());
+ public bool Equals(IDrawingObject? other)
+ {
+ if (other is not DrawingObjectWarship otherWarship)
+ {
+ return false;
+ }
+ var warship = _warship.Ship;
+ var otherEntity = otherWarship._warship.Ship;
+ if (warship.GetType() != otherEntity.GetType() ||
+ warship.Speed != otherEntity.Speed ||
+ warship.Weight != otherEntity.Weight ||
+ warship.BodyColor != otherEntity.BodyColor)
+ {
+ return false;
+ }
+
+ if (warship is EntityPlaneWarship entityPlaneWarship &&
+ otherEntity is EntityPlaneWarship otherEntityPlaneWarship && (
+ entityPlaneWarship.BodyKit != otherEntityPlaneWarship.BodyKit ||
+ entityPlaneWarship.СontrolPlace != otherEntityPlaneWarship.СontrolPlace ||
+ entityPlaneWarship.RunWay != otherEntityPlaneWarship.RunWay ||
+ entityPlaneWarship.DopColor != otherEntityPlaneWarship.DopColor))
+ {
+ return false;
+ }
+ return true;
+ }
}
}
diff --git a/Warship/Warship/IDrawingObject.cs b/Warship/Warship/IDrawingObject.cs
index 71b9ea5..2ea3196 100644
--- a/Warship/Warship/IDrawingObject.cs
+++ b/Warship/Warship/IDrawingObject.cs
@@ -9,7 +9,7 @@ namespace AircraftCarrier
///
/// Интерфейс для работы с объектом, прорисовываемым на форме
///
- internal interface IDrawingObject
+ internal interface IDrawingObject : IEquatable
{
///
/// Шаг перемещения объекта
diff --git a/Warship/Warship/MapWithSetWarshipGeneric.cs b/Warship/Warship/MapWithSetWarshipGeneric.cs
index 0c9b274..de34607 100644
--- a/Warship/Warship/MapWithSetWarshipGeneric.cs
+++ b/Warship/Warship/MapWithSetWarshipGeneric.cs
@@ -12,7 +12,7 @@ namespace AircraftCarrier
///
///
internal class MapWithSetWarshipsGeneric
- where T : class, IDrawingObject
+ where T : class, IDrawingObject, IEquatable
where U : AbstractMap
{
///
diff --git a/Warship/Warship/SetWarshipGeneric.cs b/Warship/Warship/SetWarshipGeneric.cs
index e52c7d7..8c5ca5a 100644
--- a/Warship/Warship/SetWarshipGeneric.cs
+++ b/Warship/Warship/SetWarshipGeneric.cs
@@ -11,7 +11,7 @@ namespace AircraftCarrier
///
///
internal class SetWarshipsGeneric
- where T : class
+ where T : class, IEquatable
{
///
/// Список объектов, которые храним
@@ -53,6 +53,8 @@ namespace AircraftCarrier
///
public int Insert(T ship, int position)
{
+ if (_places.Contains(ship))
+ return -1;
if (Count == _maxCount)
throw new StorageOverflowException(_maxCount);
if (!isCorrectPosition(position))
@@ -107,6 +109,18 @@ namespace AircraftCarrier
}
}
}
+ ///
+ /// Сортировка набора объектов
+ ///
+ ///
+ public void SortSet(IComparer comparer)
+ {
+ if (comparer == null)
+ {
+ return;
+ }
+ _places.Sort(comparer);
+ }
}
}