diff --git a/Stormtrooper/Stormtrooper/StormtrooperCompareByColor.cs b/Stormtrooper/Stormtrooper/StormtrooperCompareByColor.cs new file mode 100644 index 0000000..246872d --- /dev/null +++ b/Stormtrooper/Stormtrooper/StormtrooperCompareByColor.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class StormtrooperCompareByColor : IComparer + { + public int Compare(IDrawningObject? x, IDrawningObject? y) + { + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xStorm = x as DrawningObjectStorm; + var yStorm = y as DrawningObjectStorm; + if (xStorm == null && yStorm == null) + { + return 0; + } + if (xStorm == null && yStorm != null) + { + return 1; + } + if (xStorm != null && yStorm == null) + { + return -1; + } + + var baseColorCompare = xStorm.GetStormtrooper.Storm.BodyColor.ToString().CompareTo(yStorm.GetStormtrooper.Storm.BodyColor.ToString()); + if (baseColorCompare != 0) + { + return baseColorCompare; + } + + if (xStorm.GetStormtrooper.Storm is EntityMilitaryStormtrooper xDDB && yStorm.GetStormtrooper.Storm is EntityMilitaryStormtrooper yDDB) + { + var extraColorCompare = xDDB.BodyColor.ToString().CompareTo(yDDB.BodyColor.ToString()); + if (extraColorCompare != 0) + { + return extraColorCompare; + } + } + + return 0; + } + } +} diff --git a/Stormtrooper/Stormtrooper/StormtrooperCompareByType.cs b/Stormtrooper/Stormtrooper/StormtrooperCompareByType.cs new file mode 100644 index 0000000..a8694c6 --- /dev/null +++ b/Stormtrooper/Stormtrooper/StormtrooperCompareByType.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Stormtrooper +{ + internal class StormtrooperCompareByType : IComparer + { + public int Compare(IDrawningObject? x, IDrawningObject? y) + { + if (x == null && y == null) + { + return 0; + } + if (x == null && y != null) + { + return 1; + } + if (x != null && y == null) + { + return -1; + } + var xStorm = x as DrawningObjectStorm; + var yStorm = y as DrawningObjectStorm; + if (xStorm == null && yStorm == null) + { + return 0; + } + if (xStorm == null && yStorm != null) + { + return 1; + } + if (xStorm != null && yStorm == null) + { + return -1; + } + if (xStorm.GetStormtrooper.GetType().Name != yStorm.GetStormtrooper.GetType().Name) + { + if (xStorm.GetStormtrooper.GetType().Name == "Drawning") + { + return -1; + } + return 1; + } + var speedCompare = xStorm.GetStormtrooper.Storm.Speed.CompareTo(yStorm.GetStormtrooper.Storm.Speed); + if (speedCompare != 0) + { + return speedCompare; + } + return xStorm.GetStormtrooper.Storm.Weight.CompareTo(yStorm.GetStormtrooper.Storm.Weight); + } + } +}