Этап 1. Смена массива на список.
This commit is contained in:
parent
1e66082200
commit
b091beba51
@ -69,15 +69,10 @@ namespace Airbus
|
||||
{
|
||||
Shaking();
|
||||
|
||||
for(int i = 0; i < _setPlanes.Count; i++)
|
||||
{
|
||||
var plane = _setPlanes.Get(i);
|
||||
|
||||
if(plane != null)
|
||||
foreach(var plane in _setPlanes.GetAirbus())
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
|
||||
}
|
||||
}
|
||||
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
}
|
||||
@ -100,11 +95,11 @@ namespace Airbus
|
||||
|
||||
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)
|
||||
{
|
||||
@ -186,13 +181,20 @@ namespace Airbus
|
||||
public void DrawPlanes(Graphics g)
|
||||
{
|
||||
int position = 0;
|
||||
int index = 0;
|
||||
int currentWidth = 1;
|
||||
int currentHeight = 5;
|
||||
|
||||
for (int i = 0; i < _setPlanes.Count; i++)
|
||||
// for (int i = 0; i < _setPlanes.Count; i++)
|
||||
|
||||
//_setPlanes[index]?.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight);
|
||||
//_setPlanes[index]?.DrawningObject(g);
|
||||
|
||||
foreach (var plane in _setPlanes.GetAirbus())
|
||||
{
|
||||
_setPlanes.Get(i)?.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight);
|
||||
_setPlanes.Get(i)?.DrawningObject(g);
|
||||
plane.SetObject(currentWidth * _placeSizeWidth + 20, currentHeight * _placeSizeHeight + 20, _pictureWidth, _pictureHeight);
|
||||
plane.DrawningObject(g);
|
||||
index++;
|
||||
|
||||
if(position % 2 == 0)
|
||||
{
|
||||
|
@ -9,21 +9,28 @@ namespace Airbus
|
||||
internal class SetPlanesGeneric<T>
|
||||
where T: class
|
||||
{
|
||||
//массив объектов, которые храним
|
||||
private readonly T[] _places;
|
||||
//список объектов, которые храним
|
||||
private readonly List<T> _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<T>();
|
||||
}
|
||||
|
||||
//добавление объекта в набор
|
||||
public int Insert(T plane)
|
||||
{
|
||||
//вставка в начало набора
|
||||
//проверка на максим. кол-во////////////////////////////////////////////////////////////
|
||||
|
||||
return Insert(plane, 0);
|
||||
}
|
||||
|
||||
@ -31,7 +38,7 @@ namespace Airbus
|
||||
public int Insert(T plane, int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
if (position >= _places.Count || position < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -76,7 +83,7 @@ namespace Airbus
|
||||
public T Remove(int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
if (position >= _places.Count || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -89,9 +96,11 @@ namespace Airbus
|
||||
}
|
||||
|
||||
//получение объекта из набора по позиции
|
||||
public T Get(int position)
|
||||
public T this[int position]
|
||||
{
|
||||
if (position >= _places.Length || position < 0)
|
||||
get
|
||||
{
|
||||
if (position >= _places.Count || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -102,5 +111,27 @@ namespace Airbus
|
||||
|
||||
return _places[position];
|
||||
}
|
||||
set
|
||||
{
|
||||
//TODO проверка позиции
|
||||
//TODO вставка в список по позиции
|
||||
}
|
||||
}
|
||||
|
||||
//проход по набору до первого пустого
|
||||
public IEnumerable<T> GetAirbus()
|
||||
{
|
||||
foreach(var plane in _places)
|
||||
{
|
||||
if(plane != null)
|
||||
{
|
||||
yield return plane;
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user