Добавлены классы PlaneCompare

This commit is contained in:
Никита Потапов 2023-12-16 23:13:55 +04:00
parent adbf68e639
commit 85829c9c39
2 changed files with 66 additions and 0 deletions
ProjectStormtrooper/ProjectStormtrooper

@ -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<DrawingPlane?>
{
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);
}
}
}

@ -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<DrawingPlane?>
{
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);
}
}
}