53 lines
1.7 KiB
C#
53 lines
1.7 KiB
C#
using ProjectTank.DrawningObjects;
|
|
using ProjectTank.Entities;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
namespace ProjectTank.Generics
|
|
{
|
|
internal class DrawningTankBaseEqutables : IEqualityComparer<DrawningTankBase?>
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
} |