From 619e8623ae136c0f118c81d6f08f077f3bdf9c9c Mon Sep 17 00:00:00 2001 From: Pavel_Sorokin Date: Fri, 2 Dec 2022 11:50:08 +0400 Subject: [PATCH] =?UTF-8?q?Equals=20=D0=B2=20AbstractMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Liner/Liner/AbstractMap.cs | 42 +++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Liner/Liner/AbstractMap.cs b/Liner/Liner/AbstractMap.cs index faa99df..21ceac2 100644 --- a/Liner/Liner/AbstractMap.cs +++ b/Liner/Liner/AbstractMap.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Liner { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawingObject _drawningObject = null; protected int[,] _map = null; @@ -139,5 +139,45 @@ namespace Liner protected abstract void GenerateMap(); protected abstract void DrawRoadPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j); + + public bool Equals(AbstractMap? other) + { + if(other == null) + { + return false; + } + var otherMap = other as AbstractMap; + if(otherMap == null) + { + return false; + } + if(_width != otherMap._width) + { + return false; + } + if(_height != otherMap._height) + { + return false; + } + if (_size_x != otherMap._size_x) + { + return false; + } + if (_size_y != otherMap._size_y) + { + return false; + } + for(int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + if (_map[i, j] != otherMap._map[i, j]) + { + return false; + } + } + } + return true; + } } }