Сравнение объектов
This commit is contained in:
parent
3473802309
commit
6a6abe240f
@ -41,5 +41,35 @@ namespace WarmlyShip
|
||||
|
||||
public static IDrawningObject Create(string data) => new DrawningObjectShip(data.CreateDrawningShip());
|
||||
|
||||
|
||||
public bool Equals(IDrawningObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otherShip = other as DrawningObjectShip;
|
||||
if (otherShip == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var ship = _ship.Ship;
|
||||
var otherShipShip = otherShip._ship.Ship;
|
||||
if (ship.Speed != otherShipShip.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship.Weight != otherShipShip.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship.BodyColor != otherShipShip.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// TODO доделать проверки в случае продвинутого объекта
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace WarmlyShip
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||
/// </summary>
|
||||
internal interface IDrawningObject
|
||||
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
|
@ -12,7 +12,7 @@ namespace WarmlyShip
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class MapWithSetWarmlyShipGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where T : class, IDrawningObject, IEnumerable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -11,7 +11,7 @@ namespace WarmlyShip
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetWarmlyShipGeneric<T>
|
||||
where T : class
|
||||
where T : class, IEnumerable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
@ -51,6 +51,8 @@ namespace WarmlyShip
|
||||
/// <returns></returns>
|
||||
public int Insert(T ship, int position)
|
||||
{
|
||||
//TODO проверка на уникальность
|
||||
|
||||
if (Count >= _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(Count);
|
||||
|
Loading…
Reference in New Issue
Block a user