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