From baf7a2c1b3f7a32cc6e88e96e6e6fee13559a52f Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 23 Dec 2022 01:49:51 +0400 Subject: [PATCH] =?UTF-8?q?=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=8C=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WinFormsApp1/DrawningObjectTraktor.cs | 26 ++++++++++++++++++++++++ WinFormsApp1/IDrawningObject.cs | 2 +- WinFormsApp1/MapWithSetTraktorGeneric.cs | 2 +- WinFormsApp1/SetTraktorGeneric.cs | 2 +- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/WinFormsApp1/DrawningObjectTraktor.cs b/WinFormsApp1/DrawningObjectTraktor.cs index 66c5490..6fee5da 100644 --- a/WinFormsApp1/DrawningObjectTraktor.cs +++ b/WinFormsApp1/DrawningObjectTraktor.cs @@ -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; + } } } diff --git a/WinFormsApp1/IDrawningObject.cs b/WinFormsApp1/IDrawningObject.cs index 06e1b86..531997b 100644 --- a/WinFormsApp1/IDrawningObject.cs +++ b/WinFormsApp1/IDrawningObject.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace WinFormsApp1 { - interface IDrawningObject + interface IDrawningObject : IEquatable { /// Шаг перемещения объекта public float Step { get; } diff --git a/WinFormsApp1/MapWithSetTraktorGeneric.cs b/WinFormsApp1/MapWithSetTraktorGeneric.cs index e7ebc34..6238ee5 100644 --- a/WinFormsApp1/MapWithSetTraktorGeneric.cs +++ b/WinFormsApp1/MapWithSetTraktorGeneric.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace WinFormsApp1 { internal class MapWithSetTraktorGeneric - where T : class, IDrawningObject + where T : class, IDrawningObject, IEquatable where U : AbstractMap { private readonly int _pictureWidth; diff --git a/WinFormsApp1/SetTraktorGeneric.cs b/WinFormsApp1/SetTraktorGeneric.cs index 87dcc16..cc72f1a 100644 --- a/WinFormsApp1/SetTraktorGeneric.cs +++ b/WinFormsApp1/SetTraktorGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace WinFormsApp1 { internal class SetTraktorGeneric - where T : class + where T : class, IEquatable { private readonly List _places; public int Count => _places.Count; -- 2.25.1