diff --git a/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.Designer.cs b/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.Designer.cs
index e8d1b4d..443e6a7 100644
--- a/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.Designer.cs
+++ b/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.Designer.cs
@@ -30,82 +30,152 @@
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
- this.buttonLeft = new System.Windows.Forms.Button();
- this.buttonDown = new System.Windows.Forms.Button();
- this.buttonUp = new System.Windows.Forms.Button();
- this.buttonRight = new System.Windows.Forms.Button();
+ this.groupBoxMaps = new System.Windows.Forms.GroupBox();
+ this.listBoxMaps = new System.Windows.Forms.ListBox();
+ this.buttonDeleteMap = new System.Windows.Forms.Button();
+ this.buttonAddMap = new System.Windows.Forms.Button();
+ this.textBoxNewMapName = new System.Windows.Forms.TextBox();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ this.button1 = new System.Windows.Forms.Button();
+ this.button4 = new System.Windows.Forms.Button();
+ this.button3 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveAircraftCarrier = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddAircraftCarrier = new System.Windows.Forms.Button();
- this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBox1.SuspendLayout();
+ this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
- this.groupBox1.Controls.Add(this.buttonLeft);
- this.groupBox1.Controls.Add(this.buttonDown);
- this.groupBox1.Controls.Add(this.buttonUp);
- this.groupBox1.Controls.Add(this.buttonRight);
+ this.groupBox1.Controls.Add(this.groupBoxMaps);
+ this.groupBox1.Controls.Add(this.button1);
+ this.groupBox1.Controls.Add(this.button4);
+ this.groupBox1.Controls.Add(this.button3);
+ this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.buttonShowOnMap);
this.groupBox1.Controls.Add(this.buttonShowStorage);
this.groupBox1.Controls.Add(this.buttonRemoveAircraftCarrier);
this.groupBox1.Controls.Add(this.maskedTextBoxPosition);
this.groupBox1.Controls.Add(this.buttonAddAircraftCarrier);
- this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Right;
- this.groupBox1.Location = new System.Drawing.Point(550, 0);
+ this.groupBox1.Location = new System.Drawing.Point(593, 0);
this.groupBox1.Name = "groupBox1";
- this.groupBox1.Size = new System.Drawing.Size(250, 450);
+ this.groupBox1.Size = new System.Drawing.Size(250, 519);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Инструменты";
//
- // buttonLeft
+ // groupBoxMaps
//
- //this.buttonLeft.BackgroundImage = global::AircraftCarrier.Properties.Resources.Left;
- this.buttonLeft.Location = new System.Drawing.Point(61, 402);
- this.buttonLeft.Name = "buttonLeft";
- this.buttonLeft.Size = new System.Drawing.Size(30, 30);
- this.buttonLeft.TabIndex = 11;
- this.buttonLeft.UseVisualStyleBackColor = true;
- this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ this.groupBoxMaps.Controls.Add(this.listBoxMaps);
+ this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
+ this.groupBoxMaps.Controls.Add(this.buttonAddMap);
+ this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
+ this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
+ this.groupBoxMaps.Location = new System.Drawing.Point(6, 29);
+ this.groupBoxMaps.Name = "groupBoxMaps";
+ this.groupBoxMaps.Size = new System.Drawing.Size(232, 239);
+ this.groupBoxMaps.TabIndex = 12;
+ this.groupBoxMaps.TabStop = false;
+ this.groupBoxMaps.Text = "Карты";
+ //this.groupBoxMaps.Enter += new System.EventHandler(this.groupBoxMaps_Enter);
//
- // buttonDown
+ // listBoxMaps
//
- //this.buttonDown.BackgroundImage = global::AircraftCarrier.Properties.Resources.Down;
- this.buttonDown.Location = new System.Drawing.Point(97, 402);
- 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);
+ this.listBoxMaps.FormattingEnabled = true;
+ this.listBoxMaps.ItemHeight = 20;
+ this.listBoxMaps.Location = new System.Drawing.Point(19, 137);
+ this.listBoxMaps.Name = "listBoxMaps";
+ this.listBoxMaps.Size = new System.Drawing.Size(184, 64);
+ this.listBoxMaps.TabIndex = 3;
+ this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
//
- // buttonUp
+ // buttonDeleteMap
//
- this.buttonUp.Location = new System.Drawing.Point(97, 366);
- this.buttonUp.Name = "buttonUp";
- this.buttonUp.Size = new System.Drawing.Size(30, 30);
- this.buttonUp.TabIndex = 9;
- this.buttonUp.UseVisualStyleBackColor = true;
- this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
+ this.buttonDeleteMap.Location = new System.Drawing.Point(19, 208);
+ this.buttonDeleteMap.Name = "buttonDeleteMap";
+ this.buttonDeleteMap.Size = new System.Drawing.Size(184, 29);
+ this.buttonDeleteMap.TabIndex = 2;
+ this.buttonDeleteMap.Text = "Удалить карту";
+ this.buttonDeleteMap.UseVisualStyleBackColor = true;
+ this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
//
- // buttonRight
+ // buttonAddMap
//
- this.buttonRight.Location = new System.Drawing.Point(133, 402);
- this.buttonRight.Name = "buttonRight";
- this.buttonRight.Size = new System.Drawing.Size(30, 30);
- this.buttonRight.TabIndex = 8;
- this.buttonRight.UseVisualStyleBackColor = true;
- this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ this.buttonAddMap.Location = new System.Drawing.Point(19, 102);
+ this.buttonAddMap.Name = "buttonAddMap";
+ this.buttonAddMap.Size = new System.Drawing.Size(184, 29);
+ this.buttonAddMap.TabIndex = 1;
+ this.buttonAddMap.Text = "Добавить карту";
+ this.buttonAddMap.UseVisualStyleBackColor = true;
+ this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
+ //
+ // textBoxNewMapName
+ //
+ this.textBoxNewMapName.Location = new System.Drawing.Point(19, 26);
+ this.textBoxNewMapName.Name = "textBoxNewMapName";
+ this.textBoxNewMapName.Size = new System.Drawing.Size(184, 27);
+ 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(19, 68);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(184, 28);
+ this.comboBoxSelectorMap.TabIndex = 0;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
+ this.comboBoxSelectorMap.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(71, 483);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(30, 30);
+ this.button1.TabIndex = 11;
+ this.button1.UseVisualStyleBackColor = true;
+ this.button1.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // button4
+ //
+ this.button4.Location = new System.Drawing.Point(107, 483);
+ this.button4.Name = "button4";
+ this.button4.Size = new System.Drawing.Size(30, 30);
+ this.button4.TabIndex = 10;
+ this.button4.UseVisualStyleBackColor = true;
+ this.button4.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // button3
+ //
+ this.button3.Location = new System.Drawing.Point(107, 447);
+ this.button3.Name = "button3";
+ this.button3.Size = new System.Drawing.Size(30, 30);
+ this.button3.TabIndex = 9;
+ this.button3.UseVisualStyleBackColor = true;
+ this.button3.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // button2
+ //
+ this.button2.Location = new System.Drawing.Point(143, 483);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(30, 30);
+ this.button2.TabIndex = 8;
+ this.button2.UseVisualStyleBackColor = true;
+ this.button2.Click += new System.EventHandler(this.ButtonMove_Click);
//
// buttonShowOnMap
//
- this.buttonShowOnMap.Location = new System.Drawing.Point(25, 321);
+ this.buttonShowOnMap.Location = new System.Drawing.Point(25, 412);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(184, 29);
this.buttonShowOnMap.TabIndex = 6;
@@ -115,7 +185,7 @@
//
// buttonShowStorage
//
- this.buttonShowStorage.Location = new System.Drawing.Point(25, 280);
+ this.buttonShowStorage.Location = new System.Drawing.Point(25, 377);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(184, 29);
this.buttonShowStorage.TabIndex = 5;
@@ -125,7 +195,7 @@
//
// buttonRemoveAircraftCarrier
//
- this.buttonRemoveAircraftCarrier.Location = new System.Drawing.Point(25, 230);
+ this.buttonRemoveAircraftCarrier.Location = new System.Drawing.Point(25, 342);
this.buttonRemoveAircraftCarrier.Name = "buttonRemoveAircraftCarrier";
this.buttonRemoveAircraftCarrier.Size = new System.Drawing.Size(184, 29);
this.buttonRemoveAircraftCarrier.TabIndex = 4;
@@ -135,7 +205,7 @@
//
// maskedTextBoxPosition
//
- this.maskedTextBoxPosition.Location = new System.Drawing.Point(25, 168);
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(25, 309);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(184, 27);
@@ -143,7 +213,7 @@
//
// buttonAddAircraftCarrier
//
- this.buttonAddAircraftCarrier.Location = new System.Drawing.Point(25, 110);
+ this.buttonAddAircraftCarrier.Location = new System.Drawing.Point(25, 274);
this.buttonAddAircraftCarrier.Name = "buttonAddAircraftCarrier";
this.buttonAddAircraftCarrier.Size = new System.Drawing.Size(184, 29);
this.buttonAddAircraftCarrier.TabIndex = 2;
@@ -151,25 +221,12 @@
this.buttonAddAircraftCarrier.UseVisualStyleBackColor = true;
this.buttonAddAircraftCarrier.Click += new System.EventHandler(this.ButtonAddAircraftCarrier_Click);
//
- // comboBoxSelectorMap
- //
- this.comboBoxSelectorMap.FormattingEnabled = true;
- this.comboBoxSelectorMap.Items.AddRange(new object[] {
- "Простая карта",
- "Сложная карта"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(25, 61);
- this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(184, 28);
- this.comboBoxSelectorMap.TabIndex = 0;
- this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
- this.comboBoxSelectorMap.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(550, 450);
+ this.pictureBox.Size = new System.Drawing.Size(593, 519);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//this.pictureBox.Click += new System.EventHandler(this.pictureBox1_Click);
@@ -178,13 +235,15 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
+ this.ClientSize = new System.Drawing.Size(843, 519);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox1);
this.Name = "FormMapWithSetAircraftCarriers";
this.Text = "Карта с набором объектов";
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
+ this.groupBoxMaps.ResumeLayout(false);
+ this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
@@ -193,10 +252,10 @@
#endregion
private GroupBox groupBox1;
- private Button buttonLeft;
- private Button buttonDown;
- private Button buttonUp;
- private Button buttonRight;
+ private Button button1;
+ private Button button4;
+ private Button button3;
+ private Button button2;
private Button buttonShowOnMap;
private Button buttonShowStorage;
private Button buttonRemoveAircraftCarrier;
@@ -204,5 +263,10 @@
private Button buttonAddAircraftCarrier;
private ComboBox comboBoxSelectorMap;
private PictureBox pictureBox;
+ private GroupBox groupBoxMaps;
+ private ListBox listBoxMaps;
+ private Button buttonDeleteMap;
+ private Button buttonAddMap;
+ private TextBox textBoxNewMapName;
}
}
\ No newline at end of file
diff --git a/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs b/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs
index 37d36e2..f0c5486 100644
--- a/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs
+++ b/AircraftCarrier/AircraftCarrier/FormMapWithSetAircraftCarriers.cs
@@ -18,9 +18,79 @@ _mapAircraftCarriersCollectionGeneric;
///
/// Конструктор
///
+ private readonly Dictionary _mapsDict = new()
+ {
+ { "Простая карта", new SimpleMap() },
+ { "Сложная карта", new ComplexMap() }
+ };
+ private readonly MapsCollection _mapsCollection;
public FormMapWithSetAircraftCarriers()
{
InitializeComponent();
+ _mapsCollection = new MapsCollection(pictureBox.Width,
+pictureBox.Height);
+ comboBoxSelectorMap.Items.Clear();
+ foreach (var elem in _mapsDict)
+ {
+ comboBoxSelectorMap.Items.Add(elem.Key);
+ }
+ }
+ 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();
+ }
}
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
{
@@ -47,7 +117,7 @@ _mapAircraftCarriersCollectionGeneric;
}
private void ButtonAddAircraftCarrier_Click(object sender, EventArgs e)
{
- if (_mapAircraftCarriersCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -55,10 +125,12 @@ _mapAircraftCarriersCollectionGeneric;
if (form.ShowDialog() == DialogResult.OK)
{
DrawningObjectAircraftCarrier aircraftcarrier = new(form.SelectedAircraftCarrier);
- if ((_mapAircraftCarriersCollectionGeneric + aircraftcarrier) != -1)
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ??
+string.Empty] + aircraftcarrier != -1)
{
MessageBox.Show("Объект добавлен");
- pictureBox.Image = _mapAircraftCarriersCollectionGeneric.ShowSet();
+ pictureBox.Image =
+ _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@@ -68,6 +140,10 @@ _mapAircraftCarriersCollectionGeneric;
}
private void buttonRemoveAircraftCarrier_Click(object sender, EventArgs e)
{
+ if (listBoxMaps.SelectedIndex == -1)
+ {
+ return;
+ }
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
@@ -78,7 +154,8 @@ _mapAircraftCarriersCollectionGeneric;
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_mapAircraftCarriersCollectionGeneric - pos != null)
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ??
+string.Empty] - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _mapAircraftCarriersCollectionGeneric.ShowSet();
@@ -90,7 +167,7 @@ _mapAircraftCarriersCollectionGeneric;
}
private void buttonShowStorage_Click(object sender, EventArgs e)
{
- if (_mapAircraftCarriersCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -98,7 +175,7 @@ _mapAircraftCarriersCollectionGeneric;
}
private void buttonShowOnMap_Click(object sender, EventArgs e)
{
- if (_mapAircraftCarriersCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -106,7 +183,7 @@ _mapAircraftCarriersCollectionGeneric;
}
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_mapAircraftCarriersCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}