From 7457b3483601e0b54798fc0412b993c24a3a2ff6 Mon Sep 17 00:00:00 2001 From: Anastasia Date: Tue, 13 Dec 2022 11:35:28 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=81=D0=BB=D0=B5=D0=B4=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81?= =?UTF-8?q?=D0=B0=20AbstractMap=20=D0=BE=D1=82=20IEquatable.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirplaneWithRadar/AbstractMap.cs | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs b/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs index 8c78481..7a75b5f 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AirplaneWithRadar { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawingObject _drawingObject = null; protected int[,] _map = null; @@ -130,5 +130,43 @@ namespace AirplaneWithRadar 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; + } } }