comparison of object
This commit is contained in:
parent
2b2b5f3e5e
commit
fdba620e54
@ -33,5 +33,45 @@
|
||||
|
||||
public string GetInfo() => _machine?.GetDataForSave();
|
||||
public static IDrawningObject Create(string data) => new DrawningObject(data.CreateDrawningCar());
|
||||
|
||||
public bool Equals(IDrawningObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otheMachine = other as DrawningObject;
|
||||
if (otheMachine == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var machine = _machine.ArmoredVehicle;
|
||||
var otherMachineMachine = otheMachine._machine.ArmoredVehicle;
|
||||
if (machine.Speed != otherMachineMachine.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (machine.Weight != otherMachineMachine.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (machine.BodyColor != otherMachineMachine.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (machine is TankEnity && otherMachineMachine is TankEnity)
|
||||
{
|
||||
var tank = machine as TankEnity;
|
||||
var otherMachineTank = otherMachineMachine as TankEnity;
|
||||
if (tank.DopColor != otherMachineTank.DopColor || tank.Tower != otherMachineTank.Tower ||
|
||||
tank.MachineGun != otherMachineTank.MachineGun)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с объектом, прорисовываемым на форме
|
||||
/// </summary>
|
||||
internal interface IDrawningObject
|
||||
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
|
@ -6,7 +6,7 @@
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <typeparam name="U"></typeparam>
|
||||
internal class MapWithSetMachineGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where T : class, IDrawningObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -5,7 +5,7 @@
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
internal class SetMachineGeneric<T>
|
||||
where T : class
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
@ -16,7 +16,6 @@
|
||||
/// Количество объектов в списке
|
||||
/// </summary>
|
||||
public int Count => _places.Count;
|
||||
private int BusyPlaces = 0;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
@ -45,9 +44,12 @@
|
||||
/// <returns></returns>
|
||||
public int Insert(T machine, int position)
|
||||
{
|
||||
if(position >= _maxCount) throw new StorageOverflowException(_maxCount);
|
||||
if(_places.All(p => p.Equals(machine) == false))
|
||||
{
|
||||
if (position >= _maxCount) throw new StorageOverflowException(_maxCount);
|
||||
|
||||
_places.Insert(position, machine);
|
||||
_places.Insert(position, machine);
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user