Dolgov D.A. Lab Work 8 #8

Closed
devil_1nc wants to merge 4 commits from LabWork08 into LabWork07
4 changed files with 51 additions and 3 deletions
Showing only changes of commit 5d0cd05891 - Show all commits

View File

@ -40,6 +40,52 @@ namespace ProjectPlane
public string GetInfo() => _plane?.GetDataForSave();
public static IDrawingObject Create(string data) => new DrawingObject(data.CreateDrawingPlane());
public bool Equals(IDrawingObject? other)
{
if (other == null)
{
return false;
}
var otherPlane = other as DrawingObject;
if (otherPlane == null)
{
return false;
}
var plane = _plane.Plane;
var otherPlanePlane = otherPlane._plane.Plane;
if (plane.Speed != otherPlanePlane.Speed)
{
return false;
}
if (plane.Weight != otherPlanePlane.Weight)
{
return false;
}
if (plane.BodyColor != otherPlanePlane.BodyColor)
{
return false;
}
if (plane.GetType() != otherPlanePlane.GetType())
{
return false;
}
if (plane is EntityWarPlane advanced && otherPlanePlane is EntityWarPlane otheradvanced)
{
if (advanced.DopColor != otheradvanced.DopColor)
{
return false;
}
if (advanced.extraCell != otheradvanced.extraCell)
{
return false;
}
if (advanced.SuperTurbine != otheradvanced.SuperTurbine)
{
return false;
}
}
return true;
}
}
}

View File

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

View File

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

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace ProjectPlane
{
internal class SetPlanesGeneric<T> where T : class
internal class SetPlanesGeneric<T> where T : class, IEquatable<T>
{
/// <summary>
/// Список объектов, которые храним
@ -43,6 +43,8 @@ namespace ProjectPlane
/// <returns></returns>
public int Insert(T plane, int position)
{
if (_places.Contains(plane)) throw new ArgumentException("Данный объект уже есть в списке");
if (position < 0 || position >= _maxCount) throw new StorageOverflowException(_maxCount);
_places.Insert(position, plane);
return position;