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