From e1b456f4a8d54ec0ea4c4d520ed3701f3d11b88d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=80=D1=8C=D1=8F=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Fri, 16 Dec 2022 22:21:59 +0400 Subject: [PATCH 1/3] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=201.=20=D0=A1?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B0=20=D0=BC=D0=B0=D1=81=D1=81=D0=B8=D0=B2?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/MapWithSetJetsGeneric.cs | 18 ++-- AirBomber/AirBomber/SetJetGeneric.cs | 87 +++++++++++++------- 2 files changed, 64 insertions(+), 41 deletions(-) diff --git a/AirBomber/AirBomber/MapWithSetJetsGeneric.cs b/AirBomber/AirBomber/MapWithSetJetsGeneric.cs index 05be60f..ee86681 100644 --- a/AirBomber/AirBomber/MapWithSetJetsGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetJetsGeneric.cs @@ -94,13 +94,9 @@ namespace AirBomber public Bitmap ShowOnMap() { Shaking(); - for (int i = 0; i < _setJets.Count; i++) + foreach (var car in _setJets.GetJets()) { - var car = _setJets.Get(i); - if (car != null) - { - return _map.CreateMap(_pictureWidth, _pictureHeight, car); - } + return _map.CreateMap(_pictureWidth, _pictureHeight, car); } return new(_pictureWidth, _pictureHeight); } @@ -125,11 +121,11 @@ namespace AirBomber int j = _setJets.Count - 1; for (int i = 0; i < _setJets.Count; i++) { - if (_setJets.Get(i) == null) + if (_setJets[i] == null) { for (; j > i; j--) { - var car = _setJets.Get(j); + var car = _setJets[j]; if (car != null) { _setJets.Insert(car, i); @@ -189,9 +185,9 @@ namespace AirBomber { // установка позиции //_setJets.Get(i)?.SetObject(ccol * _placeSizeWidth, crow * _placeSizeHeight, _pictureWidth, _pictureHeight); - _setJets.Get(i)?.SetObject(rows - i % cols * _placeSizeWidth, i / cols * _placeSizeHeight + 3, _pictureWidth, _pictureHeight); - _setJets.Get(i)?.DrawningObject(g); - // (сначала передвигаемся влево) + _setJets[i]?.SetObject(rows - i % cols * _placeSizeWidth, i / cols * _placeSizeHeight + 3, _pictureWidth, _pictureHeight); + _setJets[i]?.DrawningObject(g); + //(сначала передвигаемся влево) ccol++; if (ccol >= cols) { diff --git a/AirBomber/AirBomber/SetJetGeneric.cs b/AirBomber/AirBomber/SetJetGeneric.cs index 4abaf03..a3edbba 100644 --- a/AirBomber/AirBomber/SetJetGeneric.cs +++ b/AirBomber/AirBomber/SetJetGeneric.cs @@ -9,23 +9,26 @@ namespace AirBomber internal class SetJetGeneric where T : class { /// - /// Массив объектов, которые храним (самолетов) + /// Список объектов, которые храним (самолетов) /// - private readonly T[] _places; + private readonly List _places; /// - /// Количество объектов в массиве + /// Количество объектов в списке /// - public int Count => _places.Length; - private int JetPlaces = 0; - + public int Count => _places.Count; + /// + /// Ограничение максимального количества самолетов в списке + /// + private readonly int _maxCount; /// /// Конструктор /// /// Количество самолетов public SetJetGeneric(int count) { - _places = new T[count]; + _maxCount = count; + _places = new List(); } /// @@ -34,29 +37,20 @@ namespace AirBomber /// Добавляемый самолет /// Позиция /// - public int Insert(T jet) - { - return Insert(jet, 0); - } + //public int Insert(T jet) + //{ + // return Insert(jet, 0); + //} public int Insert(T jet, int position = 0) { - if (position < 0 || position >= _places.Length || JetPlaces == _places.Length) + if (position < 0 || position >= _maxCount || _maxCount <= _places.Count) { return -1; } - JetPlaces++; - while (_places[position] != null) - { - for (int i = _places.Length - 1; i > 0; --i) - { - if (_places[i] == null && _places[i - 1] != null) - { - _places[i] = _places[i - 1]; - _places[i - 1] = null; - } - } - } - _places[position] = jet; + _places.Insert(position, jet); + + _places.Remove(null); + return position; } /// @@ -66,9 +60,13 @@ namespace AirBomber /// public T Remove(int position) { - if (position < 0 || position >= _places.Length) return null; + if (position < 0 || position >= _maxCount) return null; + T savedJet = _places[position]; + _places[position] = null; + + return savedJet; } @@ -77,11 +75,40 @@ namespace AirBomber /// /// Позиция получаемого самолета /// - public T Get(int position) + public T this[int position] { - // проверка позиции - if (position < 0 || position >= _places.Length) return null; - return _places[position]; + get + { + // проверка позиции + if (position < 0 || position >= _maxCount) return null; + return _places[position]; + } + set + { + // проверка позиции + if (position < 0 || position >= _maxCount) + { + _places[position] = value; + } + } + } + /// + /// Проход по набору до первого пустого + /// + /// + public IEnumerable GetJets() + { + foreach (var jet in _places) + { + if (jet != null) + { + yield return jet; + } + else + { + yield break; + } + } } } } -- 2.25.1 From 4942c6bf615fe52de9afb4d6d5c63e499fc8c9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=80=D1=8C=D1=8F=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Fri, 16 Dec 2022 22:25:19 +0400 Subject: [PATCH 2/3] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=202.=20=D0=9A?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=20MapsCollection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/MapsCollection.cs | 85 +++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 AirBomber/AirBomber/MapsCollection.cs diff --git a/AirBomber/AirBomber/MapsCollection.cs b/AirBomber/AirBomber/MapsCollection.cs new file mode 100644 index 0000000..20b280e --- /dev/null +++ b/AirBomber/AirBomber/MapsCollection.cs @@ -0,0 +1,85 @@ +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) + { + MapWithSetJetsGeneric mapJetsCollectionGeneric; + + // Если карта или её имя не задано - выходим + if (map == null || string.IsNullOrEmpty(name)) return; + + // Если совершается попытка добавить карту с уже существующим именем, то выходим + if (_mapStorages.ContainsKey(name)) return; + mapJetsCollectionGeneric = new MapWithSetJetsGeneric(_pictureWidth, _pictureHeight, map); + _mapStorages.Add(name, mapJetsCollectionGeneric); + + } + /// + /// Удаление карты + /// + /// Название карты + public void DelMap(string name) + { + // Если имя удаляемой карты не задано - выходим + if (string.IsNullOrEmpty(name)) return; + _mapStorages.Remove(name); + } + + /// + /// Доступ к ангару + /// + /// + /// + public MapWithSetJetsGeneric this[string ind] + { + get + { + if (string.IsNullOrEmpty(ind)) return null; + return _mapStorages[ind]; + + } + } + } +} -- 2.25.1 From d9b0e7a3ce8ad6e1869d8b7ea9dabcfeb6f14718 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=80=D1=8C=D1=8F=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Fri, 16 Dec 2022 22:59:45 +0400 Subject: [PATCH 3/3] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=203.=20=D0=A4?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/FormMapWithSetJets.Designer.cs | 345 ++++++++++++------ AirBomber/AirBomber/FormMapWithSetJets.cs | 126 +++++-- 2 files changed, 335 insertions(+), 136 deletions(-) diff --git a/AirBomber/AirBomber/FormMapWithSetJets.Designer.cs b/AirBomber/AirBomber/FormMapWithSetJets.Designer.cs index 8f59397..216095e 100644 --- a/AirBomber/AirBomber/FormMapWithSetJets.Designer.cs +++ b/AirBomber/AirBomber/FormMapWithSetJets.Designer.cs @@ -28,170 +28,288 @@ /// private void InitializeComponent() { + this.buttonDown1 = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.groupBox2 = new System.Windows.Forms.GroupBox(); + this.buttonAddMap = new System.Windows.Forms.Button(); + this.listBoxMaps = new System.Windows.Forms.ListBox(); + this.ButtonDeleteMap = new System.Windows.Forms.Button(); + this.textBoxNewMapName = new System.Windows.Forms.TextBox(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.buttonRight = new System.Windows.Forms.Button(); + this.buttonLeft = new System.Windows.Forms.Button(); + this.buttonUp = new System.Windows.Forms.Button(); + this.buttonDown = new System.Windows.Forms.Button(); + this.buttonRight1 = new System.Windows.Forms.Button(); + this.buttonLeft1 = new System.Windows.Forms.Button(); + this.buttonUp1 = new System.Windows.Forms.Button(); this.ButtonShowOnMap = new System.Windows.Forms.Button(); this.ButtonShowStorage = new System.Windows.Forms.Button(); - this.ButtonRemoveJet = new System.Windows.Forms.Button(); this.maskedTextBoxPosition = new System.Windows.Forms.TextBox(); this.ButtonAddJet = new System.Windows.Forms.Button(); - this.comboBoxCelectorMap1 = new System.Windows.Forms.ComboBox(); - this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonRight = new System.Windows.Forms.Button(); - this.buttonDown = new System.Windows.Forms.Button(); - this.buttonUp = new System.Windows.Forms.Button(); + this.ButtonRemoveJet = new System.Windows.Forms.Button(); this.pictureBoxJet = new System.Windows.Forms.PictureBox(); this.groupBox1.SuspendLayout(); + this.groupBox2.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxJet)).BeginInit(); this.SuspendLayout(); // + // buttonDown1 + // + this.buttonDown1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown1.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown; + this.buttonDown1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonDown1.Location = new System.Drawing.Point(68, 899); + this.buttonDown1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDown1.Name = "buttonDown1"; + this.buttonDown1.Size = new System.Drawing.Size(35, 30); + this.buttonDown1.TabIndex = 7; + this.buttonDown1.UseVisualStyleBackColor = true; + // // groupBox1 // + this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Right))); + this.groupBox1.Controls.Add(this.groupBox2); + this.groupBox1.Controls.Add(this.buttonRight); + this.groupBox1.Controls.Add(this.buttonLeft); + this.groupBox1.Controls.Add(this.buttonUp); + this.groupBox1.Controls.Add(this.buttonDown); + this.groupBox1.Controls.Add(this.buttonRight1); + this.groupBox1.Controls.Add(this.buttonLeft1); + this.groupBox1.Controls.Add(this.buttonUp1); + this.groupBox1.Controls.Add(this.buttonDown1); this.groupBox1.Controls.Add(this.ButtonShowOnMap); this.groupBox1.Controls.Add(this.ButtonShowStorage); - this.groupBox1.Controls.Add(this.ButtonRemoveJet); this.groupBox1.Controls.Add(this.maskedTextBoxPosition); this.groupBox1.Controls.Add(this.ButtonAddJet); - this.groupBox1.Controls.Add(this.comboBoxCelectorMap1); - this.groupBox1.Controls.Add(this.buttonLeft); - this.groupBox1.Controls.Add(this.buttonRight); - this.groupBox1.Controls.Add(this.buttonDown); - this.groupBox1.Controls.Add(this.buttonUp); - this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBox1.Location = new System.Drawing.Point(680, 0); + this.groupBox1.Controls.Add(this.ButtonRemoveJet); + this.groupBox1.Location = new System.Drawing.Point(893, 12); this.groupBox1.Name = "groupBox1"; - this.groupBox1.Size = new System.Drawing.Size(200, 524); - this.groupBox1.TabIndex = 0; + this.groupBox1.Size = new System.Drawing.Size(191, 561); + this.groupBox1.TabIndex = 7; this.groupBox1.TabStop = false; this.groupBox1.Text = "Инструменты"; // + // groupBox2 + // + this.groupBox2.Controls.Add(this.buttonAddMap); + this.groupBox2.Controls.Add(this.listBoxMaps); + this.groupBox2.Controls.Add(this.ButtonDeleteMap); + this.groupBox2.Controls.Add(this.textBoxNewMapName); + this.groupBox2.Controls.Add(this.comboBoxSelectorMap); + this.groupBox2.Location = new System.Drawing.Point(12, 22); + this.groupBox2.Name = "groupBox2"; + this.groupBox2.Size = new System.Drawing.Size(173, 235); + this.groupBox2.TabIndex = 15; + this.groupBox2.TabStop = false; + this.groupBox2.Text = "Карты"; + // + // buttonAddMap + // + this.buttonAddMap.Location = new System.Drawing.Point(6, 85); + this.buttonAddMap.Name = "buttonAddMap"; + this.buttonAddMap.Size = new System.Drawing.Size(161, 23); + this.buttonAddMap.TabIndex = 9; + this.buttonAddMap.Text = "Добавить карту"; + this.buttonAddMap.UseVisualStyleBackColor = true; + this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click); + // + // listBoxMaps + // + this.listBoxMaps.FormattingEnabled = true; + this.listBoxMaps.ItemHeight = 15; + this.listBoxMaps.Location = new System.Drawing.Point(6, 115); + this.listBoxMaps.Name = "listBoxMaps"; + this.listBoxMaps.Size = new System.Drawing.Size(161, 79); + this.listBoxMaps.TabIndex = 8; + this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged); + // + // ButtonDeleteMap + // + this.ButtonDeleteMap.Location = new System.Drawing.Point(6, 200); + this.ButtonDeleteMap.Name = "ButtonDeleteMap"; + this.ButtonDeleteMap.Size = new System.Drawing.Size(161, 23); + this.ButtonDeleteMap.TabIndex = 7; + this.ButtonDeleteMap.Text = "Удалить карту"; + this.ButtonDeleteMap.UseVisualStyleBackColor = true; + this.ButtonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click); + // + // textBoxNewMapName + // + this.textBoxNewMapName.Location = new System.Drawing.Point(6, 51); + this.textBoxNewMapName.Name = "textBoxNewMapName"; + this.textBoxNewMapName.Size = new System.Drawing.Size(161, 23); + this.textBoxNewMapName.TabIndex = 6; + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(161, 23); + this.comboBoxSelectorMap.TabIndex = 5; + // + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonRight.Location = new System.Drawing.Point(116, 509); + this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(35, 30); + this.buttonRight.TabIndex = 14; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonLeft.Location = new System.Drawing.Point(34, 509); + this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(35, 30); + this.buttonLeft.TabIndex = 13; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonUp.Location = new System.Drawing.Point(75, 475); + this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(35, 30); + this.buttonUp.TabIndex = 12; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonDown.Location = new System.Drawing.Point(75, 509); + this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(35, 30); + this.buttonDown.TabIndex = 11; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); + // + // buttonRight1 + // + this.buttonRight1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight1.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight; + this.buttonRight1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonRight1.Location = new System.Drawing.Point(109, 899); + this.buttonRight1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonRight1.Name = "buttonRight1"; + this.buttonRight1.Size = new System.Drawing.Size(35, 30); + this.buttonRight1.TabIndex = 10; + this.buttonRight1.UseVisualStyleBackColor = true; + // + // buttonLeft1 + // + this.buttonLeft1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft1.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft; + this.buttonLeft1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonLeft1.Location = new System.Drawing.Point(27, 899); + this.buttonLeft1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonLeft1.Name = "buttonLeft1"; + this.buttonLeft1.Size = new System.Drawing.Size(35, 30); + this.buttonLeft1.TabIndex = 9; + this.buttonLeft1.UseVisualStyleBackColor = true; + // + // buttonUp1 + // + this.buttonUp1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp1.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp; + this.buttonUp1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonUp1.Location = new System.Drawing.Point(68, 865); + this.buttonUp1.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); + this.buttonUp1.Name = "buttonUp1"; + this.buttonUp1.Size = new System.Drawing.Size(35, 30); + this.buttonUp1.TabIndex = 8; + this.buttonUp1.UseVisualStyleBackColor = true; + // // ButtonShowOnMap // - this.ButtonShowOnMap.Location = new System.Drawing.Point(6, 276); + this.ButtonShowOnMap.Location = new System.Drawing.Point(17, 418); this.ButtonShowOnMap.Name = "ButtonShowOnMap"; - this.ButtonShowOnMap.Size = new System.Drawing.Size(182, 23); - this.ButtonShowOnMap.TabIndex = 15; + this.ButtonShowOnMap.Size = new System.Drawing.Size(161, 23); + this.ButtonShowOnMap.TabIndex = 6; this.ButtonShowOnMap.Text = "Посмотреть карту"; this.ButtonShowOnMap.UseVisualStyleBackColor = true; this.ButtonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click); // // ButtonShowStorage // - this.ButtonShowStorage.Location = new System.Drawing.Point(6, 223); + this.ButtonShowStorage.Location = new System.Drawing.Point(17, 380); this.ButtonShowStorage.Name = "ButtonShowStorage"; - this.ButtonShowStorage.Size = new System.Drawing.Size(182, 23); - this.ButtonShowStorage.TabIndex = 14; + this.ButtonShowStorage.Size = new System.Drawing.Size(161, 23); + this.ButtonShowStorage.TabIndex = 3; this.ButtonShowStorage.Text = "Посмотреть хранилище"; this.ButtonShowStorage.UseVisualStyleBackColor = true; this.ButtonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click); // - // ButtonRemoveJet - // - this.ButtonRemoveJet.Location = new System.Drawing.Point(6, 144); - this.ButtonRemoveJet.Name = "ButtonRemoveJet"; - this.ButtonRemoveJet.Size = new System.Drawing.Size(182, 23); - this.ButtonRemoveJet.TabIndex = 13; - this.ButtonRemoveJet.Text = "Удалить самолет"; - this.ButtonRemoveJet.UseVisualStyleBackColor = true; - this.ButtonRemoveJet.Click += new System.EventHandler(this.ButtonRemoveJet_Click); - // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 115); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 301); this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - this.maskedTextBoxPosition.Size = new System.Drawing.Size(182, 23); - this.maskedTextBoxPosition.TabIndex = 12; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(161, 23); + this.maskedTextBoxPosition.TabIndex = 4; // // ButtonAddJet // - this.ButtonAddJet.Location = new System.Drawing.Point(6, 68); + this.ButtonAddJet.Location = new System.Drawing.Point(17, 263); this.ButtonAddJet.Name = "ButtonAddJet"; - this.ButtonAddJet.Size = new System.Drawing.Size(182, 23); - this.ButtonAddJet.TabIndex = 11; + this.ButtonAddJet.Size = new System.Drawing.Size(161, 23); + this.ButtonAddJet.TabIndex = 0; this.ButtonAddJet.Text = "Добавить самолет"; this.ButtonAddJet.UseVisualStyleBackColor = true; this.ButtonAddJet.Click += new System.EventHandler(this.ButtonAddJet_Click); // - // comboBoxCelectorMap1 + // ButtonRemoveJet // - this.comboBoxCelectorMap1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxCelectorMap1.FormattingEnabled = true; - this.comboBoxCelectorMap1.Items.AddRange(new object[] { - "Простоя карта", - "Небо"}); - this.comboBoxCelectorMap1.Location = new System.Drawing.Point(6, 22); - this.comboBoxCelectorMap1.Name = "comboBoxCelectorMap1"; - this.comboBoxCelectorMap1.Size = new System.Drawing.Size(182, 23); - this.comboBoxCelectorMap1.TabIndex = 10; - this.comboBoxCelectorMap1.SelectedIndexChanged += new System.EventHandler(this.comboBoxCelectorMap1_SelectedIndexChanged); - // - // buttonLeft - // - this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeft.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(51, 467); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(35, 30); - this.buttonLeft.TabIndex = 9; - this.buttonLeft.UseVisualStyleBackColor = true; - this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonRight - // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(133, 467); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(35, 30); - this.buttonRight.TabIndex = 8; - this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonDown - // - this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDown.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(92, 467); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(35, 30); - this.buttonDown.TabIndex = 7; - this.buttonDown.UseVisualStyleBackColor = true; - this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); - // - // buttonUp - // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(92, 431); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(35, 30); - this.buttonUp.TabIndex = 4; - this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); + this.ButtonRemoveJet.Location = new System.Drawing.Point(17, 339); + this.ButtonRemoveJet.Name = "ButtonRemoveJet"; + this.ButtonRemoveJet.Size = new System.Drawing.Size(161, 23); + this.ButtonRemoveJet.TabIndex = 1; + this.ButtonRemoveJet.Text = "Удалить самолет"; + this.ButtonRemoveJet.UseVisualStyleBackColor = true; + this.ButtonRemoveJet.Click += new System.EventHandler(this.ButtonRemoveJet_Click); // // pictureBoxJet // - this.pictureBoxJet.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxJet.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); this.pictureBoxJet.Location = new System.Drawing.Point(0, 0); this.pictureBoxJet.Name = "pictureBoxJet"; - this.pictureBoxJet.Size = new System.Drawing.Size(680, 524); - this.pictureBoxJet.TabIndex = 1; + this.pictureBoxJet.Size = new System.Drawing.Size(887, 573); + this.pictureBoxJet.TabIndex = 6; this.pictureBoxJet.TabStop = false; // // FormMapWithSetJets // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(880, 524); - this.Controls.Add(this.pictureBoxJet); + this.ClientSize = new System.Drawing.Size(1096, 573); this.Controls.Add(this.groupBox1); + this.Controls.Add(this.pictureBoxJet); this.Name = "FormMapWithSetJets"; this.Text = "Карта с набором объектов"; this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); + this.groupBox2.ResumeLayout(false); + this.groupBox2.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxJet)).EndInit(); this.ResumeLayout(false); @@ -199,17 +317,26 @@ #endregion + private Button buttonDown1; private GroupBox groupBox1; - private PictureBox pictureBoxJet; - private Button buttonUp; - private Button buttonDown; - private Button buttonRight; - private Button buttonLeft; + private Button buttonRight1; + private Button buttonLeft1; + private Button buttonUp1; private Button ButtonShowOnMap; + private ComboBox comboBoxSelectorMap; private Button ButtonShowStorage; - private Button ButtonRemoveJet; private TextBox maskedTextBoxPosition; private Button ButtonAddJet; - private ComboBox comboBoxCelectorMap1; + private Button ButtonRemoveJet; + private PictureBox pictureBoxJet; + private Button buttonRight; + private Button buttonLeft; + private Button buttonUp; + private Button buttonDown; + private GroupBox groupBox2; + private Button buttonAddMap; + private ListBox listBoxMaps; + private Button ButtonDeleteMap; + private TextBox textBoxNewMapName; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormMapWithSetJets.cs b/AirBomber/AirBomber/FormMapWithSetJets.cs index d6d27ce..2cee580 100644 --- a/AirBomber/AirBomber/FormMapWithSetJets.cs +++ b/AirBomber/AirBomber/FormMapWithSetJets.cs @@ -13,41 +13,102 @@ namespace AirBomber { public partial class FormMapWithSetJets : Form { + /// + /// Словарь для выпадающего списка + /// + private readonly Dictionary _mapsDict = new() + { + { "Простая карта", new SimpleMap() }, + { "Небо", new SkyMap() } + }; + /// + /// Объект от коллекции карт + /// + private readonly MapsCollection _mapsCollection; + /// /// Объект от класса карты с набором объектов /// private MapWithSetJetsGeneric _mapJetsCollectionGeneric; + + /// /// Конструктор /// public FormMapWithSetJets() { InitializeComponent(); + _mapsCollection = new MapsCollection(pictureBoxJet.Width, pictureBoxJet.Height); + comboBoxSelectorMap.Items.Clear(); + foreach (var elem in _mapsDict) + { + comboBoxSelectorMap.Items.Add(elem.Key); + } + } + /// + /// Заполнение listBoxMaps + /// + private void ReloadMaps() + { + int index = listBoxMaps.SelectedIndex; + listBoxMaps.Items.Clear(); + for (int i = 0; i < _mapsCollection.Keys.Count; i++) + { + listBoxMaps.Items.Add(_mapsCollection.Keys[i]); + } + if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count)) + { + listBoxMaps.SelectedIndex = 0; + } + else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count) + { + listBoxMaps.SelectedIndex = index; + } + } + /// + /// Добавление карты + /// + /// + /// + private void ButtonAddMap_Click(object sender, EventArgs e) + { + if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) + { + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text)) + { + MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); + ReloadMaps(); } /// /// Выбор карты /// /// /// - private void comboBoxCelectorMap1_SelectedIndexChanged(object sender, EventArgs e) + private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) { - AbstractMap map = null; - switch (comboBoxCelectorMap1.Text) + pictureBoxJet.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + /// + /// Удаление карты + /// + /// + /// + private void ButtonDeleteMap_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) { - case "Простая карта": - map = new SimpleMap(); - break; - case "Небо": - map = new SkyMap(); - break; + return; } - if (map != null) + if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - _mapJetsCollectionGeneric = new MapWithSetJetsGeneric(pictureBoxJet.Width, pictureBoxJet.Height, map); - } - else - { - _mapJetsCollectionGeneric = null; + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + ReloadMaps(); } } /// @@ -57,7 +118,7 @@ namespace AirBomber /// private void ButtonAddJet_Click(object sender, EventArgs e) { - if (_mapJetsCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -69,11 +130,11 @@ namespace AirBomber MessageBox.Show("Сначала создайте объект"); return; } - DrawningObjectJet bus = new(form.SelectedJet); - if (_mapJetsCollectionGeneric + bus != -1) + DrawningObjectJet jet = new(form.SelectedJet); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + jet != -1) { MessageBox.Show("Объект добавлен"); - pictureBoxJet.Image = _mapJetsCollectionGeneric.ShowSet(); + pictureBoxJet.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -88,6 +149,12 @@ namespace AirBomber /// private void ButtonRemoveJet_Click(object sender, EventArgs e) { + + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; @@ -97,10 +164,10 @@ namespace AirBomber return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapJetsCollectionGeneric - pos != null) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { MessageBox.Show("Объект удален"); - pictureBoxJet.Image = _mapJetsCollectionGeneric.ShowSet(); + pictureBoxJet.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -114,11 +181,11 @@ namespace AirBomber /// private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapJetsCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBoxJet.Image = _mapJetsCollectionGeneric.ShowSet(); + pictureBoxJet.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } /// /// Вывод карты @@ -127,15 +194,20 @@ namespace AirBomber /// private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (_mapJetsCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBoxJet.Image = _mapJetsCollectionGeneric.ShowOnMap(); + pictureBoxJet.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } + /// + /// Перемещение + /// + /// + /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_mapJetsCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -157,7 +229,7 @@ namespace AirBomber dir = Direction.Right; break; } - pictureBoxJet.Image = _mapJetsCollectionGeneric.MoveObject(dir); + pictureBoxJet.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir); } } } -- 2.25.1