From 8aa272b0cbb2fd6aaaeb343db5e641540af5fcb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Mon, 21 Nov 2022 19:58:14 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20=D1=88?= =?UTF-8?q?=D0=B0=D0=B3=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawingObjectArtillery.cs | 58 +++++++++++++++++++ SelfPropelledArtilleryUnit/IDrawingObject.cs | 2 +- .../SetArtilleriesGeneric.cs | 7 ++- 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs b/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs index b137411..bb7441b 100644 --- a/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs +++ b/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs @@ -40,5 +40,63 @@ namespace Artilleries public string GetInfo() => _artillery?.GetDateForSave(); public static IDrawingObject Create(string data) => new DrawingObjectArtillery(data.CreateDrawingArtillery()); + + public bool Equals(IDrawingObject? other) + { + if (other == null) + { + return false; + } + + var otherArtillery = other as DrawingObjectArtillery; + + if (otherArtillery == null) + { + return false; + } + + var artillery = _artillery.Artillery; + var otherArtilleryArtillery = otherArtillery._artillery.Artillery; + + if (artillery.GetType() != otherArtilleryArtillery.GetType()) + { + return false; + } + + if (artillery.Speed != otherArtilleryArtillery.Speed) + { + return false; + } + + if (artillery.Weight != otherArtilleryArtillery.Weight) + { + return false; + } + + if (artillery.BodyColor != otherArtilleryArtillery.BodyColor) + { + return false; + } + + if (artillery is EntityAdvancedArtillery advanced && otherArtilleryArtillery is EntityAdvancedArtillery otherAdvanced) + { + if (advanced.DopColor != otherAdvanced.DopColor) + { + return false; + } + + if (advanced.Weapon != otherAdvanced.Weapon) + { + return false; + } + + if (advanced.SalvoBattery != otherAdvanced.SalvoBattery) + { + return false; + } + } + + return true; + } } } diff --git a/SelfPropelledArtilleryUnit/IDrawingObject.cs b/SelfPropelledArtilleryUnit/IDrawingObject.cs index e2fddfe..6c2dd75 100644 --- a/SelfPropelledArtilleryUnit/IDrawingObject.cs +++ b/SelfPropelledArtilleryUnit/IDrawingObject.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Artilleries { - internal interface IDrawingObject + internal interface IDrawingObject : IEquatable { public float Step { get; } void SetObject(int x, int y, int width, int height); diff --git a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs index eeab600..aae0c0e 100644 --- a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs +++ b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Artilleries { internal class SetArtilleriesGeneric - where T : class + where T : class, IEquatable { private readonly List _places; public int Count => _places.Count; @@ -36,6 +36,11 @@ namespace Artilleries return -1; } + if (_places.Contains(artillery)) + { + return -1; + } + _places.Insert(position, artillery); return position;