From 7c7fe34520cf94d9c216892536202777ca22954e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=B9=D0=B4=D0=B0=D1=80?= Date: Fri, 9 Dec 2022 01:44:21 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BD=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Battleship/Battleship/AbstractMap.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/Battleship/Battleship/AbstractMap.cs b/Battleship/Battleship/AbstractMap.cs index 605c54c..c5cbf66 100644 --- a/Battleship/Battleship/AbstractMap.cs +++ b/Battleship/Battleship/AbstractMap.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Battleship { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawningObject _drawingObject = null; protected int[,] _map = null; @@ -124,6 +124,29 @@ namespace Battleship return false; } + public bool Equals(AbstractMap? other) + { + if (other == null || _map != other._map || _height != other._height || _width != other._width + || _size_x != other._size_x || _size_y != other._size_y || 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; + } + protected abstract void GenerateMap(); protected abstract void DrawRoadPart(Graphics g, int i, int j); protected abstract void DrawBarrierPart(Graphics g, int i, int j);