From e603c06444f7bed22a651e10128a1f1d4afe6f6a Mon Sep 17 00:00:00 2001 From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com> Date: Tue, 27 Dec 2022 10:32:17 +0400 Subject: [PATCH] AbstractMap IEquatable --- Boats/Boats/AbstractMap.cs | 40 +++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/Boats/Boats/AbstractMap.cs b/Boats/Boats/AbstractMap.cs index dfa1b1b..9679f89 100644 --- a/Boats/Boats/AbstractMap.cs +++ b/Boats/Boats/AbstractMap.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Boats { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawingObject _drawingObject = null; protected int[,] _map = null; @@ -196,5 +196,43 @@ namespace Boats /// /// 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; + } } }