This commit is contained in:
VictoriaPresnyakova 2022-12-04 18:55:01 +04:00
parent 4d6bd4e5ae
commit 39170916b9
3 changed files with 40 additions and 6 deletions

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Catamaran
{
internal abstract class AbstractMap
internal abstract class AbstractMap : IEquatable<AbstractMap>
{
private IDrawingObject _drawingObject = null;
protected int[,] _map = null;
@ -160,5 +160,31 @@ namespace Catamaran
protected abstract void DrawRoadPart(Graphics g, int i, int j);
protected abstract void DrawBarrierPart(Graphics g, int i, int j);
public bool Equals(AbstractMap other)
{
if (other == null)
{
return false;
}
var thisMap = this;
var otherMap = other;
if (thisMap._width != otherMap._width) return false;
if (thisMap._height != otherMap._height) return false;
if (thisMap._size_x != otherMap._size_x) return false;
if (thisMap._size_y != otherMap._size_y) return false;
if (thisMap._map.GetLength(0) != otherMap._map.GetLength(0) || thisMap._map.GetLength(1) != otherMap._map.GetLength(1)) return false;
for (int i = 0; i < thisMap._map.GetLength(0); i++)
{
for (int j = 0; j < thisMap._map.GetLength(1); j++)
{
if (thisMap._map[i, j] != otherMap._map[i, j]) return false;
}
}
return true;
}
}
}

View File

@ -13,7 +13,7 @@ namespace Catamaran
/// <typeparam name="T"></typeparam>
/// <typeparam name="U"></typeparam>
internal class MapWithSetBoatsGeneric<T, U>
where T : class, IDrawingObject
where T : class, IDrawingObject, IEquatable<T>
where U : AbstractMap
{
/// <summary>
@ -214,7 +214,7 @@ namespace Catamaran
/// <param name="comparer"></param>
public void Sort(IComparer<T> comparer)
{
_setCars.SortSet(comparer);
_setBoats.SortSet(comparer);
}
}
}

View File

@ -39,9 +39,17 @@ namespace Catamaran
/// <returns></returns>
public int Insert(T boat)
{
if (_places.Contains(boat)) return -1 ;
for (int i = 0; i < _maxCount; i++)
{
if (i == Count)
{
_places.Insert(i, boat);
return i;
}
}
throw new StorageOverflowException(_maxCount);
return Insert(boat, 0);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
@ -52,7 +60,7 @@ namespace Catamaran
public int Insert(T boat, int position)
{
// TODO проверка на уникальность
// проверка позиции
if (position < 0 || position >= _maxCount)
{