Krasnikov D.D LabWork08 #8

Closed
L1ontiev wants to merge 1 commits from LABA8 into LABA7
4 changed files with 29 additions and 3 deletions

View File

@ -42,5 +42,31 @@ namespace WinFormsApp1
{ {
_tractor.DrawEntity(g); _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 namespace WinFormsApp1
{ {
interface IDrawningObject interface IDrawningObject : IEquatable<IDrawningObject>
{ {
/// Шаг перемещения объекта /// Шаг перемещения объекта
public float Step { get; } public float Step { get; }

View File

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

View File

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