diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs
index 6b7dd53..62b18f1 100644
--- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs
+++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs
@@ -88,16 +88,13 @@ namespace Airbus
public Bitmap ShowOnMap()
{
Shaking();
- for (int i = 0; i < _setPlanes.Count; i++)
+ foreach (var plane in _setPlanes.GetPlanes())
{
- var plane = _setPlanes.Get(i);
- if (plane != null)
- {
- return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
- }
+ return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
}
return new(_pictureWidth, _pictureHeight);
}
+
///
/// Перемещение объекта по крате
///
@@ -119,11 +116,11 @@ namespace Airbus
int j = _setPlanes.Count - 1;
for (int i = 0; i < _setPlanes.Count; i++)
{
- if (_setPlanes.Get(i) == null)
+ if (_setPlanes[i] == null)
{
for (; j > i; j--)
{
- var plane = _setPlanes.Get(j);
+ var plane = _setPlanes[j];
if (plane != null)
{
_setPlanes.Insert(plane, i);
@@ -181,19 +178,13 @@ namespace Airbus
///
private void DrawPlanes(Graphics g)
{
- int width = _pictureWidth / _placeSizeWidth;
- int height = _pictureHeight / _placeSizeHeight;
-
- for (int i = 0; i < _setPlanes.Count; i++)
+ foreach (var plane in _setPlanes.GetPlanes())
{
// TODO установка позиции
- if(_setPlanes.Get(i) != null)
- {
- _setPlanes.Get(i).SetObject((width - i % width - 1) * _placeSizeWidth,(height - i / width - 1) * _placeSizeHeight, _pictureWidth, _pictureHeight);
- _setPlanes.Get(i)?.DrawningObject(g);
- }
+ plane.DrawningObject(g);
}
}
+
}
}
diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs
index a7f7d3d..121aeea 100644
--- a/Airbus/Airbus/SetPlanesGeneric.cs
+++ b/Airbus/Airbus/SetPlanesGeneric.cs
@@ -10,75 +10,46 @@ namespace Airbus
where T : class
{
///
- /// Массив объектов, которые храним
+ /// Список объектов, которые храним
///
- private readonly T[] _places;
+ private readonly List _places;
///
- /// Количество объектов в массиве
+ /// Количество объектов в списке
///
- public int Count => _places.Length;
+ public int Count => _places.Count;
+ private readonly int _maxCount;
///
/// Конструктор
///
///
public SetPlanesGeneric(int count)
{
- _places = new T[count];
+ _maxCount = count;
+ _places = new List();
}
///
/// Добавление объекта в набор
///
- /// Добавляемый самолёт
+ /// Добавляемый автомобиль
///
public int Insert(T plane)
{
// TODO вставка в начало набора
- return Insert(plane, 0);
+ // TODO проверка на _maxCount
+ return -1;
}
-
///
/// Добавление объекта в набор на конкретную позицию
///
- /// Добавляемый самолёт
+ /// Добавляемый автомобиль
/// Позиция
///
public int Insert(T plane, int position)
{
// TODO проверка позиции
- // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
- // проверка, что после вставляемого элемента в массиве есть пустой элемент
- // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
// TODO вставка по позиции
-
- if(_places[position] == null)
- {
- _places[position] = plane;
- return position;
- }
- else
- {
- int pos = -1;
- bool isFree = false;
- for (int i = 0; i < Count; i++)
- {
- if (_places[i] == null)
- {
- isFree = true;
- pos = i;
- break;
- }
- }
- if (isFree)
- {
- for (var i = pos; i > position; --i) _places[i] = _places[i - 1];
- _places[position] = plane;
- return position;
- }
- else
- {
- return -1;
- }
- }
+ _places[position] = plane;
+ return -1;
}
///
/// Удаление объекта из набора с конкретной позиции
@@ -99,15 +70,36 @@ namespace Airbus
///
///
///
- public T Get(int position)
+ public T this[int position]
{
- // TODO проверка позиции
- if (position < 0 || position >= Count)
+ get
{
- return null;
+ // TODO проверка позиции
+ return _places[position];
+ }
+ set
+ {
+ // TODO проверка позиции
+ // TODO вставка в список по позиции
+ }
+ }
+ ///
+ /// Проход по набору до первого пустого
+ ///
+ ///
+ public IEnumerable GetPlanes()
+ {
+ foreach (var plane in _places)
+ {
+ if (plane != null)
+ {
+ yield return plane;
+ }
+ else
+ {
+ yield break;
+ }
}
- return _places[position];
}
}
-
}