Сравнение
This commit is contained in:
parent
c839a502da
commit
7a4942a0a5
@ -40,5 +40,34 @@ namespace Ship
|
||||
public string GetInfo() => _ship?.GetDataForSave();
|
||||
|
||||
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
|
||||
{
|
||||
internal interface IDrawingObject
|
||||
internal interface IDrawingObject : IEquatable<IDrawingObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace Ship
|
||||
{
|
||||
internal class MapWithSetShipsGeneric<T, U>
|
||||
where T : class, IDrawingObject
|
||||
where T : class, IDrawingObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace Ship
|
||||
{
|
||||
internal class SetShipsGeneric<T>
|
||||
where T: class
|
||||
where T: class, IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
@ -45,6 +45,11 @@ namespace Ship
|
||||
/// <returns></returns>
|
||||
public int Insert(T ship, int position)
|
||||
{
|
||||
if (_places.Contains(ship))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
Loading…
x
Reference in New Issue
Block a user