From 3a0b45fdffc32afaff656d039a031e6548a20d46 Mon Sep 17 00:00:00 2001 From: Andrey_Abazov Date: Tue, 18 Oct 2022 12:13:43 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=204.=20=D0=92=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20=D1=8D?= =?UTF-8?q?=D1=82=D0=B0=D0=BF:=20=D0=BA=D0=BE=D0=BB=D0=BB=D0=B5=D0=BA?= =?UTF-8?q?=D1=86=D0=B8=D1=8F=20=D0=BA=D0=B0=D1=80=D1=82=20+=20=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D0=BE=D0=B3=D0=BE=20=D1=8D=D1=82=D0=B0=D0=BF?= =?UTF-8?q?=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/MapWithSetAirBombersGeneric.cs | 16 ++-- AirBomber/AirBomber/MapsCollection.cs | 77 +++++++++++++++++++ AirBomber/AirBomber/SetAirBombersGeneric.cs | 19 +++++ 3 files changed, 103 insertions(+), 9 deletions(-) create mode 100644 AirBomber/AirBomber/MapsCollection.cs 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; + } + } + } } }