diff --git a/AirFighter/AirFighter/DrawningObjectAirFighter.cs b/AirFighter/AirFighter/DrawningObjectAirFighter.cs
index 4b73d56..1df156f 100644
--- a/AirFighter/AirFighter/DrawningObjectAirFighter.cs
+++ b/AirFighter/AirFighter/DrawningObjectAirFighter.cs
@@ -38,5 +38,53 @@ namespace AirFighter
public string GetInfo() => _airFighter?.GetDataForSave();
public static IDrawningObject Create(string data) => new DrawningObjectAirFighter(data.CreateDrawningCar());
+
+ public bool Equals(IDrawningObject? other)
+ {
+ if (other == null)
+ {
+ return false;
+ }
+ var otherAirFighter = other as DrawningObjectAirFighter;
+ if (otherAirFighter == null)
+ {
+ return false;
+ }
+ var airFighter = _airFighter.AirFighter;
+ var otherAirFighterAirFighter = otherAirFighter._airFighter.AirFighter;
+ if (airFighter.Speed != otherAirFighterAirFighter.Speed)
+ {
+ return false;
+ }
+ if (airFighter.Weight != otherAirFighterAirFighter.Weight)
+ {
+ return false;
+ }
+ if (airFighter.BodyColor != otherAirFighterAirFighter.BodyColor)
+ {
+ return false;
+ }
+ // TODO доделать проверки в случае продвинутого объекта
+ if(airFighter is EntityUpgradeAirFighter upgradeAirFighter && otherAirFighterAirFighter is EntityUpgradeAirFighter upgradeOtherAirFighter)
+ {
+ if(upgradeAirFighter.DopWing != upgradeOtherAirFighter.DopWing)
+ {
+ return false;
+ }
+ if(upgradeAirFighter.Rocket != upgradeAirFighter.Rocket)
+ {
+ return false;
+ }
+ if(upgradeAirFighter.DopColor != upgradeOtherAirFighter.DopColor)
+ {
+ return false;
+ }
+ }else if(airFighter is EntityUpgradeAirFighter || otherAirFighterAirFighter is EntityUpgradeAirFighter)
+ {
+ return false;
+ }
+ return true;
+
+ }
}
}
diff --git a/AirFighter/AirFighter/IDrawningObject.cs b/AirFighter/AirFighter/IDrawningObject.cs
index 5f09481..5618dcd 100644
--- a/AirFighter/AirFighter/IDrawningObject.cs
+++ b/AirFighter/AirFighter/IDrawningObject.cs
@@ -9,7 +9,7 @@ namespace AirFighter
///
/// Интерфейс для работы с объектом, прорисовываемым на форме
///
- internal interface IDrawningObject
+ internal interface IDrawningObject : IEquatable
{
///
/// Шаг перемещения объекта
diff --git a/AirFighter/AirFighter/MapWithSetAirFightersGeneric.cs b/AirFighter/AirFighter/MapWithSetAirFightersGeneric.cs
index 47afcee..9453783 100644
--- a/AirFighter/AirFighter/MapWithSetAirFightersGeneric.cs
+++ b/AirFighter/AirFighter/MapWithSetAirFightersGeneric.cs
@@ -12,7 +12,7 @@ namespace AirFighter
///
///
internal class MapWithSetAirFightersGeneric
- where T : class, IDrawningObject
+ where T : class, IDrawningObject, IEquatable
where U : AbstractMap
{
///
diff --git a/AirFighter/AirFighter/SetAirFightersGeneric.cs b/AirFighter/AirFighter/SetAirFightersGeneric.cs
index fbc5f64..5a77f0b 100644
--- a/AirFighter/AirFighter/SetAirFightersGeneric.cs
+++ b/AirFighter/AirFighter/SetAirFightersGeneric.cs
@@ -12,7 +12,7 @@ namespace AirFighter
///
///
internal class SetAirFightersGeneric
- where T: class
+ where T: class, IEquatable
{
///
/// Список объектов, которые храним
@@ -52,6 +52,10 @@ namespace AirFighter
///
public int Insert(T airFighter, int position)
{
+ if (_places.Contains(airFighter))
+ {
+ throw new ArgumentException("Элемент с такими характеристиками существует в хранилище");
+ }
if (Count >= _maxCount)
{
throw new StorageOverflowException();