diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 9b3ea1f..deb007c 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -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) { diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 9c9a974..f6a01be 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -9,21 +9,28 @@ namespace Airbus internal class SetPlanesGeneric 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) { + //вставка в начало набора + //проверка на максим. кол-во//////////////////////////////////////////////////////////// + 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 GetAirbus() + { + foreach(var plane in _places) + { + if(plane != null) + { + yield return plane; + } + else + { + yield break; + } + } } } }