diff --git a/Catamaran/BoatCompareByType.cs b/Catamaran/BoatCompareByType.cs index f126f70..86cefc1 100644 --- a/Catamaran/BoatCompareByType.cs +++ b/Catamaran/BoatCompareByType.cs @@ -6,7 +6,52 @@ using System.Threading.Tasks; namespace Catamaran { - internal class BoatCompareByType + internal class BoatCompareByType : IComparer { + 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); + } } } + diff --git a/Catamaran/DrawingObjectBoat.cs b/Catamaran/DrawingObjectBoat.cs index 078200f..1758dd6 100644 --- a/Catamaran/DrawingObjectBoat.cs +++ b/Catamaran/DrawingObjectBoat.cs @@ -14,9 +14,10 @@ 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() + GetCurrentPosition() { return _catamaran?.GetCurrentPosition() ?? default; }