diff --git a/AircraftCarrier/AircraftCarrier/DrawningObjectAircraftCarrier.cs b/AircraftCarrier/AircraftCarrier/DrawningObjectAircraftCarrier.cs index f780fdc..6f9776c 100644 --- a/AircraftCarrier/AircraftCarrier/DrawningObjectAircraftCarrier.cs +++ b/AircraftCarrier/AircraftCarrier/DrawningObjectAircraftCarrier.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms.Design.Behavior; namespace AircraftCarrier { @@ -14,6 +15,7 @@ namespace AircraftCarrier _aircraftcarrier = aircraftcarrier; } public float Step => _aircraftcarrier?.AircraftCarrier?.Step ?? 0; + public DrawningAircraftCarrier GetAircraftCarrier => _aircraftcarrier; public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() { return _aircraftcarrier?.GetCurrentPosition() ?? default; @@ -32,5 +34,61 @@ namespace AircraftCarrier } public string GetInfo() => _aircraftcarrier?.GetDataForSave(); public static IDrawningObject Create(string data) => new DrawningObjectAircraftCarrier(data.CreateDrawningAircraftCarrier()); + public bool Equals(IDrawningObject? other) + { + if (other == null) + { + return false; + } + var otherAircraftCarrier = other as DrawningObjectAircraftCarrier; + if (otherAircraftCarrier == null) + { + return false; + } + var aircraftcarrier = _aircraftcarrier.AircraftCarrier; + var otherAircraftCarrierAircraftCarrier = otherAircraftCarrier._aircraftcarrier.AircraftCarrier; + + if (aircraftcarrier.GetType().Name != otherAircraftCarrierAircraftCarrier.GetType().Name) + { + return false; + } + if (aircraftcarrier.Speed != otherAircraftCarrierAircraftCarrier.Speed) + { + return false; + } + if (aircraftcarrier.Weight != otherAircraftCarrierAircraftCarrier.Weight) + { + return false; + } + if (aircraftcarrier.BodyColor != otherAircraftCarrierAircraftCarrier.BodyColor) + { + return false; + } + // TODO доделать проверки в случае продвинутого объекта + if (aircraftcarrier is EntityModernAircraftCarrier Modernaircraftcarrier && otherAircraftCarrierAircraftCarrier is EntityModernAircraftCarrier otherModernaircraftcarrier) + { + if (Modernaircraftcarrier.Route != otherModernaircraftcarrier.Route) + { + return false; + } + if (Modernaircraftcarrier.FlightDeck != otherModernaircraftcarrier.FlightDeck) + { + return false; + } + if (Modernaircraftcarrier.HangarDeck != otherModernaircraftcarrier.HangarDeck) + { + return false; + } + if (Modernaircraftcarrier.DopColor != otherModernaircraftcarrier.DopColor) + { + return false; + } + } + else if (aircraftcarrier is EntityModernAircraftCarrier || aircraftcarrier is EntityModernAircraftCarrier) + { + return false; + } + return true; + } } } \ No newline at end of file