Eliseev E.E. LabWork04 #5

Merged
eegov merged 5 commits from LabWork04 into LabWork03 2022-10-21 08:54:22 +04:00
2 changed files with 60 additions and 27 deletions
Showing only changes of commit b091beba51 - Show all commits

View File

@ -69,14 +69,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);
@ -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)
{

View File

@ -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,18 +96,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;
}
}
}
}
}