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