From df9b91ad28fda49a20289b308c9c5eac9729c2b1 Mon Sep 17 00:00:00 2001 From: Nikita Potapov <47923521+nikita-potapov@users.noreply.github.com> Date: Fri, 4 Nov 2022 16:01:59 +0400 Subject: [PATCH] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=202.=20=D0=9A=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Boats/Boats/MapsCollection.cs | 83 +++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Boats/Boats/MapsCollection.cs diff --git a/Boats/Boats/MapsCollection.cs b/Boats/Boats/MapsCollection.cs new file mode 100644 index 0000000..dd761e7 --- /dev/null +++ b/Boats/Boats/MapsCollection.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Boats +{ + /// + /// Класс для хранения коллекции карт + /// + internal class MapsCollection + { + /// + /// Словарь (хранилище) с картами + /// + readonly Dictionary> _mapStorages; + /// + /// Возвращение списка названий карт + /// + public List Keys => _mapStorages.Keys.ToList(); + /// + /// Ширина окна отрисовки + /// + private readonly int _pictureWidth; + /// + /// Высота окна отрисовки + /// + private readonly int _pictureHeight; + /// + /// Конструктор + /// + /// + /// + public MapsCollection(int pictureWidth, int pictureHeight) + { + _mapStorages = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + /// + /// Добавление карты + /// + /// Название карты + /// Карта + public void AddMap(string name, AbstractMap map) + { + // Добавление карты + MapWithSetBoatsGeneric newMap = new(_pictureWidth, _pictureHeight, map); + _mapStorages.Add(name, newMap); + } + /// + /// Удаление карты + /// + /// Название карты + public void DelMap(string name) + { + // Удаление карты + if (!_mapStorages.ContainsKey(name)) + { + return; + } + _mapStorages.Remove(name); + } + /// + /// Доступ к гавани + /// + /// + /// + public MapWithSetBoatsGeneric this[string index] + { + get + { + // Получение объекта + if (_mapStorages.ContainsKey(index)) + { + return _mapStorages[index]; + } + return null; + } + } + } +}