ISEbd-22. Baygulov A.A. Lab work 04 #5
@ -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<T> _collection;
|
||||
public LocomotivesGenericCollection(int picWidth, int picHeight)
|
||||
{
|
||||
|
@ -15,17 +15,17 @@ namespace ProjectElectricLocomotive
|
||||
/// Словарь (хранилище)
|
||||
/// </summary>
|
||||
readonly Dictionary<string, LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>> _locomotivesStorage;
|
||||
|
||||
/// <summary>
|
||||
/// Возвращение списка названий наборов
|
||||
/// </summary>
|
||||
public List<string> Keys => _locomotivesStorage.Keys.ToList();
|
||||
/// <summary>
|
||||
/// Ширина окна отрисовки
|
||||
/// </summary>
|
||||
|
||||
|
||||
private readonly int _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна отрисовки
|
||||
/// </summary>
|
||||
|
||||
private readonly int _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
@ -43,16 +43,25 @@ namespace ProjectElectricLocomotive
|
||||
/// <param name="name">Название набора</param>
|
||||
public void AddSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для добавления
|
||||
if (!_locomotivesStorage.ContainsKey(name))
|
||||
{
|
||||
_locomotivesStorage.Add(name, new LocomotivesGenericCollection<DrawingLocomotive, DrawingObjectLocomotive>(_pictureWidth, _pictureHeight));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление набора
|
||||
/// </summary>
|
||||
/// <param name="name">Название набора</param>
|
||||
public void DelSet(string name)
|
||||
{
|
||||
// TODO Прописать логику для удаления
|
||||
if (_locomotivesStorage.ContainsKey(name))
|
||||
{
|
||||
_locomotivesStorage.Remove(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Доступ к набору
|
||||
/// </summary>
|
||||
@ -63,10 +72,12 @@ namespace ProjectElectricLocomotive
|
||||
{
|
||||
get
|
||||
{
|
||||
// TODO Продумать логику получения набора
|
||||
if (_locomotivesStorage.ContainsKey(ind))
|
||||
{
|
||||
return _locomotivesStorage[ind];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -10,33 +10,40 @@ namespace ProjectElectricLocomotive.Generics
|
||||
where T : class
|
||||
{
|
||||
private readonly List<T?> _places;
|
||||
|
||||
public int Count => _places.Count;
|
||||
|
||||
/// Максимальное количество объектов в списке
|
||||
private readonly int _maxCount;
|
||||
public SetGeneric(int count)
|
||||
{
|
||||
_maxCount = count;
|
||||
_places = new List<T?>(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<T?> GetLocomotives(int? maxLocomotives = null)
|
||||
/// <summary>
|
||||
/// Проход по списку
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<T?> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user