diff --git a/Airbus/Airbus/AbstractMap.cs b/Airbus/Airbus/AbstractMap.cs index bcb2d68..d41f961 100644 --- a/Airbus/Airbus/AbstractMap.cs +++ b/Airbus/Airbus/AbstractMap.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Airbus { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { private IDrawningObject _drawningObject = null; protected int[,] _map = null; @@ -121,5 +121,32 @@ namespace Airbus 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 || + _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; + } } } diff --git a/Airbus/Airbus/PlaneCompareByColor.cs b/Airbus/Airbus/PlaneCompareByColor.cs index f7c0708..f10aa7f 100644 --- a/Airbus/Airbus/PlaneCompareByColor.cs +++ b/Airbus/Airbus/PlaneCompareByColor.cs @@ -10,7 +10,54 @@ namespace Airbus { public int Compare(IDrawningObject? x, IDrawningObject? y) { - throw new NotImplementedException(); + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xPlane = x as DrawningObjectPlane; + var yPlane = y as DrawningObjectPlane; + if (xPlane == null && yPlane == null) + { + return 0; + } + if (xPlane == null && yPlane != null) + { + return 1; + } + if (xPlane != null && yPlane == null) + { + return -1; + } + string xShipColor = xPlane.GetPlane.Plane.BodyColor.Name; + string yShipColor = yPlane.GetPlane.Plane.BodyColor.Name; + if (xShipColor != yShipColor) + { + return xShipColor.CompareTo(yShipColor); + } + if (xPlane.GetPlane.Plane is EntityAirbus xAirbus && yPlane.GetPlane.Plane is EntityAirbus yAirbus) + { + string xShipDopColor = xAirbus.DopColor.Name; + string yShipDopColor = yAirbus.DopColor.Name; + var dopColorCompare = xShipDopColor.CompareTo(yShipDopColor); + if (dopColorCompare != 0) + { + return dopColorCompare; + } + } + var speedCompare = xPlane.GetPlane.Plane.Speed.CompareTo(yPlane.GetPlane.Plane.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xPlane.GetPlane.Plane.Weight.CompareTo(yPlane.GetPlane.Plane.Weight); } } }