diff --git a/AirBomber/AirBomber/MapWithSetAirBombersGeneric.cs b/AirBomber/AirBomber/MapWithSetAirBombersGeneric.cs
index 339a883..383c3c1 100644
--- a/AirBomber/AirBomber/MapWithSetAirBombersGeneric.cs
+++ b/AirBomber/AirBomber/MapWithSetAirBombersGeneric.cs
@@ -88,13 +88,9 @@ namespace AirBomber
public Bitmap ShowOnMap()
{
Shaking();
- for (int i = 0; i < _setAirBombers.Count; i++)
+ foreach (var airBomber in _setAirBombers.GetAirBombers())
{
- var airBomber = _setAirBombers[i];
- if (airBomber != null)
- {
- return _map.CreateMap(_pictureWidth, _pictureHeight, airBomber);
- }
+ return _map.CreateMap(_pictureWidth, _pictureHeight, airBomber);
}
return new(_pictureWidth, _pictureHeight);
}
@@ -163,10 +159,12 @@ namespace AirBomber
private void DrawAirBombers(Graphics g)
{
int numOfObjectsInRow = _pictureWidth / _placeSizeWidth;
- for (int i = 0; i < _setAirBombers.Count; i++)
+ int i = 0;
+ foreach (var airBomber in _setAirBombers.GetAirBombers())
{
- _setAirBombers[i]?.SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight, _pictureWidth, _pictureHeight);
- _setAirBombers[i]?.DrawingObject(g);
+ airBomber.SetObject((numOfObjectsInRow - (i % numOfObjectsInRow) - 1) * _placeSizeWidth, (i / numOfObjectsInRow) * _placeSizeHeight, _pictureWidth, _pictureHeight);
+ airBomber.DrawingObject(g);
+ i++;
}
}
}
diff --git a/AirBomber/AirBomber/MapsCollection.cs b/AirBomber/AirBomber/MapsCollection.cs
new file mode 100644
index 0000000..5911fc4
--- /dev/null
+++ b/AirBomber/AirBomber/MapsCollection.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirBomber
+{
+ internal class MapsCollection
+ {
+ ///
+ /// Словарь (хранилище) с картами
+ ///
+ readonly Dictionary> _mapStorages;
+ ///
+ /// Возвращение списка названий карт
+ ///
+ public List Keys => _mapStorages.Keys.ToList();
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public MapsCollection(int pictureWidth, int pictureHeight)
+ {
+ _mapStorages = new Dictionary>();
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
+ }
+ ///
+ /// Добавление карты
+ ///
+ /// Название карты
+ /// Карта
+ public void AddMap(string name, AbstractMap map)
+ {
+ if (_mapStorages.ContainsKey(name))
+ {
+ MessageBox.Show("Карта с таким названием уже существует!");
+ return;
+ }
+ _mapStorages.Add(name, new MapWithSetAirBombersGeneric(_pictureWidth, _pictureHeight, map));
+ }
+ ///
+ /// Удаление карты
+ ///
+ /// Название карты
+ public void DelMap(string name)
+ {
+ if (_mapStorages.ContainsKey(name))
+ {
+ _mapStorages.Remove(name);
+ }
+ }
+ ///
+ /// Доступ к парковке
+ ///
+ ///
+ ///
+ public MapWithSetAirBombersGeneric this[string ind]
+ {
+ get
+ {
+ if (_mapStorages.ContainsKey(ind)) return _mapStorages[ind];
+ return null;
+ }
+ }
+ }
+}
diff --git a/AirBomber/AirBomber/SetAirBombersGeneric.cs b/AirBomber/AirBomber/SetAirBombersGeneric.cs
index e9a13ff..830335e 100644
--- a/AirBomber/AirBomber/SetAirBombersGeneric.cs
+++ b/AirBomber/AirBomber/SetAirBombersGeneric.cs
@@ -82,5 +82,24 @@ namespace AirBomber
if (position < 0 || position >= _maxCount) Insert(value, position);
}
}
+
+ ///
+ /// Проход по набору до первого пустого
+ ///
+ ///
+ public IEnumerable GetAirBombers()
+ {
+ foreach (var airBomber in _places)
+ {
+ if (airBomber != null)
+ {
+ yield return airBomber;
+ }
+ else
+ {
+ yield break;
+ }
+ }
+ }
}
}