Сравнение
This commit is contained in:
parent
c839a502da
commit
7a4942a0a5
@ -40,5 +40,34 @@ namespace Ship
|
|||||||
public string GetInfo() => _ship?.GetDataForSave();
|
public string GetInfo() => _ship?.GetDataForSave();
|
||||||
|
|
||||||
public static IDrawingObject Create(string data) => new DrawingObject(data.CreateDrawingShip());
|
public static IDrawingObject Create(string data) => new DrawingObject(data.CreateDrawingShip());
|
||||||
|
|
||||||
|
public bool Equals(IDrawingObject? other)
|
||||||
|
{
|
||||||
|
if (other == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var otherCar = other as DrawingObject;
|
||||||
|
if (otherCar == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var car = _ship.Ship;
|
||||||
|
var otherCarCar = otherCar._ship.Ship;
|
||||||
|
if (car.Speed != otherCarCar.Speed)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (car.Weight != otherCarCar.Weight)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (car.BodyColor != otherCarCar.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// TODO доделать проверки в случае продвинутого объекта
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace Ship
|
namespace Ship
|
||||||
{
|
{
|
||||||
internal interface IDrawingObject
|
internal interface IDrawingObject : IEquatable<IDrawingObject>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг перемещения объекта
|
/// Шаг перемещения объекта
|
||||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
namespace Ship
|
namespace Ship
|
||||||
{
|
{
|
||||||
internal class MapWithSetShipsGeneric<T, U>
|
internal class MapWithSetShipsGeneric<T, U>
|
||||||
where T : class, IDrawingObject
|
where T : class, IDrawingObject, IEquatable<T>
|
||||||
where U : AbstractMap
|
where U : AbstractMap
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
namespace Ship
|
namespace Ship
|
||||||
{
|
{
|
||||||
internal class SetShipsGeneric<T>
|
internal class SetShipsGeneric<T>
|
||||||
where T: class
|
where T: class, IEquatable<T>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Массив объектов, которые храним
|
/// Массив объектов, которые храним
|
||||||
@ -45,6 +45,11 @@ namespace Ship
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public int Insert(T ship, int position)
|
public int Insert(T ship, int position)
|
||||||
{
|
{
|
||||||
|
if (_places.Contains(ship))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (Count == _maxCount)
|
if (Count == _maxCount)
|
||||||
{
|
{
|
||||||
throw new StorageOverflowException(_maxCount);
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user