From 85829c9c39eed2f14498fda14073c5a086028ac3 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Sat, 16 Dec 2023 23:13:55 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D1=8B=20PlaneComp?= =?UTF-8?q?are?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PlaneCompareByColor.cs | 33 +++++++++++++++++++ .../ProjectStormtrooper/PlaneCompareByType.cs | 33 +++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 ProjectStormtrooper/ProjectStormtrooper/PlaneCompareByColor.cs create mode 100644 ProjectStormtrooper/ProjectStormtrooper/PlaneCompareByType.cs diff --git a/ProjectStormtrooper/ProjectStormtrooper/PlaneCompareByColor.cs b/ProjectStormtrooper/ProjectStormtrooper/PlaneCompareByColor.cs new file mode 100644 index 0000000..f90183d --- /dev/null +++ b/ProjectStormtrooper/ProjectStormtrooper/PlaneCompareByColor.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectStormtrooper +{ + public class PlaneCompareByColor : IComparer + { + public int Compare(DrawingPlane? x, DrawingPlane? y) + { + if (x == null || x.EntityPlane == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.EntityPlane == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.EntityPlane.BodyColor != y.EntityPlane.BodyColor) + { + return x.EntityPlane.BodyColor.Name.CompareTo(y.EntityPlane.BodyColor.Name); + } + var speedCompare = x.EntityPlane.Speed.CompareTo(y.EntityPlane.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return x.EntityPlane.Weight.CompareTo(y.EntityPlane.Weight); + } + } +} diff --git a/ProjectStormtrooper/ProjectStormtrooper/PlaneCompareByType.cs b/ProjectStormtrooper/ProjectStormtrooper/PlaneCompareByType.cs new file mode 100644 index 0000000..7dd60c5 --- /dev/null +++ b/ProjectStormtrooper/ProjectStormtrooper/PlaneCompareByType.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectStormtrooper +{ + public class PlaneCompareByType : IComparer + { + public int Compare(DrawingPlane? x, DrawingPlane? y) + { + if (x == null || x.EntityPlane == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.EntityPlane == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.GetType().Name != y.GetType().Name) + { + return x.GetType().Name.CompareTo(y.GetType().Name); + } + var speedCompare = x.EntityPlane.Speed.CompareTo(y.EntityPlane.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return x.EntityPlane.Weight.CompareTo(y.EntityPlane.Weight); + } + } +}