From 48eef0fb16b23d1a158010357fe35cae43c8c3f4 Mon Sep 17 00:00:00 2001 From: Danil Markov Date: Mon, 5 Dec 2022 19:11:03 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=BE=D1=80=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=BA=D0=B0=20abstractmap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ContainerShip/ContainerShip/AbstractMap.cs | 29 +++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/ContainerShip/ContainerShip/AbstractMap.cs b/ContainerShip/ContainerShip/AbstractMap.cs index ec8ce46..e0bb582 100644 --- a/ContainerShip/ContainerShip/AbstractMap.cs +++ b/ContainerShip/ContainerShip/AbstractMap.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ContainerShip { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawingObject _drawningObject = null; protected int[,] _map = null; @@ -217,5 +217,32 @@ namespace ContainerShip protected abstract void GenerateMap(); protected abstract void DrawWaterPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j); + + public bool Equals(AbstractMap? other) + { + if (other == null || + _map != other._map || + _width != other._width || + _size_x != other._size_x || + _size_y != other._size_y || + _height != other._height || + GetType() != other.GetType() || + _map.GetLength(0) != other._map.GetLength(0) || + _map.GetLength(1) != other._map.GetLength(1)) + { + return false; + } + 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; + } + } + } + return true; + } } }