From a7027333d8b3bfd3386b3d442f375dfb9382e843 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 21 Nov 2022 19:43:07 +0400 Subject: [PATCH] IEquatable AbstractMap --- Locomotive/Locomotive/AbstractMap.cs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/Locomotive/Locomotive/AbstractMap.cs b/Locomotive/Locomotive/AbstractMap.cs index d83050c..1fe18fb 100644 --- a/Locomotive/Locomotive/AbstractMap.cs +++ b/Locomotive/Locomotive/AbstractMap.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Locomotive { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawningObject _drawningObject = null; protected int[,] _map = null; @@ -164,5 +164,30 @@ namespace Locomotive 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; + } } }