From 4942c6bf615fe52de9afb4d6d5c63e499fc8c9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=80=D1=8C=D1=8F=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Fri, 16 Dec 2022 22:25:19 +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=20MapsCollection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/MapsCollection.cs | 85 +++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 AirBomber/AirBomber/MapsCollection.cs diff --git a/AirBomber/AirBomber/MapsCollection.cs b/AirBomber/AirBomber/MapsCollection.cs new file mode 100644 index 0000000..20b280e --- /dev/null +++ b/AirBomber/AirBomber/MapsCollection.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + /// + /// Класс для хранения коллекции карт + /// + 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) + { + MapWithSetJetsGeneric mapJetsCollectionGeneric; + + // Если карта или её имя не задано - выходим + if (map == null || string.IsNullOrEmpty(name)) return; + + // Если совершается попытка добавить карту с уже существующим именем, то выходим + if (_mapStorages.ContainsKey(name)) return; + mapJetsCollectionGeneric = new MapWithSetJetsGeneric(_pictureWidth, _pictureHeight, map); + _mapStorages.Add(name, mapJetsCollectionGeneric); + + } + /// + /// Удаление карты + /// + /// Название карты + public void DelMap(string name) + { + // Если имя удаляемой карты не задано - выходим + if (string.IsNullOrEmpty(name)) return; + _mapStorages.Remove(name); + } + + /// + /// Доступ к ангару + /// + /// + /// + public MapWithSetJetsGeneric this[string ind] + { + get + { + if (string.IsNullOrEmpty(ind)) return null; + return _mapStorages[ind]; + + } + } + } +}