diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs index e1f05ad..51de520 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs @@ -15,7 +15,7 @@ namespace ProjectElectricLocomotive.Generics private readonly int _pictureWidth; private readonly int _pictureHeight; private readonly int _placeSizeWidth = 200; - private readonly int _placeSizeHeight = 90; + private readonly int _placeSizeHeight = 120; private readonly SetGeneric _collection; public LocomotivesGenericCollection(int picWidth, int picHeight) { diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs index 97e93ff..f29cdff 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericStorage.cs @@ -15,17 +15,17 @@ namespace ProjectElectricLocomotive /// Словарь (хранилище) /// readonly Dictionary> _locomotivesStorage; + + /// /// Возвращение списка названий наборов /// public List Keys => _locomotivesStorage.Keys.ToList(); - /// - /// Ширина окна отрисовки - /// + + private readonly int _pictureWidth; - /// - /// Высота окна отрисовки - /// + private readonly int _pictureHeight; + /// /// Конструктор /// @@ -43,16 +43,25 @@ namespace ProjectElectricLocomotive /// Название набора public void AddSet(string name) { - // TODO Прописать логику для добавления + if (!_locomotivesStorage.ContainsKey(name)) + { + _locomotivesStorage.Add(name, new LocomotivesGenericCollection(_pictureWidth, _pictureHeight)); + } } + /// /// Удаление набора /// /// Название набора public void DelSet(string name) { - // TODO Прописать логику для удаления + if (_locomotivesStorage.ContainsKey(name)) + { + _locomotivesStorage.Remove(name); + } } + + /// /// Доступ к набору /// @@ -63,10 +72,12 @@ namespace ProjectElectricLocomotive { get { - // TODO Продумать логику получения набора + if (_locomotivesStorage.ContainsKey(ind)) + { + return _locomotivesStorage[ind]; + } return null; } } - } } diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs index 7ce9c5b..7b52791 100644 --- a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs +++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs @@ -10,33 +10,40 @@ namespace ProjectElectricLocomotive.Generics where T : class { private readonly List _places; + public int Count => _places.Count; + + /// Максимальное количество объектов в списке private readonly int _maxCount; public SetGeneric(int count) { _maxCount = count; _places = new List(count); } - public int Insert(T locomotive) + + /// Добавление объекта в набор + public int Insert(T loco) { - return Insert(locomotive, 0); + return Insert(loco, 0); } - public int Insert(T locomotive, int position) + + public int Insert(T loco, int position) { if (position < 0 || position >= _maxCount) return -1; - _places.Insert(position, locomotive); + _places.Insert(position, loco); return position; } + public T? Remove(int position) { if (position >= Count || position < 0) - { return null; - } + T? tmp = _places[position]; _places[position] = null; return tmp; } + public T? this[int position] { get @@ -50,17 +57,20 @@ namespace ProjectElectricLocomotive.Generics _places.Insert(position, value); } } - public IEnumerable GetLocomotives(int? maxLocomotives = null) + /// + /// Проход по списку + /// + /// + public IEnumerable GetLocomotives(int? maxLocos = null) { for (int i = 0; i < _places.Count; ++i) { yield return _places[i]; - if (maxLocomotives.HasValue && i == maxLocomotives.Value) + if (maxLocos.HasValue && i == maxLocos.Value) { yield break; } } } } - }