diff --git a/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs b/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs index 751f7b2..ac5ee7f 100644 --- a/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs +++ b/AccordionBus/AccordionBus/MapWithSetBusesGeneric.cs @@ -60,7 +60,7 @@ namespace AccordionBus /// /// /// - /// + /// Возвращает позицию вставленого объекта либо -1, если не получилось его добавить public static int operator +(MapWithSetBusesGeneric map, T bus) { return map._setBuses.Insert(bus); @@ -70,8 +70,8 @@ namespace AccordionBus /// /// /// - /// - public static int operator -(MapWithSetBusesGeneric map, int position) + /// Возвращает удаленный объект, либо null если его не удалось удалить + public static T operator -(MapWithSetBusesGeneric map, int position) { return map._setBuses.Remove(position); } @@ -94,13 +94,9 @@ namespace AccordionBus public Bitmap ShowOnMap() { Shaking(); - for (int i = 0; i < _setBuses.Count; i++) + foreach (var bus in _setBuses.GetBuses()) { - var bus = _setBuses.Get(i); - if (bus != null) - { - return _map.CreateMap(_pictureWidth, _pictureHeight, bus); - } + return _map.CreateMap(_pictureWidth, _pictureHeight, bus); } return new(_pictureWidth, _pictureHeight); } @@ -125,11 +121,11 @@ namespace AccordionBus int j = _setBuses.Count - 1; for (int i = 0; i < _setBuses.Count; i++) { - if (_setBuses.Get(i) == null) + if (_setBuses[i] == null) { for (; j > i; j--) { - var bus = _setBuses.Get(j); + var bus = _setBuses[j]; if (bus != null) { _setBuses.Insert(bus, i); @@ -172,10 +168,12 @@ namespace AccordionBus int numberOfSeatsInHeight = _pictureHeight / _placeSizeHeight; int rightLine = (numberOfSeatsInWidth - 1) * _placeSizeWidth; int bottomLine = (numberOfSeatsInHeight - 1) * _placeSizeHeight; - for (int i = 0; i < _setBuses.Count; i++) + int count = 0; + foreach (var bus in _setBuses.GetBuses()) { - _setBuses.Get(i)?.SetObject(rightLine - i % numberOfSeatsInWidth * _placeSizeWidth, bottomLine - i / numberOfSeatsInWidth * _placeSizeHeight, _pictureWidth, _pictureHeight); - _setBuses.Get(i)?.DrawningObject(g); + bus.SetObject(rightLine - count % numberOfSeatsInWidth * _placeSizeWidth, bottomLine - count / numberOfSeatsInWidth * _placeSizeHeight, _pictureWidth, _pictureHeight); + bus.DrawningObject(g); + count++; } } }