Zhimolostnova A.V. Lab work 8 #8
@ -39,5 +39,48 @@ namespace Warship
|
||||
public string GetInfo() => _warship?.GetDataForSave();
|
||||
|
||||
public static IDrawingObject Create(string data) => new DrawingObjectWarship(data.CreateDrawingWarship());
|
||||
|
||||
public bool Equals(IDrawingObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
return false;
|
||||
|
||||
var otherWarship = other as DrawingObjectWarship;
|
||||
|
||||
if (otherWarship == null)
|
||||
return false;
|
||||
|
||||
var warship = _warship.Warship;
|
||||
var otherWarshipWarship = otherWarship._warship.Warship;
|
||||
|
||||
if (warship.GetType() != otherWarshipWarship.GetType())
|
||||
return false;
|
||||
|
||||
if (warship.Speed != otherWarshipWarship.Speed)
|
||||
return false;
|
||||
|
||||
if (warship.Weight != otherWarshipWarship.Weight)
|
||||
return false;
|
||||
|
||||
if (warship.BodyColor != otherWarshipWarship.BodyColor)
|
||||
return false;
|
||||
|
||||
if(warship is EntityAdvancedWarship adv && otherWarshipWarship is EntityAdvancedWarship otherAdv)
|
||||
{
|
||||
if (adv.DopColor != otherAdv.DopColor)
|
||||
return false;
|
||||
|
||||
if (adv.Antenna != otherAdv.Antenna)
|
||||
return false;
|
||||
|
||||
if (adv.Helipad != otherAdv.Helipad)
|
||||
return false;
|
||||
|
||||
if (adv.Missile != otherAdv.Missile)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Warship
|
||||
{
|
||||
internal interface IDrawingObject
|
||||
internal interface IDrawingObject : IEquatable<IDrawingObject>
|
||||
{
|
||||
public float Step { get; }
|
||||
void SetObject(int x, int y, int width, int height);
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace Warship
|
||||
{
|
||||
internal class MapWithSetWarshipsGeneric<T,U>
|
||||
where T : class, IDrawingObject
|
||||
where T : class, IDrawingObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace Warship
|
||||
{
|
||||
internal class SetWarshipsGeneric<T>
|
||||
where T : class
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
private readonly List<T> _places;
|
||||
|
||||
@ -25,15 +25,22 @@ namespace Warship
|
||||
{
|
||||
if (Count >= _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
||||
_places.Insert(0, warship);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int Insert(T warship, int position)
|
||||
{
|
||||
if (_places.Contains(warship))
|
||||
return -1;
|
||||
|
||||
if (position >= _maxCount || position < 0)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
||||
_places.Insert(position, warship);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user