PIbd-14_Pruidze_I.K_Simple_.../ProjectCruiser/DrawningSamples/DrawningShipEqutables.cs
2024-06-16 23:08:52 +04:00

46 lines
1.7 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; } // ангар */
EntityCruiser EntityX = (EntityCruiser)x.EntityTransport;
EntityCruiser EntityY = (EntityCruiser)y.EntityTransport;
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
return false;
if (EntityX.Hangars != EntityY.Hangars)
return false;
if (EntityX.HelicopterPads != EntityY.HelicopterPads)
return false;
}
return true;
}
public int GetHashCode([DisallowNull] DrawningBase obj)
{
return obj.GetHashCode();
}
}