BoatCompareByType full

This commit is contained in:
VictoriaPresnyakova 2022-12-04 16:36:25 +04:00
parent 20b507a35f
commit d48d24198b
2 changed files with 48 additions and 2 deletions

View File

@ -6,7 +6,52 @@ using System.Threading.Tasks;
namespace Catamaran
{
internal class BoatCompareByType
internal class BoatCompareByType : IComparer<IDrawingObject>
{
public int Compare(IDrawingObject x, IDrawingObject y)
{
if (x == null && y == null)
{
return 0;
}
if (x == null && y != null)
{
return 1;
}
if (x != null && y == null)
{
return -1;
}
var xBoat = x as DrawingObjectBoat;
var yBoat = y as DrawingObjectBoat;
if (xBoat == null && yBoat == null)
{
return 0;
}
if (xBoat == null && yBoat != null)
{
return 1;
}
if (xBoat != null && yBoat == null)
{
return -1;
}
if (xBoat.GetBoat.GetType().Name != yBoat.GetBoat.GetType().Name)
{
if (xBoat.GetBoat.GetType().Name == "DrawingBoat")
{
return -1;
}
return 1;
}
var speedCompare =
xBoat.GetBoat.Boat.Speed.CompareTo(yBoat.GetBoat.Boat.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return xBoat.GetBoat.Boat.Weight.CompareTo(yBoat.GetBoat.Boat.Weight);
}
}
}

View File

@ -14,6 +14,7 @@ namespace Catamaran
{
_catamaran = catamaran;
}
public DrawingBoat GetBoat => _catamaran;
public float Step => _catamaran?.Catamaran?.Step ?? 0;
public (float Left, float Right, float Top, float Bottom)
GetCurrentPosition()