сравнение обьектов

This commit is contained in:
Daniel 2022-12-23 01:49:51 +04:00
parent 931ccb2599
commit baf7a2c1b3
4 changed files with 29 additions and 3 deletions

View File

@ -42,5 +42,31 @@ namespace WinFormsApp1
{
_tractor.DrawEntity(g);
}
public bool Equals(IDrawningObject? other)
{
if (other is not DrawningObjectTractor otherTraktor)
{
return false;
}
var entity = _tractor.Tractor;
var otherEntity = otherTraktor._tractor.Tractor;
if (entity.GetType() != otherEntity.GetType() ||
entity.Speed != otherEntity.Speed ||
entity.Weight != otherEntity.Weight ||
entity.BodyColor != otherEntity.BodyColor)
{
return false;
}
if (entity is MultiTraktor entityTraktorDOP &&
otherEntity is MultiTraktor otherEntityTraktorDOP && (
entityTraktorDOP.dopAhead != otherEntityTraktorDOP.dopAhead ||
entityTraktorDOP.DopColor != otherEntityTraktorDOP.DopColor ||
entityTraktorDOP.dopBehind != otherEntityTraktorDOP.dopBehind))
{
return false;
}
return true;
}
}
}

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace WinFormsApp1
{
interface IDrawningObject
interface IDrawningObject : IEquatable<IDrawningObject>
{
/// Шаг перемещения объекта
public float Step { get; }

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace WinFormsApp1
{
internal class MapWithSetTraktorGeneric<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 WinFormsApp1
{
internal class SetTraktorGeneric<T>
where T : class
where T : class, IEquatable<T>
{
private readonly List<T> _places;
public int Count => _places.Count;