diff --git a/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs b/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs
index 16e65bd..7ad63c4 100644
--- a/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs
+++ b/Stormtrooper/Stormtrooper/DrawningObjectStorm.cs
@@ -14,6 +14,7 @@ namespace Stormtrooper
_storm = storm;
}
public float Step => _storm?.Storm?.Step ?? 0;
+ public Drawning GetStormtrooper => _storm;
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
{
return _storm?.GetCurrentPosition() ?? default;
@@ -35,5 +36,59 @@ namespace Stormtrooper
public string GetInfo() => _storm?.GetDataForSave();
public static IDrawningObject Create(string data) => new DrawningObjectStorm(data.CreateDrawningStormtrooper());
+ public bool Equals(IDrawningObject? other)
+ {
+ if (other == null)
+ {
+ return false;
+ }
+ var otherStorm = other as DrawningObjectStorm;
+ if (otherStorm == null)
+ {
+ return false;
+ }
+ var storm = _storm.Storm;
+ var otherStormStorm = otherStorm._storm.Storm;
+ if (storm.Speed != otherStormStorm.Speed)
+ {
+ return false;
+ }
+ if (storm.Weight != otherStormStorm.Weight)
+ {
+ return false;
+ }
+ if (storm.BodyColor != otherStormStorm.BodyColor)
+ {
+ return false;
+ }
+ if (storm is EntityMilitaryStormtrooper milstorm)
+ {
+ if (other is not EntityMilitaryStormtrooper othermilstorm)
+ {
+ return false;
+ }
+
+ if (milstorm.DopColor != othermilstorm.DopColor)
+ {
+ return false;
+ }
+
+ if (milstorm.BodyKit != othermilstorm.BodyKit)
+ {
+ return false;
+ }
+
+ if (milstorm.Rocket != othermilstorm.Rocket)
+ {
+ return false;
+ }
+
+ if (milstorm.SportLine != othermilstorm.SportLine)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
}
}
diff --git a/Stormtrooper/Stormtrooper/IDrawningObject.cs b/Stormtrooper/Stormtrooper/IDrawningObject.cs
index 539dbd0..37c828c 100644
--- a/Stormtrooper/Stormtrooper/IDrawningObject.cs
+++ b/Stormtrooper/Stormtrooper/IDrawningObject.cs
@@ -9,7 +9,7 @@ namespace Stormtrooper
///
/// Интерфейс для работы с объектом, прорисовываемым на форме
///
- internal interface IDrawningObject
+ internal interface IDrawningObject : IEquatable
{
///
/// Шаг перемещения объекта
diff --git a/Stormtrooper/Stormtrooper/SetStormtroopersGeneric.cs b/Stormtrooper/Stormtrooper/SetStormtroopersGeneric.cs
index 35dc27a..a746fd6 100644
--- a/Stormtrooper/Stormtrooper/SetStormtroopersGeneric.cs
+++ b/Stormtrooper/Stormtrooper/SetStormtroopersGeneric.cs
@@ -11,7 +11,7 @@ namespace Stormtrooper
///
///
internal class SetStormtroopersGeneric
- where T : class
+ where T : class, IEquatable
{
///
/// Список объектов, которые храним
@@ -49,6 +49,10 @@ namespace Stormtrooper
///
public int Insert(T stormtrooper, int position)
{
+ if (_places.Contains(stormtrooper))
+ {
+ throw new ArgumentException("Такой самолёт уже есть");
+ }
if (position < 0 || position >= _maxCount)
throw new StorageOverflowException(_maxCount);
if (_places.Count >= _maxCount) throw new StorageOverflowException(_maxCount);
@@ -105,5 +109,18 @@ namespace Stormtrooper
}
}
}
+ ///
+ /// Сортировка набора объектов
+ ///
+ ///
+ public void SortSet(IComparer comparer)
+ {
+ if (comparer == null)
+ {
+ return;
+ }
+ _places.Sort(comparer);
+ }
+
}
}