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

This commit is contained in:
Артём Алейкин 2022-12-13 17:12:38 +04:00
parent a4a89b5f21
commit 94a7aca855
4 changed files with 35 additions and 3 deletions

View File

@ -40,5 +40,36 @@ namespace AirBomber
public string GetInfo() => _airBomber?.GetDataForSave();
public static IDrawningObject Create(string data) => new DrawningObjectBomber(data.CreateDrawningAirBomber());
public bool Equals(IDrawningObject? other)
{
if (other == null)
{
return false;
}
var otherBomber = other as DrawningObjectBomber;
if (otherBomber == null)
{
return false;
}
var airBomber = _airBomber.AirBomber;
var otherBomberBomber = otherBomber._airBomber.AirBomber;
if (airBomber.Speed != otherBomberBomber.Speed)
{
return false;
}
if (airBomber.Weight != otherBomberBomber.Weight)
{
return false;
}
if (airBomber.BodyColor != otherBomberBomber.BodyColor)
{
return false;
}
//TODO
return true;
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AirBomber
{
internal interface IDrawningObject
internal interface IDrawningObject : IEquatable<IDrawningObject>
{
public float Step { get; }

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace AirBomber
{
internal class MapWithSetAirBomberGeneric<T, U>
where T : class, IDrawningObject
where T : class, IDrawningObject, IEquatable<T>
where U : AbstractMap
{
private readonly int _pictureWidth;

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace AirBomber
{
internal class SetAirBomberGeneric<T>
where T : class
where T : class, IEquatable<T>
{
private readonly List<T> _places;
@ -28,6 +28,7 @@ namespace AirBomber
public int Insert(T airBomber, int position)
{
//TODO проверка на уникальность
if (_places.Count >= _maxCount)
{
throw new StorageOverflowException(_maxCount);