PIbd-21 Belianin N.N. LabWork04 #4

Closed
Belnik wants to merge 5 commits from LabWork04 into LabWork03
4 changed files with 22 additions and 7 deletions
Showing only changes of commit a974a4341e - Show all commits

View File

@ -55,7 +55,6 @@ namespace Tank
Direction.Right => _startPosX + _Width + Tank.Step < _pictureWidth,
Direction.Down => _startPosY + _Height + Tank.Step < _pictureHeight,
_ => false
};
}

View File

@ -9,22 +9,27 @@ namespace Tank
{
internal class SetGeneric<T> 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?>(_maxCount);
}
// Добавление объекта в набор
public bool Insert(T tank)
{
return Insert(tank, 0);
}
// Добавление на конкретную позицию
public bool Insert(T tank, int position)
{
if (position < 0 || position >= _maxCount)
@ -36,6 +41,7 @@ namespace Tank
return true;
}
// Удаление объекта из набора с конкретной позиции
public bool Remove(int position)
{
if (position < 0 || position > _maxCount)
@ -46,6 +52,7 @@ namespace Tank
return true;
}
// Получение объекта из набора по позиции
public T? this[int position]
{
get
@ -62,12 +69,13 @@ namespace Tank
}
}
public IEnumerable<T?> GetTanks(int? maxCars = null)
// Проход по списку
public IEnumerable<T?> GetTanks(int? maxTanks = null)
{
for (int i = 0; i < _places.Count; ++i)
{
yield return _places[i];
if (maxCars.HasValue && i == maxCars.Value)
if (maxTanks.HasValue && i == maxTanks.Value)
{
yield break;
}

View File

@ -99,12 +99,11 @@ namespace Tank.Generics
{
if (tank != null)
{
tank.SetPosition(i % width * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
tank.SetPosition((i % (_pictureWidth / _placeSizeWidth)) * _placeSizeWidth, (i / (_pictureWidth / _placeSizeWidth)) * _placeSizeHeight);
tank.DrawTransport(g);
}
i++;
}
}
}
}
}

View File

@ -11,28 +11,37 @@ namespace Tank
{
internal class TanksGenericStorage
{
// Словарь
readonly Dictionary<string, TanksGenericCollection<DrawArmoVehicle, DrawingObjectTank>> _tankStorages;
// Возвращение списка названий наборов
public List<string> Keys => _tankStorages.Keys.ToList();
private readonly int _pictureWidth;
private readonly int _pictureHeight;
// Конструктор
public TanksGenericStorage(int pictureWidth, int pictureHeight)
{
_tankStorages = new Dictionary<string, TanksGenericCollection<DrawArmoVehicle, DrawingObjectTank>>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
// Добавление набора
public void AddSet(string name)
{
if (_tankStorages.ContainsKey(name)) return;
_tankStorages[name] = new TanksGenericCollection<DrawArmoVehicle, DrawingObjectTank>(_pictureWidth, _pictureHeight);
}
// Удаление набора
public void DelSet(string name)
{
if (!_tankStorages.ContainsKey(name)) return;
_tankStorages.Remove(name);
}
// Доступ к набору
public TanksGenericCollection<DrawArmoVehicle, DrawingObjectTank>?
this[string ind]
{
@ -43,4 +52,4 @@ namespace Tank
}
}
}
}
}