Лабораторная работа 4. Третий этап: изменение формы.

This commit is contained in:
Андрей Абазов 2022-10-18 12:50:10 +04:00
parent 3a0b45fdff
commit aa4ca53f3f
2 changed files with 224 additions and 110 deletions

View File

@ -29,23 +29,30 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBoxTools = new System.Windows.Forms.GroupBox(); this.groupBoxTools = new System.Windows.Forms.GroupBox();
this.pictureBox = new System.Windows.Forms.PictureBox(); 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.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonAddAirBomber = new System.Windows.Forms.Button(); this.buttonShowOnMap = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonRemoveAirBomber = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button(); this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveAirBomber = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddAirBomber = new System.Windows.Forms.Button();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout(); this.groupBoxTools.SuspendLayout();
this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBoxTools // groupBoxTools
// //
this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Controls.Add(this.buttonShowOnMap); this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
this.groupBoxTools.Controls.Add(this.buttonRight); this.groupBoxTools.Controls.Add(this.buttonRight);
this.groupBoxTools.Controls.Add(this.buttonDown); this.groupBoxTools.Controls.Add(this.buttonDown);
@ -55,84 +62,99 @@
this.groupBoxTools.Controls.Add(this.buttonRemoveAirBomber); this.groupBoxTools.Controls.Add(this.buttonRemoveAirBomber);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonAddAirBomber); this.groupBoxTools.Controls.Add(this.buttonAddAirBomber);
this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
this.groupBoxTools.Location = new System.Drawing.Point(621, 0); this.groupBoxTools.Location = new System.Drawing.Point(621, 0);
this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(261, 453); this.groupBoxTools.Size = new System.Drawing.Size(261, 671);
this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Инструменты"; this.groupBoxTools.Text = "Инструменты";
// //
// pictureBox // groupBoxMaps
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.groupBoxMaps.Controls.Add(this.buttonAddMap);
this.pictureBox.Location = new System.Drawing.Point(0, 0); this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
this.pictureBox.Name = "pictureBox"; this.groupBoxMaps.Controls.Add(this.listBoxMaps);
this.pictureBox.Size = new System.Drawing.Size(621, 453); this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
this.pictureBox.TabIndex = 1; this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
this.pictureBox.TabStop = false; this.groupBoxMaps.Location = new System.Drawing.Point(18, 34);
this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxMaps.Name = "groupBoxMaps";
this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.groupBoxMaps.Size = new System.Drawing.Size(219, 331);
this.groupBoxMaps.TabIndex = 20;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Карты";
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(13, 107);
this.buttonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(200, 47);
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(13, 275);
this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(200, 47);
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 = 20;
this.listBoxMaps.Location = new System.Drawing.Point(13, 161);
this.listBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(199, 104);
this.listBoxMaps.TabIndex = 3;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(13, 29);
this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(199, 27);
this.textBoxNewMapName.TabIndex = 0;
// //
// comboBoxSelectorMap // comboBoxSelectorMap
// //
this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] { this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Простая карта", "Простая карта"});
"Городская карта", this.comboBoxSelectorMap.Location = new System.Drawing.Point(13, 68);
"Линейная карта"}); this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.comboBoxSelectorMap.Location = new System.Drawing.Point(19, 35);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(218, 28); this.comboBoxSelectorMap.Size = new System.Drawing.Size(199, 28);
this.comboBoxSelectorMap.TabIndex = 10; this.comboBoxSelectorMap.TabIndex = 1;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged);
// //
// buttonAddAirBomber // buttonShowOnMap
// //
this.buttonAddAirBomber.Location = new System.Drawing.Point(19, 109); this.buttonShowOnMap.Location = new System.Drawing.Point(6, 546);
this.buttonAddAirBomber.Name = "buttonAddAirBomber"; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonAddAirBomber.Size = new System.Drawing.Size(218, 41); this.buttonShowOnMap.Size = new System.Drawing.Size(243, 41);
this.buttonAddAirBomber.TabIndex = 11; this.buttonShowOnMap.TabIndex = 19;
this.buttonAddAirBomber.Text = "Добавить бомбардировщик"; this.buttonShowOnMap.Text = "Посмотреть карту";
this.buttonAddAirBomber.UseVisualStyleBackColor = true; this.buttonShowOnMap.UseVisualStyleBackColor = true;
this.buttonAddAirBomber.Click += new System.EventHandler(this.buttonAddAirBomber_Click); this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 188);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(218, 27);
this.maskedTextBoxPosition.TabIndex = 12;
this.maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonRemoveAirBomber
//
this.buttonRemoveAirBomber.Location = new System.Drawing.Point(19, 221);
this.buttonRemoveAirBomber.Name = "buttonRemoveAirBomber";
this.buttonRemoveAirBomber.Size = new System.Drawing.Size(218, 41);
this.buttonRemoveAirBomber.TabIndex = 13;
this.buttonRemoveAirBomber.Text = "Удалить бомбардировщик";
this.buttonRemoveAirBomber.UseVisualStyleBackColor = true;
this.buttonRemoveAirBomber.Click += new System.EventHandler(this.buttonRemoveAirBomber_Click);
//
// buttonShowStorage
//
this.buttonShowStorage.Location = new System.Drawing.Point(19, 281);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(218, 41);
this.buttonShowStorage.TabIndex = 14;
this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click);
// //
// buttonRight // buttonRight
// //
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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.BackgroundImage = global::AirBomber.Properties.Resources.arrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(148, 411); this.buttonRight.Location = new System.Drawing.Point(148, 629);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 18; this.buttonRight.TabIndex = 18;
@ -144,7 +166,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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.BackgroundImage = global::AirBomber.Properties.Resources.arrowDown;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(112, 411); this.buttonDown.Location = new System.Drawing.Point(112, 629);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 17; this.buttonDown.TabIndex = 17;
@ -156,7 +178,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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.BackgroundImage = global::AirBomber.Properties.Resources.arrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(76, 411); this.buttonLeft.Location = new System.Drawing.Point(76, 629);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 16; this.buttonLeft.TabIndex = 16;
@ -168,34 +190,74 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 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.BackgroundImage = global::AirBomber.Properties.Resources.arrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(112, 375); this.buttonUp.Location = new System.Drawing.Point(112, 593);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 15; this.buttonUp.TabIndex = 15;
this.buttonUp.UseVisualStyleBackColor = true; this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
// //
// buttonShowOnMap // buttonShowStorage
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(19, 328); this.buttonShowStorage.Location = new System.Drawing.Point(6, 499);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowOnMap.Size = new System.Drawing.Size(218, 41); this.buttonShowStorage.Size = new System.Drawing.Size(243, 41);
this.buttonShowOnMap.TabIndex = 19; this.buttonShowStorage.TabIndex = 14;
this.buttonShowOnMap.Text = "Посмотреть карту"; this.buttonShowStorage.Text = "Посмотреть хранилище";
this.buttonShowOnMap.UseVisualStyleBackColor = true; this.buttonShowStorage.UseVisualStyleBackColor = true;
this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click); this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click);
//
// buttonRemoveAirBomber
//
this.buttonRemoveAirBomber.Location = new System.Drawing.Point(6, 452);
this.buttonRemoveAirBomber.Name = "buttonRemoveAirBomber";
this.buttonRemoveAirBomber.Size = new System.Drawing.Size(243, 41);
this.buttonRemoveAirBomber.TabIndex = 13;
this.buttonRemoveAirBomber.Text = "Удалить бомбардировщик";
this.buttonRemoveAirBomber.UseVisualStyleBackColor = true;
this.buttonRemoveAirBomber.Click += new System.EventHandler(this.buttonRemoveAirBomber_Click);
//
// maskedTextBoxPosition
//
this.maskedTextBoxPosition.Location = new System.Drawing.Point(31, 419);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(199, 27);
this.maskedTextBoxPosition.TabIndex = 12;
this.maskedTextBoxPosition.ValidatingType = typeof(int);
//
// buttonAddAirBomber
//
this.buttonAddAirBomber.Location = new System.Drawing.Point(6, 372);
this.buttonAddAirBomber.Name = "buttonAddAirBomber";
this.buttonAddAirBomber.Size = new System.Drawing.Size(243, 41);
this.buttonAddAirBomber.TabIndex = 11;
this.buttonAddAirBomber.Text = "Добавить бомбардировщик";
this.buttonAddAirBomber.UseVisualStyleBackColor = true;
this.buttonAddAirBomber.Click += new System.EventHandler(this.buttonAddAirBomber_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(621, 671);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
// //
// FormMapWithSetAirBombers // FormMapWithSetAirBombers
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(882, 453); this.ClientSize = new System.Drawing.Size(882, 671);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetAirBombers"; this.Name = "FormMapWithSetAirBombers";
this.Text = "Карта с набором объектов"; this.Text = "Карта с набором объектов";
this.groupBoxTools.ResumeLayout(false); this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout(); this.groupBoxTools.PerformLayout();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -205,7 +267,6 @@
private GroupBox groupBoxTools; private GroupBox groupBoxTools;
private PictureBox pictureBox; private PictureBox pictureBox;
private ComboBox comboBoxSelectorMap;
private MaskedTextBox maskedTextBoxPosition; private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddAirBomber; private Button buttonAddAirBomber;
private Button buttonShowStorage; private Button buttonShowStorage;
@ -215,5 +276,11 @@
private Button buttonLeft; private Button buttonLeft;
private Button buttonUp; private Button buttonUp;
private Button buttonShowOnMap; private Button buttonShowOnMap;
private GroupBox groupBoxMaps;
private Button buttonAddMap;
private Button buttonDeleteMap;
private ListBox listBoxMaps;
private TextBox textBoxNewMapName;
private ComboBox comboBoxSelectorMap;
} }
} }

View File

@ -14,44 +14,33 @@ namespace AirBomber
public partial class FormMapWithSetAirBombers : Form public partial class FormMapWithSetAirBombers : Form
{ {
/// <summary> /// <summary>
/// Объект от класса карты с набором объектов /// Словарь для выпадающего списка
/// </summary> /// </summary>
private MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap> _mapAirBombersCollectionGeneric; private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{"Городская карта", new CityMap() },
{"Линейная карта", new LineMap() }
};
/// <summary>
/// Объект от коллекции карт
/// </summary>
private readonly MapsCollection _mapsCollection;
public FormMapWithSetAirBombers() public FormMapWithSetAirBombers()
{ {
InitializeComponent(); InitializeComponent();
} _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) foreach (var elem in _mapsDict)
{
AbstractMap map = null;
switch (comboBoxSelectorMap.Text)
{ {
case "Простая карта": comboBoxSelectorMap.Items.Add(elem.Key);
map = new SimpleMap();
break;
case "Городская карта":
map = new CityMap();
break;
case "Линейная карта":
map = new LineMap();
break;
}
if (map != null)
{
_mapAirBombersCollectionGeneric = new MapWithSetAirBombersGeneric<DrawingObjectAirBomber, AbstractMap>(
pictureBox.Width, pictureBox.Height, map);
}
else
{
_mapAirBombersCollectionGeneric = null;
} }
} }
private void buttonAddAirBomber_Click(object sender, EventArgs e) private void buttonAddAirBomber_Click(object sender, EventArgs e)
{ {
if (_mapAirBombersCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -59,10 +48,10 @@ namespace AirBomber
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
DrawingObjectAirBomber airBomber = new(form.SelectedAirBomber); DrawingObjectAirBomber airBomber = new(form.SelectedAirBomber);
if (_mapAirBombersCollectionGeneric + airBomber != -1) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + airBomber != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapAirBombersCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -73,6 +62,10 @@ namespace AirBomber
private void buttonRemoveAirBomber_Click(object sender, EventArgs e) private void buttonRemoveAirBomber_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{ {
return; return;
@ -82,10 +75,10 @@ namespace AirBomber
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapAirBombersCollectionGeneric - pos != null) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapAirBombersCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -95,20 +88,20 @@ namespace AirBomber
private void buttonShowStorage_Click(object sender, EventArgs e) private void buttonShowStorage_Click(object sender, EventArgs e)
{ {
if (_mapAirBombersCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapAirBombersCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
private void buttonShowOnMap_Click(object sender, EventArgs e) private void buttonShowOnMap_Click(object sender, EventArgs e)
{ {
if (_mapAirBombersCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapAirBombersCollectionGeneric.ShowOnMap(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
} }
/// <summary> /// <summary>
@ -136,7 +129,61 @@ namespace AirBomber
dir = Direction.Right; dir = Direction.Right;
break; break;
} }
pictureBox.Image = _mapAirBombersCollectionGeneric?.MoveObject(dir); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
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[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].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(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
ReloadMaps();
}
} }
} }
} }