PIbd-14_Pruidze_I.K_Simple_.../ProjectCruiser/DrawningSamples/DrawningShipCompare.cs
2024-06-16 23:08:52 +04:00

32 lines
819 B
C#

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