diff --git a/ProjectStormtrooper/ProjectStormtrooper/DrawingPlaneEqutables.cs b/ProjectStormtrooper/ProjectStormtrooper/DrawingPlaneEqutables.cs new file mode 100644 index 0000000..9c93c03 --- /dev/null +++ b/ProjectStormtrooper/ProjectStormtrooper/DrawingPlaneEqutables.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectStormtrooper +{ + public class DrawingPlaneEqutables : IEqualityComparer + { + public bool Equals(DrawingPlane? x, DrawingPlane? y) + { + if (x == null || x.EntityPlane == null) + { + throw new ArgumentNullException(nameof(x)); + } + if (y == null || y.EntityPlane == null) + { + throw new ArgumentNullException(nameof(y)); + } + if (x.GetType().Name != y.GetType().Name) + { + return false; + } + if (x.EntityPlane.Speed != y.EntityPlane.Speed) + { + return false; + } + if (x.EntityPlane.Weight != y.EntityPlane.Weight) + { + return false; + } + if (x.EntityPlane.BodyColor != y.EntityPlane.BodyColor) + { + return false; + } + if (x is DrawingStormtrooper && y is DrawingStormtrooper) + { + var xStormtrooper = (x.EntityPlane as EntityStormtrooper); + var yStormtrooper = (y.EntityPlane as EntityStormtrooper); + if (xStormtrooper?.AdditionalColor != yStormtrooper?.AdditionalColor) + { + return false; + } + if (xStormtrooper?.Bombs != yStormtrooper?.Bombs) + { + return false; + } + if (xStormtrooper?.Rockets != yStormtrooper?.Rockets) + { + return false; + } + } + return true; + } + + public int GetHashCode([DisallowNull] DrawingPlane obj) + { + return obj.GetHashCode(); + } + } +}