PIbd-21_Putintsev_D.M._Road.../RoadTrain/RoadTrainGenericStorage.cs

81 lines
2.7 KiB
C#
Raw Permalink Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RoadTrain.DrawningObjects;
using RoadTrain.MovementStrategy;
namespace RoadTrain.Generics
{
/// <summary>
/// Класс для хранения коллекции
/// </summary>
internal class RoadTrainGenericStorage
{
/// <summary>
/// Словарь (хранилище)
/// </summary>
readonly Dictionary<string, RoadTrainGenericCollection<DrawningRoadTrain,
DrawningObjectTrain>> _trainStorages;
/// <summary>
/// Возвращение списка названий наборов
/// </summary>
public List<string> Keys => _trainStorages.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 RoadTrainGenericStorage(int pictureWidth, int pictureHeight)
{
_trainStorages = new Dictionary<string,
RoadTrainGenericCollection<DrawningRoadTrain, DrawningObjectTrain>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
/// <summary>
/// Добавление набора
/// </summary>
/// <param name="name">Название набора</param>
public void AddSet(string name)
{
if (_trainStorages.ContainsKey(name)) return;
_trainStorages[name] = new RoadTrainGenericCollection<DrawningRoadTrain, DrawningObjectTrain>(_pictureWidth, _pictureHeight);
}
/// <summary>
/// Удаление набора
/// </summary>
/// <param name="name">Название набора</param>
public void DelSet(string name)
{
if (_trainStorages.ContainsKey(name)) _trainStorages.Remove(name);
return;
}
/// <summary>
/// Доступ к набору
/// </summary>
/// <param name="ind"></param>
/// <returns></returns>
public RoadTrainGenericCollection<DrawningRoadTrain, DrawningObjectTrain>?
this[string ind]
{
get
{
if (_trainStorages.ContainsKey(ind)) return _trainStorages[ind];
return null;
}
}
}
}