Сравнение объектов
This commit is contained in:
parent
681b60f6a6
commit
9387eb7e2f
@ -32,5 +32,48 @@ namespace Boats
|
||||
}
|
||||
public string GetInfo() => _boat?.GetDataForSave();
|
||||
public static IDrawingObject Create(string data) => new DrawingObjectBoat(data.CreateDrawingBoat());
|
||||
|
||||
public bool Equals(IDrawingObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otherBoat = other as DrawingObjectBoat;
|
||||
if (otherBoat == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var boat = _boat.Boat;
|
||||
var otherBoatBoat = otherBoat._boat.Boat;
|
||||
if (boat.Speed != otherBoatBoat.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (boat.Weight != otherBoatBoat.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (boat.BodyColor != otherBoatBoat.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (boat is EntityCatamaran catamaran && otherBoatBoat is EntityCatamaran otherCatamaran)
|
||||
{
|
||||
if (catamaran.Sail != otherCatamaran.Sail)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (catamaran.Bobbers != otherCatamaran.Bobbers)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (catamaran.DopColor != otherCatamaran.DopColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ namespace Boats
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||
/// </summary>
|
||||
internal interface IDrawingObject
|
||||
internal interface IDrawingObject : IEquatable<IDrawingObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
|
@ -12,7 +12,7 @@ namespace Boats
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class MapWithSetBoatsGeneric<T, U>
|
||||
where T : class, IDrawingObject
|
||||
where T : class, IDrawingObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -11,7 +11,7 @@ namespace Boats
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetBoatsGeneric<T>
|
||||
where T : class
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
@ -56,6 +56,11 @@ namespace Boats
|
||||
/// <returns></returns>
|
||||
public int Insert(T boat, int position)
|
||||
{
|
||||
// Проверка на уникальность
|
||||
if (_places.Contains(boat))
|
||||
{
|
||||
throw new ArgumentException($"Объект {boat} уже есть");
|
||||
}
|
||||
// Проверка позиции
|
||||
if (position < 0 || position >= _maxCount - 1)
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user