diff --git a/Airbus/Airbus/MapWithSetPlanesGeneric.cs b/Airbus/Airbus/MapWithSetPlanesGeneric.cs index 28114e5..506f4ef 100644 --- a/Airbus/Airbus/MapWithSetPlanesGeneric.cs +++ b/Airbus/Airbus/MapWithSetPlanesGeneric.cs @@ -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) { diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index 81cfdc7..38c1a98 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -9,21 +9,27 @@ namespace Airbus internal class SetPlanesGeneric where T : class { - //массив объектов, которые храним - private readonly T[] _places; + //список объектов, которые храним + private readonly List _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(); } //добавление объекта в набор 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 GetAirbus() + { + foreach (var plane in _places) + { + if (plane != null) + { + yield return plane; + } + else + { + yield break; + } + } } } }