diff --git a/Catamaran/AbstractMap.cs b/Catamaran/AbstractMap.cs index a6c19cb..0137b3a 100644 --- a/Catamaran/AbstractMap.cs +++ b/Catamaran/AbstractMap.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Catamaran { - internal abstract class AbstractMap + internal abstract class AbstractMap : IEquatable { 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; + } + } } diff --git a/Catamaran/MapWithSetBoatsGeneric.cs b/Catamaran/MapWithSetBoatsGeneric.cs index 82f10e8..116b901 100644 --- a/Catamaran/MapWithSetBoatsGeneric.cs +++ b/Catamaran/MapWithSetBoatsGeneric.cs @@ -13,7 +13,7 @@ namespace Catamaran /// /// internal class MapWithSetBoatsGeneric - where T : class, IDrawingObject + where T : class, IDrawingObject, IEquatable where U : AbstractMap { /// @@ -214,7 +214,7 @@ namespace Catamaran /// public void Sort(IComparer comparer) { - _setCars.SortSet(comparer); + _setBoats.SortSet(comparer); } } } diff --git a/Catamaran/SetBoatsGeneric.cs b/Catamaran/SetBoatsGeneric.cs index 500620d..13a77f6 100644 --- a/Catamaran/SetBoatsGeneric.cs +++ b/Catamaran/SetBoatsGeneric.cs @@ -39,9 +39,17 @@ namespace Catamaran /// 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); - } /// /// Добавление объекта в набор на конкретную позицию @@ -52,7 +60,7 @@ namespace Catamaran public int Insert(T boat, int position) { // TODO проверка на уникальность - + // проверка позиции if (position < 0 || position >= _maxCount) {