PIBD-14_Lavrova_K.I._Simple/solution/lab1/Drawnings/DrawningTrackedVehicleEqutables.cs

59 lines
1.6 KiB
C#
Raw Permalink Normal View History

2024-10-22 13:37:29 +04:00
using lab1.Drawnings;
using lab1.Entities;
using System.Diagnostics.CodeAnalysis;
namespace lab1;
public class DrawningTrackedVehicleEqutables : IEqualityComparer<DrawningTrackedVehicle?>
{
public bool Equals(DrawningTrackedVehicle? x, DrawningTrackedVehicle? y)
{
if (x == null || x.EntityTrackedVehicle == null)
{
return false;
}
if (y == null || y.EntityTrackedVehicle == null)
{
return false;
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityTrackedVehicle.Speed != y.EntityTrackedVehicle.Speed)
{
return false;
}
if (x.EntityTrackedVehicle.Weight != y.EntityTrackedVehicle.Weight)
{
return false;
}
if (x.EntityTrackedVehicle.BodyColor != y.EntityTrackedVehicle.BodyColor)
{
return false;
}
if (x is DrawningEntityFighter && y is DrawningEntityFighter)
{
EntityFighter _x = (EntityFighter)x.EntityTrackedVehicle;
EntityFighter _y = (EntityFighter)x.EntityTrackedVehicle;
if (_x.AdditionalColor != _y.AdditionalColor)
{
return false;
}
if (_x.Kovsh != _y.Kovsh)
{
return false;
}
if (_x.Otval != _y.Otval)
{
return false;
}
}
return true;
}
public int GetHashCode([DisallowNull] DrawningTrackedVehicle obj)
{
return obj.GetHashCode();
}
}