From 93a18dcbb56d799f4658156734e905dad8fbfeca Mon Sep 17 00:00:00 2001 From: Zyzf Date: Sat, 3 Dec 2022 19:38:34 +0400 Subject: [PATCH] 1st step --- .../DrawningObjectBoat.cs | 51 +++++++++++++++++++ .../IDrawningObject.cs | 2 +- .../MapWithSetBoatsGeneric.cs | 2 +- .../SetBoatsGeneric.cs | 6 ++- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/DrawningObjectBoat.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/DrawningObjectBoat.cs index 6dc06c4..e113eca 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/DrawningObjectBoat.cs +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/DrawningObjectBoat.cs @@ -32,5 +32,56 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base _boat.SetPosition(x, y, width, height); } public static IDrawningObject Create(string data) => new DrawningObjectBoat(data.CreateDrawningBoat()); + + public bool Equals(IDrawningObject? other) + { + if (other == null) + { + return false; + } + var otherBoat = other as DrawningObjectBoat; + if (otherBoat == null) + { + return false; + } + var boat = _boat.Boat; + var otherBoatBoat = otherBoat._boat.Boat; + if (boat.GetType() != otherBoatBoat.GetType()) + { + return false; + } + if (boat.Speed != otherBoatBoat.Speed) + { + return false; + } + if (boat.Weight != otherBoatBoat.Weight) + { + return false; + } + if (boat.BodyColor != otherBoatBoat.BodyColor) + { + return false; + } + if (boat is EntitySpeedboat speedboat && otherBoatBoat is EntitySpeedboat otherSpeedboatSpeedboat) + { + if (speedboat.DopColor != otherSpeedboatSpeedboat.DopColor) + { + return false; + } + if (speedboat.BodyKit != otherSpeedboatSpeedboat.BodyKit) + { + return false; + } + if (speedboat.Wing != otherSpeedboatSpeedboat.Wing) + { + return false; + } + if (speedboat.SportLine != otherSpeedboatSpeedboat.SportLine) + { + return false; + } + } + return true; + } } } diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/IDrawningObject.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/IDrawningObject.cs index e2ce4e7..a1777cc 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/IDrawningObject.cs +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/IDrawningObject.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base { - internal interface IDrawningObject + internal interface IDrawningObject : IEquatable { /// /// Шаг перемещения объекта diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapWithSetBoatsGeneric.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapWithSetBoatsGeneric.cs index 0f6e139..0a75b06 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapWithSetBoatsGeneric.cs +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/MapWithSetBoatsGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base { internal class MapWithSetBoatsGeneric - where T : class, IDrawningObject + where T : class, IDrawningObject, IEquatable where U : AbstractMap { /// diff --git a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/SetBoatsGeneric.cs b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/SetBoatsGeneric.cs index 1c0f397..022d7b9 100644 --- a/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/SetBoatsGeneric.cs +++ b/PIbd-22_Kalyshev_Y_V_MotorBoat_Base/SetBoatsGeneric.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base { internal class SetBoatsGeneric - where T : class + where T : class, IEquatable { /// /// Список объектов, которые храним @@ -36,6 +36,10 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base /// public int Insert(T boat) { + if (!_places.Contains(boat)) + { + return -1; + } if (_places.Count < _maxCount) { _places.Add(boat);