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

46 lines
1.7 KiB
C#
Raw Normal View History

2024-06-16 21:39:45 +04:00
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;
2024-06-16 23:08:52 +04:00
2024-06-16 21:39:45 +04:00
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)
{
2024-06-16 23:08:52 +04:00
/* public Color AdditionalColor { get; private set; } // доп. цвет
2024-06-16 21:39:45 +04:00
// признаки (наличия)
public bool HelicopterPads { get; private set; } // вертолетная площадка
2024-06-16 23:08:52 +04:00
public bool Hangars { get; private set; } // ангар */
2024-06-16 21:39:45 +04:00
2024-06-16 23:08:52 +04:00
EntityCruiser EntityX = (EntityCruiser)x.EntityTransport;
EntityCruiser EntityY = (EntityCruiser)y.EntityTransport;
2024-06-16 21:39:45 +04:00
2024-06-16 23:08:52 +04:00
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
return false;
2024-06-16 21:39:45 +04:00
2024-06-16 23:08:52 +04:00
if (EntityX.Hangars != EntityY.Hangars)
return false;
if (EntityX.HelicopterPads != EntityY.HelicopterPads)
return false;
}
2024-06-16 21:39:45 +04:00
return true;
}
public int GetHashCode([DisallowNull] DrawningBase obj)
{
return obj.GetHashCode();
}
}