From 950ea78e74dad8ade87e1d97945659610a68f11e Mon Sep 17 00:00:00 2001 From: malimova Date: Mon, 25 Dec 2023 18:52:55 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=20=D1=81=D1=80=D0=B0=D0=B2=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/PlaneCompareByColor.cs | 57 ++++++++++++++++++++++ AirBomber/AirBomber/PlaneCompareByType.cs | 39 +++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 AirBomber/AirBomber/PlaneCompareByColor.cs create mode 100644 AirBomber/AirBomber/PlaneCompareByType.cs diff --git a/AirBomber/AirBomber/PlaneCompareByColor.cs b/AirBomber/AirBomber/PlaneCompareByColor.cs new file mode 100644 index 0000000..9272b95 --- /dev/null +++ b/AirBomber/AirBomber/PlaneCompareByColor.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AirBomber.DrawningObjects; +using AirBomber.Entities; + +namespace AirBomber +{ + internal class PlaneCompareByColor: IComparer + { + public int Compare(DrawningAirPlane? x, DrawningAirPlane? y) + { + if (x == null || x.EntityAirPlane == null) + { + throw new ArgumentNullException(nameof(x)); + } + + if (y == null || y.EntityAirPlane == null) + { + throw new ArgumentNullException(nameof(y)); + } + + var bodyColorCompare = x.EntityAirPlane.BodyColor.Name.CompareTo(y.EntityAirPlane.BodyColor.Name); + + if (bodyColorCompare != 0) + { + return bodyColorCompare; + } + + if (x.EntityAirPlane is EntityAirBomber xEntitySailCatamaran && y.EntityAirPlane is EntityAirBomber yEntitySailCatamaran) + { + var BodyColorCompare = xEntitySailCatamaran.BodyColor.Name.CompareTo(yEntitySailCatamaran.BodyColor.Name); + if (BodyColorCompare != 0) + { + return BodyColorCompare; + } + var AdditionalColorCompare = xEntitySailCatamaran.AdditionalColor.Name.CompareTo(yEntitySailCatamaran.AdditionalColor.Name); + if (AdditionalColorCompare != 0) + { + return AdditionalColorCompare; + } + } + + var speedCompare = x.EntityAirPlane.Speed.CompareTo(y.EntityAirPlane.Speed); + + if (speedCompare != 0) + { + return speedCompare; + } + + return x.EntityAirPlane.Weight.CompareTo(y.EntityAirPlane.Weight); + } + } +} + diff --git a/AirBomber/AirBomber/PlaneCompareByType.cs b/AirBomber/AirBomber/PlaneCompareByType.cs new file mode 100644 index 0000000..9ddc482 --- /dev/null +++ b/AirBomber/AirBomber/PlaneCompareByType.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using AirBomber.DrawningObjects; + +namespace AirBomber.Generics +{ + internal class PlaneCompareByType: IComparer + { + public int Compare(DrawningAirPlane? x, DrawningAirPlane? y) + { + if (x == null || x.EntityAirPlane == null) + { + throw new ArgumentNullException(nameof(x)); + } + + if (y == null || y.EntityAirPlane == null) + { + throw new ArgumentNullException(nameof(y)); + } + + if (x.GetType().Name != y.GetType().Name) + { + return x.GetType().Name.CompareTo(y.GetType().Name); + } + + var speedCompare = x.EntityAirPlane.Speed.CompareTo(y.EntityAirPlane.Speed); + + if (speedCompare != 0) + { + return speedCompare; + } + + return x.EntityAirPlane.Weight.CompareTo(y.EntityAirPlane.Weight); + } + } +}