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); + } + } +}