Сравнение объектов

This commit is contained in:
crum61kg 2023-02-14 23:21:28 +04:00
parent 3473802309
commit 6a6abe240f
4 changed files with 35 additions and 3 deletions

View File

@ -41,5 +41,35 @@ namespace WarmlyShip
public static IDrawningObject Create(string data) => new DrawningObjectShip(data.CreateDrawningShip()); public static IDrawningObject Create(string data) => new DrawningObjectShip(data.CreateDrawningShip());
public bool Equals(IDrawningObject? other)
{
if (other == null)
{
return false;
}
var otherShip = other as DrawningObjectShip;
if (otherShip == null)
{
return false;
}
var ship = _ship.Ship;
var otherShipShip = otherShip._ship.Ship;
if (ship.Speed != otherShipShip.Speed)
{
return false;
}
if (ship.Weight != otherShipShip.Weight)
{
return false;
}
if (ship.BodyColor != otherShipShip.BodyColor)
{
return false;
}
// TODO доделать проверки в случае продвинутого объекта
return true;
}
} }
} }

View File

@ -9,7 +9,7 @@ namespace WarmlyShip
/// <summary> /// <summary>
/// Интерфейс для работы с объектом, прорисовываемым на форме /// Интерфейс для работы с объектом, прорисовываемым на форме
/// </summary> /// </summary>
internal interface IDrawningObject internal interface IDrawningObject : IEquatable<IDrawningObject>
{ {
/// <summary> /// <summary>
/// Шаг перемещения объекта /// Шаг перемещения объекта

View File

@ -12,7 +12,7 @@ namespace WarmlyShip
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam> /// <typeparam name="U"></typeparam>
internal class MapWithSetWarmlyShipGeneric<T, U> internal class MapWithSetWarmlyShipGeneric<T, U>
where T : class, IDrawningObject where T : class, IDrawningObject, IEnumerable<T>
where U : AbstractMap where U : AbstractMap
{ {
/// <summary> /// <summary>

View File

@ -11,7 +11,7 @@ namespace WarmlyShip
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
internal class SetWarmlyShipGeneric<T> internal class SetWarmlyShipGeneric<T>
where T : class where T : class, IEnumerable<T>
{ {
/// <summary> /// <summary>
/// Список объектов, которые храним /// Список объектов, которые храним
@ -51,6 +51,8 @@ namespace WarmlyShip
/// <returns></returns> /// <returns></returns>
public int Insert(T ship, int position) public int Insert(T ship, int position)
{ {
//TODO проверка на уникальность
if (Count >= _maxCount) if (Count >= _maxCount)
{ {
throw new StorageOverflowException(Count); throw new StorageOverflowException(Count);