From c707897b008ed71b4ad8fa2eaa53c0b985201c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B0=D0=BB=D0=B5=D1=80=D0=B8=D1=8F=20=D0=9D=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=D1=84=D0=BE=D1=80=D0=BE=D0=B2=D0=B0?= Date: Fri, 9 Dec 2022 18:36:38 +0400 Subject: [PATCH] IEquatable AbstractMap --- AccordionBus/AccordionBus/AbstractMap.cs | 42 +++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/AccordionBus/AccordionBus/AbstractMap.cs b/AccordionBus/AccordionBus/AbstractMap.cs index 437ac7f..06068a2 100644 --- a/AccordionBus/AccordionBus/AbstractMap.cs +++ b/AccordionBus/AccordionBus/AbstractMap.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace AccordionBus { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawningObject _drawningObject = null; protected int[,] _map = null; @@ -158,5 +158,45 @@ namespace AccordionBus 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; + } } } \ No newline at end of file