diff --git a/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs b/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs index e3901b1..a5b2393 100644 --- a/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/MapWithSetWarmlyShipGeneric.cs @@ -164,10 +164,13 @@ namespace WarmlyShip /// private void DrawWarmlyShip(Graphics g) { + int width = _pictureWidth / _placeSizeWidth; + int k = 0; foreach (var ship in _setWarmlyShip.GetShip()) { - // TODO установка позиции + ship.SetObject(k % width * _placeSizeWidth + 10, k / width * _placeSizeHeight + 20, _pictureWidth, _pictureHeight); ship.DrawningObject(g); + k++; } } diff --git a/WarmlyShip/WarmlyShip/MapsCollection.cs b/WarmlyShip/WarmlyShip/MapsCollection.cs index add470b..361ef5e 100644 --- a/WarmlyShip/WarmlyShip/MapsCollection.cs +++ b/WarmlyShip/WarmlyShip/MapsCollection.cs @@ -6,6 +6,9 @@ using System.Threading.Tasks; namespace WarmlyShip { + /// + /// Класс для хранения коллекции карт + /// internal class MapsCollection { /// @@ -42,7 +45,8 @@ namespace WarmlyShip /// Карта public void AddMap(string name, AbstractMap map) { - + if (!Keys.Contains(name)) + _mapStorages.Add(name, new MapWithSetWarmlyShipGeneric(_pictureWidth, _pictureHeight, map)); } /// /// Удаление карты @@ -50,7 +54,8 @@ namespace WarmlyShip /// Название карты public void DelMap(string name) { - // TODO Прописать логику для удаления + if (Keys.Contains(name)) + _mapStorages.Remove(name); } /// /// Доступ к парковке @@ -62,10 +67,10 @@ namespace WarmlyShip { get { - // TODO Продумать логику получения объекта + if (Keys.Contains(ind)) + return _mapStorages[ind]; return null; } } - } } diff --git a/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs b/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs index e03f6fe..9036562 100644 --- a/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs +++ b/WarmlyShip/WarmlyShip/SetWarmlyShipGeneric.cs @@ -39,18 +39,9 @@ namespace WarmlyShip /// public int Insert(T ship) { - // + проверка на _maxCount - - if (ship == null) - { - return -1; - } - for (int i = Count - 1; i > 0; i--) - { - _places[i] = _places[i - 1]; - } - _places[0] = ship; - return 0; + if (Count < _maxCount) + return Insert(ship, 0); + return -1; } /// /// Добавление объекта в набор на конкретную позицию @@ -60,27 +51,12 @@ namespace WarmlyShip /// public int Insert(T ship, int position) { - //кое что убрать (проверка позиции) if (position < 0 || position > Count) { return -1; } - int firstNullElementIndex = position; - while (_places[firstNullElementIndex] != null) - { - if (firstNullElementIndex >= Count) - { - return -1; - } - firstNullElementIndex++; - } - for (int i = firstNullElementIndex; i > position; i--) - { - _places[i] = _places[i - 1]; - } - - _places[position] = ship; - return 0; + _places.Insert(position, ship); + return position; } /// /// Удаление объекта из набора с конкретной позиции @@ -89,14 +65,12 @@ namespace WarmlyShip /// public T Remove(int position) { - // убрать удаление объекта - if (_places[position] == null) - { + if (position < 0 || position >= Count) return null; - } var result = _places[position]; - _places[position] = null; + _places.RemoveAt(position); return result; + } /// /// Получение объекта из набора по позиции @@ -107,13 +81,15 @@ namespace WarmlyShip { get { - // TODO проверка позиции + if (position < 0 || position >= Count) + return null; return _places[position]; } set { - // TODO проверка позиции - // TODO вставка в список по позиции + if (position < 0 || position >= _maxCount) + return; + _places.Add(value); } } ///