From 5526cd9bc4c4805a0ae5eaf5b300e9d9ddc41232 Mon Sep 17 00:00:00 2001 From: Zyzf Date: Sat, 3 Dec 2022 20:22:50 +0400 Subject: [PATCH] final step --- .../AbstractMap.cs | 42 ++++++++++++++++++- .../BoatCompareByColor.cs | 16 ------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/AbstractMap.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/AbstractMap.cs index 680ffb5..a9ee26a 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/AbstractMap.cs +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/AbstractMap.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawningObject _drawningObject = null; protected int[,] _map = null; @@ -131,5 +131,45 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base 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; + } } } diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/BoatCompareByColor.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/BoatCompareByColor.cs index 77e0ef6..1b79e65 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/BoatCompareByColor.cs +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/BoatCompareByColor.cs @@ -41,22 +41,6 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base { return colorCompare; } - if (xBoat.GetBoat.GetType().Name != yBoat.GetBoat.GetType().Name) - { - if (xBoat.GetBoat.GetType().Name == "DrawningBoat") - { - return -1; - } - return 1; - } - if (xBoat.GetBoat.Boat is EntitySpeedboat xSpeedBoat && xBoat.GetBoat.Boat is EntitySpeedboat ySpeedBoat) - { - var colorAdvCompare = xSpeedBoat.DopColor.Name.CompareTo(ySpeedBoat.DopColor.Name); - if (colorAdvCompare != 0) - { - return colorAdvCompare; - } - } var speedCompare = xBoat.GetBoat.Boat.Speed.CompareTo(yBoat.GetBoat.Boat.Speed); if (speedCompare != 0) {