diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs
index a62de35..065664e 100644
--- a/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs
+++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.Designer.cs
@@ -30,6 +30,12 @@
{
this.comboTypeEngines = new System.Windows.Forms.ComboBox();
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();
@@ -47,11 +53,11 @@
this.btnGenerateAirplane = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
- this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout();
+ this.groupBoxMaps.SuspendLayout();
this.groupBoxGenerate.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownEngines)).BeginInit();
@@ -74,6 +80,7 @@
//
// 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);
@@ -82,20 +89,82 @@
this.groupBoxTools.Controls.Add(this.groupBoxGenerate);
this.groupBoxTools.Controls.Add(this.buttonDown);
this.groupBoxTools.Controls.Add(this.buttonRight);
- this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxTools.Controls.Add(this.buttonLeft);
this.groupBoxTools.Controls.Add(this.buttonUp);
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, 594);
+ this.groupBoxTools.Size = new System.Drawing.Size(204, 779);
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, 267);
+ this.groupBoxMaps.Name = "groupBoxMaps";
+ this.groupBoxMaps.Size = new System.Drawing.Size(192, 248);
+ this.groupBoxMaps.TabIndex = 26;
+ 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 = 0;
+ //
// maskedTextBoxPosition
//
- this.maskedTextBoxPosition.Location = new System.Drawing.Point(23, 317);
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 565);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
@@ -104,9 +173,9 @@
//
// buttonRemoveAirplane
//
- this.buttonRemoveAirplane.Location = new System.Drawing.Point(23, 346);
+ this.buttonRemoveAirplane.Location = new System.Drawing.Point(17, 594);
this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
- this.buttonRemoveAirplane.Size = new System.Drawing.Size(175, 35);
+ this.buttonRemoveAirplane.Size = new System.Drawing.Size(175, 26);
this.buttonRemoveAirplane.TabIndex = 23;
this.buttonRemoveAirplane.Text = "Удалить самолет";
this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
@@ -114,9 +183,9 @@
//
// buttonShowStorage
//
- this.buttonShowStorage.Location = new System.Drawing.Point(23, 387);
+ this.buttonShowStorage.Location = new System.Drawing.Point(17, 626);
this.buttonShowStorage.Name = "buttonShowStorage";
- this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
+ this.buttonShowStorage.Size = new System.Drawing.Size(175, 26);
this.buttonShowStorage.TabIndex = 24;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
@@ -124,7 +193,7 @@
//
// buttonShowOnMap
//
- this.buttonShowOnMap.Location = new System.Drawing.Point(23, 424);
+ this.buttonShowOnMap.Location = new System.Drawing.Point(17, 658);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
this.buttonShowOnMap.TabIndex = 25;
@@ -134,7 +203,7 @@
//
// buttonAddAirplane
//
- this.buttonAddAirplane.Location = new System.Drawing.Point(23, 273);
+ this.buttonAddAirplane.Location = new System.Drawing.Point(17, 521);
this.buttonAddAirplane.Name = "buttonAddAirplane";
this.buttonAddAirplane.Size = new System.Drawing.Size(175, 35);
this.buttonAddAirplane.TabIndex = 21;
@@ -244,78 +313,71 @@
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, 544);
+ this.buttonDown.Location = new System.Drawing.Point(91, 737);
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, 544);
+ this.buttonRight.Location = new System.Drawing.Point(127, 737);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 9;
this.buttonRight.UseVisualStyleBackColor = true;
- //
- // 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(23, 465);
- 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);
+ 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, 544);
+ this.buttonLeft.Location = new System.Drawing.Point(55, 737);
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, 508);
+ this.buttonUp.Location = new System.Drawing.Point(91, 701);
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);
//
// 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, 594);
+ this.pictureBox.Size = new System.Drawing.Size(811, 779);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
- // FormGeneratorAirplane
+ // FormMapWithSetAirplanes
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1015, 594);
+ this.ClientSize = new System.Drawing.Size(1015, 779);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
- this.Name = "FormGeneratorAirplane";
+ this.Name = "FormMapWithSetAirplanes";
this.Text = "Генератор самолетов";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
+ this.groupBoxMaps.ResumeLayout(false);
+ this.groupBoxMaps.PerformLayout();
this.groupBoxGenerate.ResumeLayout(false);
this.groupBoxGenerate.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericSpeed)).EndInit();
@@ -351,5 +413,10 @@
private Button buttonShowStorage;
private Button buttonShowOnMap;
private Button buttonAddAirplane;
+ private GroupBox groupBoxMaps;
+ private Button buttonAddMap;
+ private Button buttonDeleteMap;
+ private ListBox listBoxMaps;
+ private TextBox textBoxNewMapName;
}
}
\ No newline at end of file
diff --git a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs
index 3082e34..b407c40 100644
--- a/AirBomber/AirBomber/FormMapWithSetAirplanes.cs
+++ b/AirBomber/AirBomber/FormMapWithSetAirplanes.cs
@@ -5,17 +5,102 @@ namespace AirBomber
public partial class FormMapWithSetAirplanes : Form
{
///
- /// Объект от класса карты с набором объектов
+ /// Словарь для выпадающего списка
///
- private MapWithSetAirplanesGeneric _mapAirplanesCollectionGeneric;
+ private readonly Dictionary _mapsDict = new()
+ {
+ { "Простая карта", new SimpleMap() },
+ { "Карта со стенами", new WallMap() },
+ };
+ ///
+ /// Объект от коллекции карт
+ ///
+ private readonly MapsCollection _mapsCollection;
private GeneratorAirplane _generatorAirplane;
///
/// Конструктор
///
public FormMapWithSetAirplanes()
{
- _generatorAirplane = new(100, 100);
InitializeComponent();
+ _generatorAirplane = new(100, 100);
+ _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
+ comboBoxSelectorMap.Items.Clear();
+ foreach (var elem in _mapsDict)
+ {
+ comboBoxSelectorMap.Items.Add(elem.Key);
+ }
+ }
+
+ private string NameMap => listBoxMaps.SelectedItem?.ToString() ?? string.Empty;
+ ///
+ /// Заполнение 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 ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ pictureBox.Image = _mapsCollection[NameMap].ShowSet();
+ }
+ ///
+ /// Удаление карты
+ ///
+ ///
+ ///
+ private void ButtonDeleteMap_Click(object sender, EventArgs e)
+ {
+ if (listBoxMaps.SelectedIndex == -1)
+ {
+ return;
+ }
+
+ if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ _mapsCollection.DelMap(NameMap);
+ ReloadMaps();
+ }
}
///
/// Добавление самолета на карту
@@ -23,41 +108,15 @@ namespace AirBomber
/// самолет.
private void AddAirplaneInMap(DrawningObject airplane)
{
- if (airplane == null || !(_mapAirplanesCollectionGeneric + airplane))
+ if (airplane == null ||
+ !(_mapsCollection[NameMap] + airplane))
{
MessageBox.Show("Не удалось добавить объект");
}
else
{
MessageBox.Show("Объект добавлен");
- pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
- }
- }
- ///
- /// Выбор карты
- ///
- ///
- ///
- private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
- {
- AbstractMap map = null;
- switch (comboBoxSelectorMap.Text)
- {
- case "Простая карта":
- map = new SimpleMap();
- break;
- case "Карта со стенами":
- map = new WallMap();
- break;
- }
- if (map != null)
- {
- _mapAirplanesCollectionGeneric = new MapWithSetAirplanesGeneric(
- pictureBox.Width, pictureBox.Height, map);
- }
- else
- {
- _mapAirplanesCollectionGeneric = null;
+ pictureBox.Image = _mapsCollection[NameMap].ShowSet();
}
}
///
@@ -85,7 +144,7 @@ namespace AirBomber
dir = Direction.Right;
break;
}
- pictureBox.Image = _mapAirplanesCollectionGeneric?.MoveObject(dir) ?? pictureBox.Image;
+ pictureBox.Image = _mapsCollection[NameMap].MoveObject(dir);
}
///
/// Добавления типа двигателя и его количество в генератор
@@ -116,7 +175,7 @@ namespace AirBomber
///
private void btnGenerateAirplane_Click(object sender, EventArgs e)
{
- if (_mapAirplanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -160,7 +219,7 @@ namespace AirBomber
///
private void ButtonAddAirplane_Click(object sender, EventArgs e)
{
- if (_mapAirplanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -177,7 +236,7 @@ namespace AirBomber
///
private void ButtonRemoveAirplane_Click(object sender, EventArgs e)
{
- if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
+ if (listBoxMaps.SelectedIndex == -1 || string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
}
@@ -186,10 +245,10 @@ namespace AirBomber
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_mapAirplanesCollectionGeneric - pos)
+ if (_mapsCollection[NameMap] - pos)
{
MessageBox.Show("Объект удален");
- pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
+ pictureBox.Image = _mapsCollection[NameMap].ShowSet();
}
else
{
@@ -203,11 +262,11 @@ namespace AirBomber
///
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
- if (_mapAirplanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
- pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
+ pictureBox.Image = _mapsCollection[NameMap].ShowSet();
}
///
/// Вывод карты
@@ -216,11 +275,11 @@ namespace AirBomber
///
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
- if (_mapAirplanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
- pictureBox.Image = _mapAirplanesCollectionGeneric.ShowOnMap();
+ pictureBox.Image = _mapsCollection[NameMap].ShowOnMap();
}
}
}
\ No newline at end of file