Komlev_S.I. Lab8 #10
@ -38,5 +38,58 @@ namespace GasolineTanker
|
||||
}
|
||||
public string GetInfo() => _Tanker?.GetDataForSave();
|
||||
public static IDrawningObject Create(string data) => new DrawningObjectTanker(data.CreateDrawningTanker());
|
||||
|
||||
public bool Equals(IDrawningObject? other)
|
||||
{
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otherTanker = other as DrawningObjectTanker;
|
||||
if (otherTanker == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var tanker = _Tanker.Tanker;
|
||||
var otherTankerTanker = otherTanker._Tanker.Tanker;
|
||||
if (tanker.GetType().Name != otherTankerTanker.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (tanker.Speed != otherTankerTanker.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (tanker.Weight != otherTankerTanker.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (tanker.BodyColor != otherTankerTanker.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (tanker is EntityGasolineTanker gasolinetanker && otherTankerTanker is EntityGasolineTanker otherGasolineTanker)
|
||||
{
|
||||
if (gasolinetanker.DopColor != otherGasolineTanker.DopColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (gasolinetanker.Cabin != otherGasolineTanker.Cabin)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (gasolinetanker.Signal != otherGasolineTanker.Signal)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (gasolinetanker.BenzoBack != otherGasolineTanker.BenzoBack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace GasolineTanker
|
||||
{
|
||||
internal interface IDrawningObject
|
||||
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
|
@ -1,7 +1,7 @@
|
||||
namespace GasolineTanker
|
||||
{
|
||||
internal class MapWithSetTankersGeneric<T, U>
|
||||
where T : class, IDrawningObject
|
||||
where T : class, IDrawningObject,IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
private readonly int _pictureWidth;
|
||||
|
@ -1,7 +1,7 @@
|
||||
namespace GasolineTanker
|
||||
{
|
||||
internal class SetTankersGeneric<T>
|
||||
where T : class
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
private readonly List<T> _places;
|
||||
public int Count => _places.Count;
|
||||
@ -20,6 +20,10 @@
|
||||
public int Insert(T tanker, int position)
|
||||
|
||||
{
|
||||
if (_places.Contains(tanker))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (Count == _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
Loading…
Reference in New Issue
Block a user