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

This commit is contained in:
ArtemEmelyanov 2022-12-09 12:17:27 +04:00
parent 644ea73342
commit 13591af122
4 changed files with 55 additions and 3 deletions

View File

@ -33,5 +33,53 @@ namespace Airbus
}
public string GetInfo() => _plane?.GetDataForSave();
public static IDrawningObject Create(string data) => new DrawningObjectPlane(data.CreateDrawningPlane());
public bool Equals(IDrawningObject? other)
{
if (other == null)
{
return false;
}
var otherPlane = other as DrawningObjectPlane;
if (otherPlane == null)
{
return false;
}
var plane = _plane.Plane;
var otherPlanePlane = otherPlane._plane.Plane;
if (plane.Speed != otherPlanePlane.Speed)
{
return false;
}
if (plane.Weight != otherPlanePlane.Weight)
{
return false;
}
if (plane.BodyColor != otherPlanePlane.BodyColor)
{
return false;
}
if (plane is EntityAirbus airbus && otherPlanePlane is EntityAirbus otherAirbus)
{
if (airbus.DopColor != otherAirbus.DopColor)
{
return false;
}
if (airbus.BodyKit != otherAirbus.BodyKit)
{
return false;
}
if (airbus.Wing != otherAirbus.BodyKit)
{
return false;
}
if (airbus.SportLine != otherAirbus.SportLine)
{
return false;
}
}
return true;
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Airbus
{
internal interface IDrawningObject
internal interface IDrawningObject : IEquatable<IDrawningObject>
{
/// <summary>
/// Шаг перемещения объекта

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Airbus
{
internal class MapWithSetPlanesGeneric<T, U>
where T : class, IDrawningObject
where T : class, IDrawningObject, IEquatable<T>
where U : AbstractMap
{
/// <summary>

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Airbus
{
internal class SetPlanesGeneric<T>
where T : class
where T : class, IEquatable<T>
{
/// <summary>
/// Список объектов, которые храним
@ -48,6 +48,10 @@ namespace Airbus
{
// TODO проверка позиции
// TODO вставка по позиции
if (_places.Contains(plane))
{
return -1;
}
if (_places.Count == _maxCount) throw new StorageOverflowException(_maxCount);
_places.Insert(position, plane);
return position;