Сравнение объектов.
This commit is contained in:
parent
60da240f7a
commit
9d3083ae94
@ -33,5 +33,32 @@ namespace AircraftCarrier
|
|||||||
}
|
}
|
||||||
public string GetInfo() => _warship?.GetDataForSave();
|
public string GetInfo() => _warship?.GetDataForSave();
|
||||||
public static IDrawingObject Create(string data) => new DrawingObjectWarship(data.CreateDrawingWarship());
|
public static IDrawingObject Create(string data) => new DrawingObjectWarship(data.CreateDrawingWarship());
|
||||||
|
public bool Equals(IDrawingObject? other)
|
||||||
|
{
|
||||||
|
if (other is not DrawingObjectWarship otherWarship)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var warship = _warship.Ship;
|
||||||
|
var otherEntity = otherWarship._warship.Ship;
|
||||||
|
if (warship.GetType() != otherEntity.GetType() ||
|
||||||
|
warship.Speed != otherEntity.Speed ||
|
||||||
|
warship.Weight != otherEntity.Weight ||
|
||||||
|
warship.BodyColor != otherEntity.BodyColor)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (warship is EntityPlaneWarship entityPlaneWarship &&
|
||||||
|
otherEntity is EntityPlaneWarship otherEntityPlaneWarship && (
|
||||||
|
entityPlaneWarship.BodyKit != otherEntityPlaneWarship.BodyKit ||
|
||||||
|
entityPlaneWarship.СontrolPlace != otherEntityPlaneWarship.СontrolPlace ||
|
||||||
|
entityPlaneWarship.RunWay != otherEntityPlaneWarship.RunWay ||
|
||||||
|
entityPlaneWarship.DopColor != otherEntityPlaneWarship.DopColor))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ namespace AircraftCarrier
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal interface IDrawingObject
|
internal interface IDrawingObject : IEquatable<IDrawingObject>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Шаг перемещения объекта
|
/// Шаг перемещения объекта
|
||||||
|
@ -12,7 +12,7 @@ namespace AircraftCarrier
|
|||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <typeparam name="U"></typeparam>
|
/// <typeparam name="U"></typeparam>
|
||||||
internal class MapWithSetWarshipsGeneric<T, U>
|
internal class MapWithSetWarshipsGeneric<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 AircraftCarrier
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
internal class SetWarshipsGeneric<T>
|
internal class SetWarshipsGeneric<T>
|
||||||
where T : class
|
where T : class, IEquatable<T>
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Список объектов, которые храним
|
/// Список объектов, которые храним
|
||||||
@ -53,6 +53,8 @@ namespace AircraftCarrier
|
|||||||
/// <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);
|
||||||
if (!isCorrectPosition(position))
|
if (!isCorrectPosition(position))
|
||||||
@ -107,6 +109,18 @@ namespace AircraftCarrier
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Сортировка набора объектов
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="comparer"></param>
|
||||||
|
public void SortSet(IComparer<T> comparer)
|
||||||
|
{
|
||||||
|
if (comparer == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_places.Sort(comparer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user