Первый шаг
This commit is contained in:
parent
38646b0587
commit
165d0d1392
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace Stormtrooper
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||
/// </summary>
|
||||
internal interface IDrawningObject
|
||||
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
|
@ -11,7 +11,7 @@ namespace Stormtrooper
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetStormtroopersGeneric<T>
|
||||
where T : class
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
@ -49,6 +49,10 @@ namespace Stormtrooper
|
||||
/// <returns></returns>
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Сортировка набора объектов
|
||||
/// </summary>
|
||||
/// <param name="comparer"></param>
|
||||
public void SortSet(IComparer<T> comparer)
|
||||
{
|
||||
if (comparer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_places.Sort(comparer);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user