From 590b2985a654dcf6acced096dc92f9edb235216c Mon Sep 17 00:00:00 2001 From: Anastasia Date: Thu, 22 Dec 2022 21:58:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B2=D0=BE=D1=81=D1=8C=D0=BC=D0=B0=D1=8F=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirplaneWithRadar/AirplaneCompareByColor.cs | 16 +++++++--------- .../AirplaneWithRadar/AirplaneCompareByType.cs | 4 ++-- .../AirplaneWithRadar/DrawingObjectAirplane.cs | 2 ++ .../AirplaneWithRadar/FormAirplaneWithRadar.cs | 6 +++++- .../AirplaneWithRadar/SetAirplanesGeneric.cs | 2 +- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs index eb9a760..a380cc3 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByColor.cs @@ -8,7 +8,7 @@ namespace AirplaneWithRadar { internal class AirplaneCompareByColor : IComparer { - public int Compare(IDrawingObject x, IDrawingObject y) + public int Compare(IDrawingObject? x, IDrawingObject? y) { if (x == null && y == null) { @@ -36,19 +36,17 @@ namespace AirplaneWithRadar { return -1; } - string xAirplaneColor = xAirplane.GetAirplane.Airplane.BodyColor.Name; - string yAirplaneColor = yAirplane.GetAirplane.Airplane.BodyColor.Name; - if (xAirplaneColor != yAirplaneColor) + var baseColorCompare = xAirplane.GetAirplane.Airplane.BodyColor.ToString().CompareTo(yAirplane.GetAirplane.Airplane.BodyColor.ToString()); + if (baseColorCompare != 0) { - return xAirplaneColor.CompareTo(yAirplane); + return baseColorCompare; } if (xAirplane.GetAirplane.Airplane is EntityAirplaneWithRadar xAirpl && yAirplane.GetAirplane.Airplane is EntityAirplaneWithRadar yAirpl) { - string xAirplaneDopColor = xAirpl.DopColor.Name; - string yAirplaneDopColor = yAirpl.DopColor.Name; - if (xAirplaneDopColor != yAirplaneDopColor) + var dopColorCompare = xAirpl.DopColor.ToString().CompareTo(yAirpl.DopColor.ToString()); + if (dopColorCompare != 0) { - return xAirplaneDopColor.CompareTo(yAirplaneDopColor); + return dopColorCompare; } } var speedCompare = xAirplane.GetAirplane.Airplane.Speed.CompareTo(yAirplane.GetAirplane.Airplane.Speed); diff --git a/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs index 2c33797..771d540 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/AirplaneCompareByType.cs @@ -40,9 +40,9 @@ namespace AirplaneWithRadar { if (xAirplane.GetAirplane.GetType().Name == "DrawingAirplane") { - return 1; + return -1; } - return -1; + return 1; } var speedCompare = xAirplane.GetAirplane.Airplane.Speed.CompareTo(yAirplane.GetAirplane.Airplane.Speed); if (speedCompare != 0) diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs index d2e1a3d..def80df 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingObjectAirplane.cs @@ -76,6 +76,8 @@ namespace AirplaneWithRadar return false; } } + else if (airplane is EntityAirplaneWithRadar || otherAirplaneAirplane is EntityAirplaneWithRadar) return false; + return true; } } diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs index 21d57ce..7a8ffa8 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs @@ -48,7 +48,11 @@ namespace AirplaneWithRadar SetData(); Draw(); } - + /// + /// Перемещение + /// + /// + /// private void ButtonMove_Click(object sender, EventArgs e) { string name = ((Button)sender)?.Name ?? string.Empty; diff --git a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs index f5f463e..b9cb5fe 100644 --- a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs +++ b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs @@ -152,6 +152,6 @@ namespace AirplaneWithRadar return; } _places.Sort(comparer); - } + } } }