From 8a247dcc9a839579b98cc33c24b1149f200b3283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 1 Oct 2022 01:01:21 +0400 Subject: [PATCH 01/16] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BC=D0=B0=D1=81=D1=81=D0=B8=D0=B2=D0=B0=20=D0=BD=D0=B0=20?= =?UTF-8?q?=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/MapWithSetAirplanesGeneric.cs | 8 +-- AirBomber/AirBomber/SetAirplanesGeneric.cs | 60 ++++++++++++------- 2 files changed, 43 insertions(+), 25 deletions(-) diff --git a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs index f1b5c96..26a65ef 100644 --- a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs @@ -90,7 +90,7 @@ namespace AirBomber Shaking(); for (int i = 0; i < _setAirplanes.Count; i++) { - var airplane = _setAirplanes.Get(i); + var airplane = _setAirplanes[i]; if (airplane != null) { return _map.CreateMap(_pictureWidth, _pictureHeight, airplane); @@ -119,11 +119,11 @@ namespace AirBomber int j = _setAirplanes.Count - 1; for (int i = 0; i < _setAirplanes.Count; i++) { - if (_setAirplanes.Get(i) == null) + if (_setAirplanes[i] == null) { for (; j > i; j--) { - var airplane = _setAirplanes.Get(j); + var airplane = _setAirplanes[j]; if (airplane != null) { _setAirplanes.Insert(airplane, i); @@ -175,7 +175,7 @@ namespace AirBomber int maxLeft = (countInLine - 1) * _placeSizeWidth; for (int i = 0; i < _setAirplanes.Count; i++) { - var airplane = _setAirplanes.Get(i); + var airplane = _setAirplanes[i]; airplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth, i / countInLine * _placeSizeHeight + 3, _pictureWidth, _pictureHeight); airplane?.DrawningObject(g); } diff --git a/AirBomber/AirBomber/SetAirplanesGeneric.cs b/AirBomber/AirBomber/SetAirplanesGeneric.cs index 178d798..7acf838 100644 --- a/AirBomber/AirBomber/SetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/SetAirplanesGeneric.cs @@ -14,20 +14,23 @@ namespace AirBomber where T : class { /// - /// Массив объектов, которые храним + /// Список объектов, которые храним /// - private readonly T[] _places; + private readonly List _places; /// /// Количество объектов в массиве /// - public int Count => _places.Length; + public int Count => _places.Count; + + private readonly int _maxcount; /// /// Конструктор /// /// public SetAirplanesGeneric(int count) { - _places = new T[count]; + _maxcount = count; + _places = new List(); } /// /// Добавление объекта в набор @@ -41,7 +44,7 @@ namespace AirBomber private bool isCorrectPosition(int position) { - return 0 <= position && position < Count; + return 0 <= position && position < _maxcount; } /// /// Добавление объекта в набор на конкретную позицию @@ -51,22 +54,11 @@ namespace AirBomber /// public bool Insert(T airplane, int position) { - int positionNullElement = position; - while (Get(positionNullElement) != null) - { - positionNullElement++; - } - // Если изначальная позиция была некорректной или пустых элементов справа не оказалось возвращаем false - if (!isCorrectPosition(positionNullElement)) + if (!isCorrectPosition(position)) { return false; } - while (positionNullElement != position) // Смещение вправо - { - _places[positionNullElement] = _places[positionNullElement - 1]; - positionNullElement--; - } - _places[position] = airplane; + _places.Insert(position, airplane); return true; } /// @@ -78,7 +70,7 @@ namespace AirBomber { if (!isCorrectPosition(position)) return false; - _places[position] = null; + _places.RemoveAt(position); return true; } /// @@ -86,9 +78,35 @@ namespace AirBomber /// /// /// - public T Get(int position) + public T this[int position] { - return isCorrectPosition(position) ? _places[position] : null; + get + { + return isCorrectPosition(position) && position < Count ? _places[position] : null; + } + set + { + Insert(value, position); + } + } + /// + /// Проход по набору до первого пустого + /// + /// + public IEnumerable GetCars() + { + foreach (var car in _places) + { + if (car != null) + { + yield return car; + } + else + { + yield break; + } + } + } } } -- 2.25.1 From 9f549cc1543ebb382901b1fbe825fc41fe33df55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 1 Oct 2022 01:38:55 +0400 Subject: [PATCH 02/16] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BB=D0=BB=D0=B5?= =?UTF-8?q?=D0=BA=D1=86=D0=B8=D1=8F=20=D0=BA=D0=B0=D1=80=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/MapsCollection.cs | 75 +++++++++++++++++++++++++++ 1 file changed, 75 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..f2e3362 --- /dev/null +++ b/AirBomber/AirBomber/MapsCollection.cs @@ -0,0 +1,75 @@ +using AirBomber; +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) + { + _mapStorages.Add(name, new(_pictureWidth, _pictureHeight, map)); + } + /// + /// Удаление карты + /// + /// Название карты + public void DelMap(string name) + { + _mapStorages.Remove(name); + } + /// + /// Доступ к аэродрому + /// + /// + /// + public MapWithSetAirplanesGeneric this[string ind] + { + get + { + _mapStorages.TryGetValue(ind, out var mapWithSetAirplanesGeneric); + return mapWithSetAirplanesGeneric; + } + } + } +} -- 2.25.1 From ad1b421aeef4bcae2fb26aaa9d49e17a45b79c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 1 Oct 2022 01:55:13 +0400 Subject: [PATCH 03/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BD=D0=BE=D0=B2=D0=B0=D1=8F=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D1=80=D0=B0?= =?UTF-8?q?=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D0=BA=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningObject.cs | 2 +- .../FormMapWithSetAirplanes.Designer.cs | 119 +++++++++++++---- .../AirBomber/FormMapWithSetAirplanes.cs | 124 +++++++++++++----- AirBomber/AirBomber/SetAirplanesGeneric.cs | 8 +- 4 files changed, 190 insertions(+), 63 deletions(-) diff --git a/AirBomber/AirBomber/DrawningObject.cs b/AirBomber/AirBomber/DrawningObject.cs index dca9b4d..4ebc751 100644 --- a/AirBomber/AirBomber/DrawningObject.cs +++ b/AirBomber/AirBomber/DrawningObject.cs @@ -29,7 +29,7 @@ namespace AirBomber public void SetObject(int x, int y, int width, int height) { - _airplane.SetPosition(x, y, width, height); + _airplane?.SetPosition(x, y, width, height); } void IDrawningObject.DrawningObject(Graphics g) diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs index 8d581aa..0cdc893 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { this.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.groupBoxMaps = new System.Windows.Forms.GroupBox(); + this.buttonAddMap = new System.Windows.Forms.Button(); + this.buttonDeleteMap = new System.Windows.Forms.Button(); + this.listBoxMaps = new System.Windows.Forms.ListBox(); + this.textBoxNewMapName = new System.Windows.Forms.TextBox(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonRemoveAirplane = new System.Windows.Forms.Button(); this.buttonShowStorage = new System.Windows.Forms.Button(); @@ -38,14 +44,15 @@ this.buttonUp = new System.Windows.Forms.Button(); this.buttonShowOnMap = new System.Windows.Forms.Button(); this.buttonAddAirplane = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.pictureBox = new System.Windows.Forms.PictureBox(); this.groupBoxTools.SuspendLayout(); + this.groupBoxMaps.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); // // groupBoxTools // + this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.buttonRemoveAirplane); this.groupBoxTools.Controls.Add(this.buttonShowStorage); @@ -55,18 +62,79 @@ this.groupBoxTools.Controls.Add(this.buttonUp); this.groupBoxTools.Controls.Add(this.buttonShowOnMap); this.groupBoxTools.Controls.Add(this.buttonAddAirplane); - this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Location = new System.Drawing.Point(811, 0); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(204, 554); + this.groupBoxTools.Size = new System.Drawing.Size(204, 632); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Инструменты"; // + // groupBoxMaps + // + this.groupBoxMaps.Controls.Add(this.buttonAddMap); + this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); + this.groupBoxMaps.Controls.Add(this.listBoxMaps); + this.groupBoxMaps.Controls.Add(this.textBoxNewMapName); + this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); + this.groupBoxMaps.Location = new System.Drawing.Point(6, 22); + this.groupBoxMaps.Name = "groupBoxMaps"; + this.groupBoxMaps.Size = new System.Drawing.Size(192, 248); + this.groupBoxMaps.TabIndex = 0; + this.groupBoxMaps.TabStop = false; + this.groupBoxMaps.Text = "Карты"; + // + // buttonAddMap + // + this.buttonAddMap.Location = new System.Drawing.Point(11, 80); + this.buttonAddMap.Name = "buttonAddMap"; + this.buttonAddMap.Size = new System.Drawing.Size(175, 35); + this.buttonAddMap.TabIndex = 2; + this.buttonAddMap.Text = "Добавить карту"; + this.buttonAddMap.UseVisualStyleBackColor = true; + this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click); + // + // buttonDeleteMap + // + this.buttonDeleteMap.Location = new System.Drawing.Point(11, 206); + this.buttonDeleteMap.Name = "buttonDeleteMap"; + this.buttonDeleteMap.Size = new System.Drawing.Size(175, 35); + this.buttonDeleteMap.TabIndex = 4; + this.buttonDeleteMap.Text = "Удалить карту"; + this.buttonDeleteMap.UseVisualStyleBackColor = true; + this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click); + // + // listBoxMaps + // + this.listBoxMaps.FormattingEnabled = true; + this.listBoxMaps.ItemHeight = 15; + this.listBoxMaps.Location = new System.Drawing.Point(11, 121); + this.listBoxMaps.Name = "listBoxMaps"; + this.listBoxMaps.Size = new System.Drawing.Size(175, 79); + this.listBoxMaps.TabIndex = 3; + this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged); + // + // textBoxNewMapName + // + this.textBoxNewMapName.Location = new System.Drawing.Point(11, 22); + this.textBoxNewMapName.Name = "textBoxNewMapName"; + this.textBoxNewMapName.Size = new System.Drawing.Size(175, 23); + this.textBoxNewMapName.TabIndex = 0; + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(11, 51); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23); + this.comboBoxSelectorMap.TabIndex = 1; + // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 166); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 355); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23); @@ -75,7 +143,7 @@ // // buttonRemoveAirplane // - this.buttonRemoveAirplane.Location = new System.Drawing.Point(17, 195); + this.buttonRemoveAirplane.Location = new System.Drawing.Point(17, 384); this.buttonRemoveAirplane.Name = "buttonRemoveAirplane"; this.buttonRemoveAirplane.Size = new System.Drawing.Size(175, 35); this.buttonRemoveAirplane.TabIndex = 3; @@ -85,7 +153,7 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(17, 287); + this.buttonShowStorage.Location = new System.Drawing.Point(17, 437); this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Size = new System.Drawing.Size(175, 35); this.buttonShowStorage.TabIndex = 4; @@ -98,48 +166,52 @@ 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(91, 504); + this.buttonDown.Location = new System.Drawing.Point(91, 582); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 10; this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.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(127, 504); + this.buttonRight.Location = new System.Drawing.Point(127, 582); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 9; 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.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(55, 504); + this.buttonLeft.Location = new System.Drawing.Point(55, 582); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 8; 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.Stretch; - this.buttonUp.Location = new System.Drawing.Point(91, 468); + this.buttonUp.Location = new System.Drawing.Point(91, 546); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 7; this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(17, 391); + this.buttonShowOnMap.Location = new System.Drawing.Point(17, 487); this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35); this.buttonShowOnMap.TabIndex = 5; @@ -149,7 +221,7 @@ // // buttonAddAirplane // - this.buttonAddAirplane.Location = new System.Drawing.Point(17, 106); + this.buttonAddAirplane.Location = new System.Drawing.Point(17, 314); this.buttonAddAirplane.Name = "buttonAddAirplane"; this.buttonAddAirplane.Size = new System.Drawing.Size(175, 35); this.buttonAddAirplane.TabIndex = 1; @@ -157,24 +229,12 @@ this.buttonAddAirplane.UseVisualStyleBackColor = true; this.buttonAddAirplane.Click += new System.EventHandler(this.ButtonAddAirplane_Click); // - // comboBoxSelectorMap - // - this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxSelectorMap.FormattingEnabled = true; - this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта", "Карта со стенами"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23); - this.comboBoxSelectorMap.TabIndex = 0; - this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); - // // pictureBox // this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Location = new System.Drawing.Point(0, 0); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(811, 554); + this.pictureBox.Size = new System.Drawing.Size(811, 632); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -182,13 +242,15 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1015, 554); + this.ClientSize = new System.Drawing.Size(1015, 632); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); this.Name = "FormMapWithSetAirplanes"; this.Text = "Карта с набором объектов"; this.groupBoxTools.ResumeLayout(false); this.groupBoxTools.PerformLayout(); + this.groupBoxMaps.ResumeLayout(false); + this.groupBoxMaps.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); this.ResumeLayout(false); @@ -208,5 +270,10 @@ private Button buttonShowStorage; private Button buttonRemoveAirplane; private MaskedTextBox maskedTextBoxPosition; + private GroupBox groupBoxMaps; + private Button buttonDeleteMap; + private ListBox listBoxMaps; + private TextBox textBoxNewMapName; + private Button buttonAddMap; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index def5d4e..ee48b85 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -3,41 +3,97 @@ public partial class FormMapWithSetAirplanes : Form { /// - /// Объект от класса карты с набором объектов + /// Словарь для выпадающего списка /// - private MapWithSetAirplanesGeneric _mapAirplanesCollectionGeneric; + private readonly Dictionary _mapsDict = new() + { + { "Простая карта", new SimpleMap() }, + { "Карта со стенами", new WallMap() }, + }; + /// + /// Объект от коллекции карт + /// + private readonly MapsCollection _mapsCollection; /// /// Конструктор /// public FormMapWithSetAirplanes() { InitializeComponent(); + _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.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 ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e) { - AbstractMap map = null; - switch (comboBoxSelectorMap.Text) + pictureBox.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 WallMap(); - break; + return; } - if (map != null) + + if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - _mapAirplanesCollectionGeneric = new MapWithSetAirplanesGeneric( - pictureBox.Width, pictureBox.Height, map); - } - else - { - _mapAirplanesCollectionGeneric = null; + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + ReloadMaps(); } } /// @@ -47,22 +103,22 @@ /// private void ButtonAddAirplane_Click(object sender, EventArgs e) { - if(_mapAirplanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } FormAirBomber form = new(); if (form.ShowDialog() == DialogResult.OK) { - DrawningObject airplane = new(form.SelectedAirplane); - if (form.SelectedAirplane == null || !(_mapAirplanesCollectionGeneric + airplane)) + DrawningObject car = new(form.SelectedAirplane); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + car) { - MessageBox.Show("Не удалось добавить объект"); + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { - MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet(); + MessageBox.Show("Не удалось добавить объект"); } } } @@ -73,6 +129,10 @@ /// private void ButtonRemoveAirplane_Click(object sender, EventArgs e) { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; @@ -82,10 +142,10 @@ return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapAirplanesCollectionGeneric - pos) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -99,11 +159,11 @@ /// private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapAirplanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } /// /// Вывод карты @@ -112,11 +172,11 @@ /// private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (_mapAirplanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapAirplanesCollectionGeneric.ShowOnMap(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } /// /// Перемещение @@ -125,7 +185,7 @@ /// private void ButtonMove_Click(object sender, EventArgs e) { - if (_mapAirplanesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -147,7 +207,7 @@ dir = Direction.Right; break; } - pictureBox.Image = _mapAirplanesCollectionGeneric.MoveObject(dir); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir); } } } \ No newline at end of file diff --git a/AirBomber/AirBomber/SetAirplanesGeneric.cs b/AirBomber/AirBomber/SetAirplanesGeneric.cs index 7acf838..7cc4649 100644 --- a/AirBomber/AirBomber/SetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/SetAirplanesGeneric.cs @@ -93,13 +93,13 @@ namespace AirBomber /// Проход по набору до первого пустого /// /// - public IEnumerable GetCars() + public IEnumerable GetAirplanes() { - foreach (var car in _places) + foreach (var airplane in _places) { - if (car != null) + if (airplane != null) { - yield return car; + yield return airplane; } else { -- 2.25.1 From c5f38eed0752eb8860738220cb7c8c7a85e00da6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 1 Oct 2022 01:59:37 +0400 Subject: [PATCH 04/16] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=BE=D0=BC=D0=BC=D0=B5=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs index 26a65ef..a039593 100644 --- a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs @@ -150,7 +150,6 @@ namespace AirBomber for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++) { DrawHangar(g, pen, new RectangleF(i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth / 1.8F, _placeSizeHeight / 1.6F)); - // g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); } } } -- 2.25.1 From 004ef856b9a3cb43628255970aa71afd5857e9e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 1 Oct 2022 03:41:11 +0400 Subject: [PATCH 05/16] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BC=D0=B0=D1=88=D0=B8=D0=BD=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=81=D0=B0=D0=BC=D0=BE=D0=BB=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/FormMapWithSetAirplanes.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index ee48b85..32d0bd4 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -110,8 +110,8 @@ FormAirBomber form = new(); if (form.ShowDialog() == DialogResult.OK) { - DrawningObject car = new(form.SelectedAirplane); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + car) + DrawningObject airplane = new(form.SelectedAirplane); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airplane) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); -- 2.25.1 From beb02493927669c2e50afb0171ae8a395db5434f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 1 Oct 2022 05:24:33 +0400 Subject: [PATCH 06/16] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningObject.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AirBomber/AirBomber/DrawningObject.cs b/AirBomber/AirBomber/DrawningObject.cs index 4ebc751..5751bfc 100644 --- a/AirBomber/AirBomber/DrawningObject.cs +++ b/AirBomber/AirBomber/DrawningObject.cs @@ -32,7 +32,7 @@ namespace AirBomber _airplane?.SetPosition(x, y, width, height); } - void IDrawningObject.DrawningObject(Graphics g) + public void DrawObject(Graphics g) { _airplane?.DrawTransport(g); } -- 2.25.1 From 20a73a199a24358ad3af467127f4e01db5a07e0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 1 Oct 2022 05:32:04 +0400 Subject: [PATCH 07/16] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= =?UTF-8?q?=20=D1=81=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AbstractMap.cs | 2 +- AirBomber/AirBomber/IDrawningObject.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AirBomber/AirBomber/AbstractMap.cs b/AirBomber/AirBomber/AbstractMap.cs index 78425d8..8cc655f 100644 --- a/AirBomber/AirBomber/AbstractMap.cs +++ b/AirBomber/AirBomber/AbstractMap.cs @@ -162,7 +162,7 @@ namespace AirBomber DrawMap(); if (_staticBitMap != null) gr.DrawImage(_staticBitMap, 0, 0); - _drawningObject.DrawningObject(gr); + _drawningObject.DrawObject(gr); return bmp; } diff --git a/AirBomber/AirBomber/IDrawningObject.cs b/AirBomber/AirBomber/IDrawningObject.cs index 6077012..a2afce7 100644 --- a/AirBomber/AirBomber/IDrawningObject.cs +++ b/AirBomber/AirBomber/IDrawningObject.cs @@ -33,7 +33,7 @@ namespace AirBomber /// Отрисовка объекта /// /// - void DrawningObject(Graphics g); + void DrawObject(Graphics g); /// /// Получение текущей позиции объекта /// -- 2.25.1 From 7e3898123bee6e89d97e4b63292bfcd9e83dcfb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 1 Oct 2022 05:54:28 +0400 Subject: [PATCH 08/16] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs index a039593..444dbfd 100644 --- a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs @@ -176,7 +176,7 @@ namespace AirBomber { var airplane = _setAirplanes[i]; airplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth, i / countInLine * _placeSizeHeight + 3, _pictureWidth, _pictureHeight); - airplane?.DrawningObject(g); + airplane?.DrawObject(g); } } } -- 2.25.1 From eace47e5ed7af03a25a99f3675f0f30ba29c7bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Sat, 1 Oct 2022 06:00:01 +0400 Subject: [PATCH 09/16] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B8=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B8=20=D1=81=D0=B0=D0=BC=D0=BE=D0=BB=D0=B5=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/SetAirplanesGeneric.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AirBomber/AirBomber/SetAirplanesGeneric.cs b/AirBomber/AirBomber/SetAirplanesGeneric.cs index 7cc4649..8577377 100644 --- a/AirBomber/AirBomber/SetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/SetAirplanesGeneric.cs @@ -68,7 +68,7 @@ namespace AirBomber /// public bool Remove(int position) { - if (!isCorrectPosition(position)) + if (!isCorrectPosition(position) || position >= Count) return false; _places.RemoveAt(position); return true; -- 2.25.1 From 056cf6de2ee770dd4e9365afc4e86b0ce0b8c7ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Wed, 5 Oct 2022 02:01:24 +0400 Subject: [PATCH 10/16] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=20=D0=B2=20=D0=BE=D1=82=D1=80=D0=B8=D1=81?= =?UTF-8?q?=D0=BE=D0=B2=D0=BA=D0=B5=20=D1=83=D1=87=D0=B0=D1=81=D1=82=D0=BA?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=BA=D0=B0=D1=80=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/SimpleMap.cs | 4 ++-- AirBomber/AirBomber/WallMap.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AirBomber/AirBomber/SimpleMap.cs b/AirBomber/AirBomber/SimpleMap.cs index 63bb878..f5f9a69 100644 --- a/AirBomber/AirBomber/SimpleMap.cs +++ b/AirBomber/AirBomber/SimpleMap.cs @@ -16,11 +16,11 @@ protected override void DrawBarrierPart(Graphics g, int i, int j) { - g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, _size_x, _size_y); } protected override void DrawRoadPart(Graphics g, int i, int j) { - g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); } protected override void GenerateMap() { diff --git a/AirBomber/AirBomber/WallMap.cs b/AirBomber/AirBomber/WallMap.cs index 8cb7989..59273aa 100644 --- a/AirBomber/AirBomber/WallMap.cs +++ b/AirBomber/AirBomber/WallMap.cs @@ -31,7 +31,7 @@ namespace AirBomber protected override void DrawRoadPart(Graphics g, int i, int j) { - g.FillRectangle(roadColor, i * _size_x, j * _size_y, (i + 1) * _size_x, (j + 1) * _size_y); + g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y); } protected override void GenerateMap() -- 2.25.1 From 69db2652b3322594cbaec3dad9ac614af1aa92b9 Mon Sep 17 00:00:00 2001 From: the Date: Wed, 5 Oct 2022 12:15:46 +0400 Subject: [PATCH 11/16] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/FormMapWithSetAirplanes.cs | 2 +- AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs | 8 ++++---- AirBomber/AirBomber/SetAirplanesGeneric.cs | 13 +++++++------ 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index 32d0bd4..6b4eb6c 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -142,7 +142,7 @@ return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos) + if (_mapAirplanesCollectionGeneric - pos != -1) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); diff --git a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs index 444dbfd..baef1ea 100644 --- a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs @@ -54,8 +54,8 @@ namespace AirBomber /// /// /// - /// - public static bool operator +(MapWithSetAirplanesGeneric map, T airplane) + /// Возвращает позицию вставленого объекта либо -1, если не получилось его добавить + public static int operator +(MapWithSetAirplanesGeneric map, T airplane) { return map._setAirplanes.Insert(airplane); } @@ -64,8 +64,8 @@ namespace AirBomber /// /// /// - /// - public static bool operator -(MapWithSetAirplanesGeneric map, int position) + /// Возвращает удаленный объект, либо null если его не удалось удалить + public static T operator -(MapWithSetAirplanesGeneric map, int position) { return map._setAirplanes.Remove(position); } diff --git a/AirBomber/AirBomber/SetAirplanesGeneric.cs b/AirBomber/AirBomber/SetAirplanesGeneric.cs index 8577377..41ddb96 100644 --- a/AirBomber/AirBomber/SetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/SetAirplanesGeneric.cs @@ -65,13 +65,14 @@ namespace AirBomber /// Удаление объекта из набора с конкретной позиции /// /// - /// - public bool Remove(int position) + /// Возвращает удаленный объект, либо null если его не удалось удалить + public T Remove(int position) { - if (!isCorrectPosition(position) || position >= Count) - return false; - _places.RemoveAt(position); - return true; + if (!isCorrectPosition(position)) + return null; + var result = _places[position]; + _places[position] = null; + return result; } /// /// Получение объекта из набора по позиции -- 2.25.1 From e4026d0b86367728cdea9b4ca16188866de2e67f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Fri, 7 Oct 2022 18:25:04 +0400 Subject: [PATCH 12/16] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=BE=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/SetAirplanesGeneric.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AirBomber/AirBomber/SetAirplanesGeneric.cs b/AirBomber/AirBomber/SetAirplanesGeneric.cs index 41ddb96..097d88f 100644 --- a/AirBomber/AirBomber/SetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/SetAirplanesGeneric.cs @@ -71,7 +71,7 @@ namespace AirBomber if (!isCorrectPosition(position)) return null; var result = _places[position]; - _places[position] = null; + _places.RemoveAt(position); return result; } /// -- 2.25.1 From 56df1b9cb50d3f33141540af94641036490910dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Fri, 7 Oct 2022 18:31:50 +0400 Subject: [PATCH 13/16] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20/=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8E=20=D1=81=D0=B0=D0=BC=D0=BE=D0=BB=D0=B5=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/SetAirplanesGeneric.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AirBomber/AirBomber/SetAirplanesGeneric.cs b/AirBomber/AirBomber/SetAirplanesGeneric.cs index 097d88f..c3a054a 100644 --- a/AirBomber/AirBomber/SetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/SetAirplanesGeneric.cs @@ -36,8 +36,8 @@ namespace AirBomber /// Добавление объекта в набор /// /// Добавляемый самолет - /// - public bool Insert(T airplane) + /// Возвращает позицию вставленного объекта, либо -1 если его не удалось вставить + public int Insert(T airplane) { return Insert(airplane, 0); } @@ -51,15 +51,15 @@ namespace AirBomber /// /// Добавляемый самолет /// Позиция - /// - public bool Insert(T airplane, int position) + /// Возвращает позицию вставленного объекта, либо -1 если его не удалось вставить + public int Insert(T airplane, int position) { if (!isCorrectPosition(position)) { - return false; + return -1; } _places.Insert(position, airplane); - return true; + return position; } /// /// Удаление объекта из набора с конкретной позиции -- 2.25.1 From e31712ac6ae38d5625c4356f9fe0bf23b36d3ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Fri, 7 Oct 2022 18:37:39 +0400 Subject: [PATCH 14/16] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/FormMapWithSetAirplanes.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index 6b4eb6c..e9d9bfd 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -111,7 +111,7 @@ if (form.ShowDialog() == DialogResult.OK) { DrawningObject airplane = new(form.SelectedAirplane); - if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airplane) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airplane != -1) { MessageBox.Show("Объект добавлен"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); @@ -142,7 +142,7 @@ return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapAirplanesCollectionGeneric - pos != -1) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { MessageBox.Show("Объект удален"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); -- 2.25.1 From 7e5c89d03661de4a3bbb8f9fcf1710a7bcbbea54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Fri, 7 Oct 2022 18:44:20 +0400 Subject: [PATCH 15/16] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/FormMapWithSetAirplanes.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs index e9d9bfd..fdf68b6 100644 --- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs +++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs @@ -129,15 +129,8 @@ /// private void ButtonRemoveAirplane_Click(object sender, EventArgs e) { - if (listBoxMaps.SelectedIndex == -1) - { - return; - } - if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) - { - return; - } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text) || + MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } -- 2.25.1 From 2f1f85031640a2c568cbbb1f267adbf83c62ef7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BD=D0=B8=D1=8F=D1=80=20=D0=90=D0=B3=D0=BB?= =?UTF-8?q?=D0=B8=D1=83=D0=BB=D0=BB=D0=BE=D0=B2?= Date: Tue, 4 Oct 2022 03:00:30 +0400 Subject: [PATCH 16/16] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D1=89=D0=B0=D1=82=D1=8C=20=D1=81=D0=B0=D0=BC=D0=BE=D0=BB=D0=B5?= =?UTF-8?q?=D1=82=20=D0=BF=D0=BE=20=D0=BA=D0=B0=D1=80=D1=82=D0=B5,=20?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D1=89=D0=B0=D1=82=D1=8C=20=D0=B2=20=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=BB=D0=B8=D1=89=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AbstractMap.cs | 2 ++ AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/AirBomber/AirBomber/AbstractMap.cs b/AirBomber/AirBomber/AbstractMap.cs index 8cc655f..62dbec5 100644 --- a/AirBomber/AirBomber/AbstractMap.cs +++ b/AirBomber/AirBomber/AbstractMap.cs @@ -34,6 +34,8 @@ namespace AirBomber return DrawMapWithObject(); } + public bool HasMap => _map != null; + /// Проверяет наличие непроходимых участков в заданной области /// Заданная область /// i-ый индекс первого барьера, который был найден в области diff --git a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs index baef1ea..291cff0 100644 --- a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs @@ -34,6 +34,9 @@ namespace AirBomber /// Карта /// private readonly U _map; + + public U Map => _map; + /// /// Конструктор /// @@ -93,7 +96,7 @@ namespace AirBomber var airplane = _setAirplanes[i]; if (airplane != null) { - return _map.CreateMap(_pictureWidth, _pictureHeight, airplane); + return Map.CreateMap(_pictureWidth, _pictureHeight, airplane); } } return new(_pictureWidth, _pictureHeight); @@ -105,9 +108,9 @@ namespace AirBomber /// public Bitmap MoveObject(Direction direction) { - if (_map != null) + if (Map != null) { - return _map.MoveObject(direction); + return Map.MoveObject(direction); } return new(_pictureWidth, _pictureHeight); } -- 2.25.1