From 1bec916bb172304ba64b933024aec789e51792f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=98=D0=B3=D0=BE=D1=80=D1=8C?= Date: Thu, 8 Dec 2022 18:19:03 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20IEquatable=20=D0=B4=D0=BB=D1=8F=20Abstract?= =?UTF-8?q?Map?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotives/Locomotives/AbstractMap.cs | 34 ++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/Locomotives/Locomotives/AbstractMap.cs b/Locomotives/Locomotives/AbstractMap.cs index 2708099..0aff92b 100644 --- a/Locomotives/Locomotives/AbstractMap.cs +++ b/Locomotives/Locomotives/AbstractMap.cs @@ -1,6 +1,6 @@ namespace Locomotives { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { /// /// Поле от интерфейса прорисовки @@ -60,7 +60,7 @@ /// public (int Top, int Bottom, int Left, int Right) GetObjectCoordinates() { - return + return ( (int)(_drawningObject.GetCurrentPosition().Top / _size_y), (int)(_drawningObject.GetCurrentPosition().Bottom / _size_y), @@ -239,5 +239,35 @@ /// /// protected abstract void DrawBarrierPart(Graphics g, int i, int j); + /// + /// Реализация сравнения + /// + /// + /// + public bool Equals(AbstractMap? other) + { + if (other == null) + { + return false; + } + if (_map.GetLength(0) == other._map.GetLength(0) && _map.GetLength(1) == other._map.GetLength(1)) + { + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + if (_map[i, j] != other._map[i, j]) + { + return false; + } + } + } + } + else + { + return false; + } + return true; + } } }