using ProjectTank.DrawningObjects; using ProjectTank.Entities; using System.Diagnostics.CodeAnalysis; namespace ProjectTank.Generics { internal class DrawningTankBaseEqutables : IEqualityComparer { public bool Equals(DrawningTankBase? x, DrawningTankBase? y) { if (x == null || x.EntityTankBase == null) { throw new ArgumentNullException(nameof(x)); } if (y == null || y.EntityTankBase == null) { throw new ArgumentNullException(nameof(y)); } if (x.GetType().Name != y.GetType().Name) { return false; } if (x.EntityTankBase.Speed != y.EntityTankBase.Speed) { return false; } if (x.EntityTankBase.Weight != y.EntityTankBase.Weight) { return false; } if (x.EntityTankBase.BodyColor != y.EntityTankBase.BodyColor) { return false; } if (x is DrawningTank && y is DrawningTank) { EntityTank EntityX = (EntityTank)x.EntityTankBase; EntityTank EntityY = (EntityTank)y.EntityTankBase; if (EntityX.AntiAirforceGun != EntityY.AntiAirforceGun) return false; if (EntityX.TankTower != EntityY.TankTower) return false; if (EntityX.AdditionalColor != EntityY.AdditionalColor) return false; } return true; } public int GetHashCode([DisallowNull] DrawningTankBase obj) { return obj.GetHashCode(); } } }