PIbd-14_Pruidze_I.K_Simple_.../ProjectCruiser/DrawningSamples/DrawningShipCompare.cs

31 lines
818 B
C#
Raw Normal View History

2024-06-16 21:39:45 +04:00
namespace ProjectCruiser.DrawningSamples;
// Сравнение по типу, скорости, весу
public class DrawningShipCompare : IComparer<DrawningBase?>
{
public int Compare(DrawningBase? x, DrawningBase? y)
{
if (x == null || x.EntityTransport == null)
{
return -1;
}
if (y == null || y.EntityTransport == null)
{
return 1;
}
if (x.GetType().Name != y.GetType().Name)
{
return x.GetType().Name.CompareTo(y.GetType().Name);
}
var speedCompare = x.EntityTransport.Speed.CompareTo(y.EntityTransport.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityTransport.Weight.CompareTo(y.EntityTransport.Weight);
}
}