diff --git a/Airbus/Airbus/AbstractMap.cs b/Airbus/Airbus/AbstractMap.cs index da78b80..4330bc9 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; @@ -118,5 +118,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/AirplaneCompareByColor.cs b/Airbus/Airbus/AirplaneCompareByColor.cs index 4c30e0c..82a073d 100644 --- a/Airbus/Airbus/AirplaneCompareByColor.cs +++ b/Airbus/Airbus/AirplaneCompareByColor.cs @@ -10,8 +10,54 @@ namespace Airbus { public int Compare(IDrawningObject? x, IDrawningObject? y) { - // TODO реализовать логику сравнения - 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 xAirplane = x as DrawningObjectAirplane; + var yAirplane = y as DrawningObjectAirplane; + if (xAirplane == null && yAirplane == null) + { + return 0; + } + if (xAirplane == null && yAirplane != null) + { + return 1; + } + if (xAirplane != null && yAirplane == null) + { + return -1; + } + string xAirplaneColor = xAirplane.GetAirplane.airplane.BodyColor.Name; + string yAirplaneColor = yAirplane.GetAirplane.airplane.BodyColor.Name; + if (xAirplaneColor != yAirplaneColor) + { + return xAirplaneColor.CompareTo(yAirplaneColor); + } + if (xAirplane.GetAirplane.airplane is EntityAirbus xContainerShip && yAirplane.GetAirplane.airplane is EntityAirbus yContainerShip) + { + string xShipDopColor = xContainerShip.DopColor.Name; + string yShipDopColor = yContainerShip.DopColor.Name; + var dopColorCompare = xShipDopColor.CompareTo(yShipDopColor); + if (dopColorCompare != 0) + { + return dopColorCompare; + } + } + var speedCompare = xAirplane.GetAirplane.airplane.Speed.CompareTo(yAirplane.GetAirplane.airplane.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xAirplane.GetAirplane.airplane.Weight.CompareTo(yAirplane.GetAirplane.airplane.Weight); } } - } +} \ No newline at end of file diff --git a/Airbus/Airbus/AirplaneCompareByType.cs b/Airbus/Airbus/AirplaneCompareByType.cs index 04d80f3..443f53a 100644 --- a/Airbus/Airbus/AirplaneCompareByType.cs +++ b/Airbus/Airbus/AirplaneCompareByType.cs @@ -38,7 +38,7 @@ namespace Airbus } if (xAirplane.GetAirplane.GetType().Name != yAirplane.GetAirplane.GetType().Name) { - if (xAirplane.GetAirplane.GetType().Name == "DrawingAirplane") + if (xAirplane.GetAirplane.GetType().Name == "DrawningAirplane") { return -1; } diff --git a/Airbus/Airbus/DrawningObjectAirplane.cs b/Airbus/Airbus/DrawningObjectAirplane.cs index 4d22429..cf2c6d1 100644 --- a/Airbus/Airbus/DrawningObjectAirplane.cs +++ b/Airbus/Airbus/DrawningObjectAirplane.cs @@ -61,7 +61,22 @@ namespace Airbus { return false; } - // TODO доделать проверки в случае продвинутого объекта + + if (airplane is EntityAirbus airbus && otherAirplaneAirplane is EntityAirbus otherAirbus) + { + if (airbus.DopColor != otherAirbus.DopColor) + { + return false; + } + if (airbus.Engine != otherAirbus.Engine) + { + return false; + } + if (airbus.Compartment != otherAirbus.Compartment) + { + return false; + } + } return true; } } diff --git a/Airbus/Airbus/FormMapWithSetAirplane.cs b/Airbus/Airbus/FormMapWithSetAirplane.cs index 3f56206..f66c9b6 100644 --- a/Airbus/Airbus/FormMapWithSetAirplane.cs +++ b/Airbus/Airbus/FormMapWithSetAirplane.cs @@ -311,7 +311,12 @@ namespace Airbus private void buttonSortByColor_Click(object sender, EventArgs e) { - + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].Sort(new AirplaneCompareByColor()); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } } } diff --git a/Airbus/Airbus/SetAirplaneGeneric.cs b/Airbus/Airbus/SetAirplaneGeneric.cs index c3cabec..82104a2 100644 --- a/Airbus/Airbus/SetAirplaneGeneric.cs +++ b/Airbus/Airbus/SetAirplaneGeneric.cs @@ -24,6 +24,10 @@ namespace Airbus public int Insert(T airplane, int position) { + if (_places.Contains(airplane)) + { + return -1; + } if (Count == _maxCount) throw new StorageOverflowException(_maxCount); if (position < 0 || position > _places.Count) return -1;