PIbd-14_Pruidze_I.K_Simple_.../ProjectCruiser/DrawningSamples/DrawningShipEqutables.cs

44 lines
1.8 KiB
C#

using System.Diagnostics.CodeAnalysis;
using ProjectCruiser.Entities;
namespace ProjectCruiser.DrawningSamples;
// Реализация сравнения двух объектов класса-прорисовки
public class DrawiningShipEqutables : IEqualityComparer<DrawningBase?>
{
public bool Equals(DrawningBase? x, DrawningBase? y)
{
if (x == null || x.EntityTransport == null) return false;
if (y == null || y.EntityTransport == null) return false;
if (x.GetType().Name != y.GetType().Name) return false;
if (x.EntityTransport.Speed != y.EntityTransport.Speed) return false;
if (x.EntityTransport.Weight != y.EntityTransport.Weight) return false;
if (x.EntityTransport.MainColor != y.EntityTransport.MainColor) return false;
if (x is DrawningCruiser && y is DrawningCruiser)
{
/*
public Color AdditionalColor { get; private set; } // доп. цвет
// признаки (наличия)
public bool HelicopterPads { get; private set; } // вертолетная площадка
public bool Hangars { get; private set; } // ангар
*/
if (((EntityCruiser)x.EntityTransport).AdditionalColor
!= ((EntityCruiser)y.EntityTransport).AdditionalColor) return false;
if (((EntityCruiser)x.EntityTransport).HelicopterPads
!= ((EntityCruiser)y.EntityTransport).HelicopterPads) return false;
if (((EntityCruiser)x.EntityTransport).Hangars
!= ((EntityCruiser)y.EntityTransport).Hangars) return false;
}
return true;
}
public int GetHashCode([DisallowNull] DrawningBase obj)
{
return obj.GetHashCode();
}
}