This commit is contained in:
Kirill 2023-12-07 14:14:15 +04:00
parent b3f332db43
commit e4baa6c1f0

View File

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