From 66cf50c25a23011ae649665713bbc569c9e41131 Mon Sep 17 00:00:00 2001 From: Danil Kargin Date: Wed, 2 Nov 2022 22:04:03 +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 --- AirFighter/AirFighter/MapsCollection.cs | 83 +++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 AirFighter/AirFighter/MapsCollection.cs diff --git a/AirFighter/AirFighter/MapsCollection.cs b/AirFighter/AirFighter/MapsCollection.cs new file mode 100644 index 0000000..ff24c26 --- /dev/null +++ b/AirFighter/AirFighter/MapsCollection.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirFighter +{ + /// + /// Класс для хранения коллекции карт + /// + 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) + { + if (!string.IsNullOrEmpty(name) && map != null && !Keys.Contains(name)) + { + _mapStorages.Add(name, new MapWithSetAirFightersGeneric(_pictureWidth, _pictureHeight, map)); + } + } + /// + /// Удаление карты + /// + /// Название карты + public void DelMap(string name) + { + if (!string.IsNullOrEmpty(name)) + { + _mapStorages.Remove(name); + } + } + /// + /// Доступ к парковке + /// + /// + /// + public MapWithSetAirFightersGeneric this[string ind] + { + get + { + MapWithSetAirFightersGeneric _map; + if (_mapStorages.TryGetValue(ind, out _map)) + { + return _map; + } + else + return null; + } + } + } +}