This commit is contained in:
Калышев Ян 2022-12-03 19:38:34 +04:00
parent 1c4c533ceb
commit 93a18dcbb5
4 changed files with 58 additions and 3 deletions

View File

@ -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;
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
{
internal interface IDrawningObject
internal interface IDrawningObject : IEquatable<IDrawningObject>
{
/// <summary>
/// Шаг перемещения объекта

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
{
internal class MapWithSetBoatsGeneric<T, U>
where T : class, IDrawningObject
where T : class, IDrawningObject, IEquatable<T>
where U : AbstractMap
{
/// <summary>

View File

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
{
internal class SetBoatsGeneric<T>
where T : class
where T : class, IEquatable<T>
{
/// <summary>
/// Список объектов, которые храним
@ -36,6 +36,10 @@ namespace PIbd_22_Kalyshev_Y_V_MotorBoat_Base
/// <returns></returns>
public int Insert(T boat)
{
if (!_places.Contains(boat))
{
return -1;
}
if (_places.Count < _maxCount)
{
_places.Add(boat);