Этап 2. Класс MapsCollection
This commit is contained in:
parent
e1b456f4a8
commit
4942c6bf61
85
AirBomber/AirBomber/MapsCollection.cs
Normal file
85
AirBomber/AirBomber/MapsCollection.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AirBomber
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс для хранения коллекции карт
|
||||
/// </summary>
|
||||
internal class MapsCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Словарь (хранилище) с картами
|
||||
/// </summary>
|
||||
readonly Dictionary<string, MapWithSetJetsGeneric<DrawningObjectJet, AbstractMap>> _mapStorages;
|
||||
/// <summary>
|
||||
/// Возвращение списка названий карт
|
||||
/// </summary>
|
||||
public List<string> Keys => _mapStorages.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
private readonly int _pictureHeight;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="pictureWidth"></param>
|
||||
/// <param name="pictureHeight"></param>
|
||||
public MapsCollection(int pictureWidth, int pictureHeight)
|
||||
{
|
||||
_mapStorages = new Dictionary<string, MapWithSetJetsGeneric<DrawningObjectJet, AbstractMap>>();
|
||||
_pictureWidth = pictureWidth;
|
||||
_pictureHeight = pictureHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
/// <param name="map">Карта</param>
|
||||
public void AddMap(string name, AbstractMap map)
|
||||
{
|
||||
MapWithSetJetsGeneric<DrawningObjectJet, AbstractMap> mapJetsCollectionGeneric;
|
||||
|
||||
// Если карта или её имя не задано - выходим
|
||||
if (map == null || string.IsNullOrEmpty(name)) return;
|
||||
|
||||
// Если совершается попытка добавить карту с уже существующим именем, то выходим
|
||||
if (_mapStorages.ContainsKey(name)) return;
|
||||
mapJetsCollectionGeneric = new MapWithSetJetsGeneric<DrawningObjectJet, AbstractMap>(_pictureWidth, _pictureHeight, map);
|
||||
_mapStorages.Add(name, mapJetsCollectionGeneric);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление карты
|
||||
/// </summary>
|
||||
/// <param name="name">Название карты</param>
|
||||
public void DelMap(string name)
|
||||
{
|
||||
// Если имя удаляемой карты не задано - выходим
|
||||
if (string.IsNullOrEmpty(name)) return;
|
||||
_mapStorages.Remove(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Доступ к ангару
|
||||
/// </summary>
|
||||
/// <param name="ind"></param>
|
||||
/// <returns></returns>
|
||||
public MapWithSetJetsGeneric<DrawningObjectJet, AbstractMap> this[string ind]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (string.IsNullOrEmpty(ind)) return null;
|
||||
return _mapStorages[ind];
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user