Сравнение объектов
This commit is contained in:
parent
60bbe79b41
commit
1f90797c6a
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace AirFighter
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||
/// </summary>
|
||||
internal interface IDrawningObject
|
||||
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
|
@ -12,7 +12,7 @@ namespace AirFighter
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class MapWithSetAirFightersGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where T : class, IDrawningObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -12,7 +12,7 @@ namespace AirFighter
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetAirFightersGeneric<T>
|
||||
where T: class
|
||||
where T: class, IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
@ -52,6 +52,10 @@ namespace AirFighter
|
||||
/// <returns></returns>
|
||||
public int Insert(T airFighter, int position)
|
||||
{
|
||||
if (_places.Contains(airFighter))
|
||||
{
|
||||
throw new ArgumentException("Элемент с такими характеристиками существует в хранилище");
|
||||
}
|
||||
if (Count >= _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException();
|
||||
|
Loading…
Reference in New Issue
Block a user