Сравнение объектов.
This commit is contained in:
parent
6f2ab62ff2
commit
c67d41e1ab
@ -32,5 +32,47 @@ namespace Liner
|
||||
}
|
||||
public string GetInfo() => _ship?.GetDataForSave();
|
||||
public static IDrawingObject Create(string data) => new DrawingObjectShip(data.CreateDrawingShip());
|
||||
|
||||
public bool Equals(IDrawingObject? other)
|
||||
{
|
||||
if (other is not DrawingObjectShip otherShip)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var ship = _ship.Ship;
|
||||
var otherShipShip = otherShip._ship.Ship;
|
||||
if (ship.GetType() != otherShipShip.GetType())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship.Speed != otherShipShip.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship.Weight != otherShipShip.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship.BodyColor != otherShipShip.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ship is EntityLiner liner && otherShipShip is EntityLiner otherLiner)
|
||||
{
|
||||
if (liner.DopColor != otherLiner.DopColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (liner.Pool != otherLiner.Pool)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (liner.DopDeck != otherLiner.DopDeck)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Liner
|
||||
{
|
||||
internal interface IDrawingObject
|
||||
internal interface IDrawingObject : IEquatable<IDrawingObject>
|
||||
{
|
||||
public float Step { get; }
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace Liner
|
||||
{
|
||||
internal class MapWithSetShipsGeneric<T, U>
|
||||
where T : class, IDrawingObject
|
||||
where T : class, IDrawingObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace Liner
|
||||
{
|
||||
internal class SetShipsGeneric<T>
|
||||
where T : class
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
private readonly List<T> _places;
|
||||
public int Count => _places.Count;
|
||||
@ -23,6 +23,10 @@ namespace Liner
|
||||
}
|
||||
public int Insert(T ship, int position)
|
||||
{
|
||||
if (_places.Contains(ship))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
Loading…
Reference in New Issue
Block a user