diff --git a/WarmlyShip/WarmlyShip/DrawningObjectShip.cs b/WarmlyShip/WarmlyShip/DrawningObjectShip.cs
index 24e6ff5..80b06bb 100644
--- a/WarmlyShip/WarmlyShip/DrawningObjectShip.cs
+++ b/WarmlyShip/WarmlyShip/DrawningObjectShip.cs
@@ -41,5 +41,35 @@ namespace WarmlyShip
public static IDrawningObject Create(string data) => new DrawningObjectShip(data.CreateDrawningShip());
+
+ public bool Equals(IDrawningObject? other)
+ {
+ if (other == null)
+ {
+ return false;
+ }
+ var otherShip = other as DrawningObjectShip;
+ if (otherShip == null)
+ {
+ return false;
+ }
+ var ship = _ship.Ship;
+ var otherShipShip = otherShip._ship.Ship;
+ if (ship.Speed != otherShipShip.Speed)
+ {
+ return false;
+ }
+ if (ship.Weight != otherShipShip.Weight)
+ {
+ return false;
+ }
+ if (ship.BodyColor != otherShipShip.BodyColor)
+ {
+ return false;
+ }
+ // TODO доделать проверки в случае продвинутого объекта
+ return true;
+
+ }
}
}
diff --git a/WarmlyShip/WarmlyShip/IDrawningObject.cs b/WarmlyShip/WarmlyShip/IDrawningObject.cs
index cbbd689..c7ea0dd 100644
--- a/WarmlyShip/WarmlyShip/IDrawningObject.cs
+++ b/WarmlyShip/WarmlyShip/IDrawningObject.cs
@@ -9,7 +9,7 @@ namespace WarmlyShip
///
/// Интерфейс для работы с объектом, прорисовываемым на форме
///
- internal interface IDrawningObject
+ internal interface IDrawningObject : IEquatable
{
///
/// Шаг перемещения объекта
diff --git a/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs
index 9a6e6b3..abf3dbb 100644
--- a/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs
+++ b/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs
@@ -12,7 +12,7 @@ namespace WarmlyShip
///
///
internal class MapWithSetWarmlyShipGeneric
- where T : class, IDrawningObject
+ where T : class, IDrawningObject, IEnumerable
where U : AbstractMap
{
///
diff --git a/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs b/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs
index 6bdff72..c5cfa3a 100644
--- a/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs
+++ b/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs
@@ -11,7 +11,7 @@ namespace WarmlyShip
///
///
internal class SetWarmlyShipGeneric
- where T : class
+ where T : class, IEnumerable
{
///
/// Список объектов, которые храним
@@ -51,6 +51,8 @@ namespace WarmlyShip
///
public int Insert(T ship, int position)
{
+ //TODO проверка на уникальность
+
if (Count >= _maxCount)
{
throw new StorageOverflowException(Count);