Komlev_S.I. Lab8 #10

Closed
SemkaKMLV wants to merge 3 commits from Lab8 into Lab7
4 changed files with 60 additions and 3 deletions
Showing only changes of commit aa244afca7 - Show all commits

View File

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

View File

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

View File

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

View File

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