Сравнения объектов
This commit is contained in:
parent
9c0a1678a0
commit
a2d2543486
@ -40,5 +40,49 @@ namespace WarmlyShip
|
|||||||
public string GetInfo() => _warmlyShip?.GetDataForSave();
|
public string GetInfo() => _warmlyShip?.GetDataForSave();
|
||||||
|
|
||||||
public static IDrawningObject Create(string data) => new DrawningObjectShip(data.CreateDrawningShip());
|
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 = _warmlyShip.warmlyShip;
|
||||||
|
var otherShipShip = otherShip._warmlyShip.warmlyShip;
|
||||||
|
if (ship.Speed != otherShipShip.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ship.Weight != otherShipShip.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ship.BodyColor != otherShipShip.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ship is EntityMotorShip motorShip && otherShipShip is EntityMotorShip otherMotorShip)
|
||||||
|
{
|
||||||
|
if (motorShip.DopColor != otherMotorShip.DopColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (motorShip.Tubes != otherMotorShip.Tubes)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (motorShip.Cistern != otherMotorShip.Cistern)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace WarmlyShip
|
namespace WarmlyShip
|
||||||
{
|
{
|
||||||
internal interface IDrawningObject
|
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||||
{
|
{
|
||||||
public float Step { get; }
|
public float Step { get; }
|
||||||
void SetObject(int x, int y, int width, int height);
|
void SetObject(int x, int y, int width, int height);
|
||||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
namespace WarmlyShip
|
namespace WarmlyShip
|
||||||
{
|
{
|
||||||
internal class MapWithSetShipGeneric<T, U>
|
internal class MapWithSetShipGeneric<T, U>
|
||||||
where T : class, IDrawningObject
|
where T : class, IDrawningObject, IEquatable<T>
|
||||||
where U : AbstractMap
|
where U : AbstractMap
|
||||||
{
|
{
|
||||||
private readonly int _pictureWidth;
|
private readonly int _pictureWidth;
|
||||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
namespace WarmlyShip
|
namespace WarmlyShip
|
||||||
{
|
{
|
||||||
internal class SetShipGeneric<T>
|
internal class SetShipGeneric<T>
|
||||||
where T : class
|
where T : class, IEquatable<T>
|
||||||
{
|
{
|
||||||
private readonly List<T> _places;
|
private readonly List<T> _places;
|
||||||
public int Count => _places.Count;
|
public int Count => _places.Count;
|
||||||
@ -27,6 +27,10 @@ namespace WarmlyShip
|
|||||||
|
|
||||||
public int Insert(T ship, int position)
|
public int Insert(T ship, int position)
|
||||||
{
|
{
|
||||||
|
if (_places.Contains(ship))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (position < 0 || position > Count || Count == _maxCount) throw new StorageOverflowException(_maxCount);
|
if (position < 0 || position > Count || Count == _maxCount) throw new StorageOverflowException(_maxCount);
|
||||||
_places.Insert(position, ship);
|
_places.Insert(position, ship);
|
||||||
return position;
|
return position;
|
||||||
|
Loading…
Reference in New Issue
Block a user