Bondarenko M.S. Lab Work 8 #15

Closed
maxnes3 wants to merge 4 commits from LabWork_08 into LabWork_07
4 changed files with 51 additions and 3 deletions
Showing only changes of commit a2d2543486 - Show all commits

View File

@ -40,5 +40,49 @@ namespace WarmlyShip
public string GetInfo() => _warmlyShip?.GetDataForSave();
public static IDrawningObject Create(string data) => new DrawningObjectShip(data.CreateDrawningShip());
public bool Equals(IDrawningObject? other)
{
if (other == null)
{
return false;
}
var otherShip = other as DrawningObjectShip;
if (otherShip == null)
{
return false;
}
var ship = _warmlyShip.warmlyShip;
var otherShipShip = otherShip._warmlyShip.warmlyShip;
if (ship.Speed != otherShipShip.Speed)
{
return false;
}
if (ship.Weight != otherShipShip.Weight)
{
return false;
}
if (ship.BodyColor != otherShipShip.BodyColor)
{
return false;
}
if (ship is EntityMotorShip motorShip && otherShipShip is EntityMotorShip otherMotorShip)
{
if (motorShip.DopColor != otherMotorShip.DopColor)
{
return false;
}
if (motorShip.Tubes != otherMotorShip.Tubes)
{
return false;
}
if (motorShip.Cistern != otherMotorShip.Cistern)
{
return false;
}
}
return true;
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace WarmlyShip
{
internal interface IDrawningObject
internal interface IDrawningObject : IEquatable<IDrawningObject>
{
public float Step { get; }
void SetObject(int x, int y, int width, int height);

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace WarmlyShip
{
internal class MapWithSetShipGeneric<T, U>
where T : class, IDrawningObject
where T : class, IDrawningObject, IEquatable<T>
where U : AbstractMap
{
private readonly int _pictureWidth;

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace WarmlyShip
{
internal class SetShipGeneric<T>
where T : class
where T : class, IEquatable<T>
{
private readonly List<T> _places;
public int Count => _places.Count;
@ -27,6 +27,10 @@ namespace WarmlyShip
public int Insert(T ship, int position)
{
if (_places.Contains(ship))
{
return -1;
}
if (position < 0 || position > Count || Count == _maxCount) throw new StorageOverflowException(_maxCount);
_places.Insert(position, ship);
return position;