Этап 1. Смена массива на список.
This commit is contained in:
parent
a71b990a51
commit
6e87686141
@ -64,14 +64,9 @@ namespace Airbus
|
||||
{
|
||||
Shaking();
|
||||
|
||||
for (int i = 0; i < _setPlanes.Count; i++)
|
||||
foreach (var plane in _setPlanes.GetAirbus())
|
||||
{
|
||||
var plane = _setPlanes.Get(i);
|
||||
|
||||
if (plane != null)
|
||||
{
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
|
||||
}
|
||||
return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
|
||||
}
|
||||
|
||||
return new(_pictureWidth, _pictureHeight);
|
||||
@ -95,11 +90,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,12 +181,14 @@ namespace Airbus
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int position = 0;
|
||||
int index = 0;
|
||||
int currentWidth = 1;
|
||||
int currentHeight = 5;
|
||||
for (int i = 0; i < _setPlanes.Count; i++)
|
||||
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,27 @@ namespace Airbus
|
||||
internal class SetPlanesGeneric<T>
|
||||
where T : class
|
||||
{
|
||||
//массив объектов, которые храним
|
||||
private readonly T[] _places;
|
||||
//список объектов, которые храним
|
||||
private readonly List<T> _places;
|
||||
|
||||
//количество объектов в массиве
|
||||
public int Count => _places.Length;
|
||||
//количество объектов в cписке
|
||||
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 +37,7 @@ namespace Airbus
|
||||
public int Insert(T plane, int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
if (position >= _places.Count || position < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
@ -75,7 +81,7 @@ namespace Airbus
|
||||
public T Remove(int position)
|
||||
{
|
||||
// проверка позиции
|
||||
if (position >= _places.Length || position < 0)
|
||||
if (position >= _places.Count || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@ -88,18 +94,42 @@ namespace Airbus
|
||||
}
|
||||
|
||||
//получение объекта из набора по позиции
|
||||
public T Get(int position)
|
||||
public T this[int position]
|
||||
{
|
||||
if (position >= _places.Length || position < 0)
|
||||
get
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (_places[position] == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (position >= _places.Count || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else if (_places[position] == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _places[position];
|
||||
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