Этап 3. Форма

This commit is contained in:
Hells Hound 2022-10-15 21:12:39 +04:00
parent 5efdfaea7a
commit 49727eceb0
3 changed files with 192 additions and 63 deletions

View File

@ -29,6 +29,12 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.groupBoxTools = new System.Windows.Forms.GroupBox(); 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.buttonShowOnMap = new System.Windows.Forms.Button(); this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonShowStorage = new System.Windows.Forms.Button(); this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonRemoveWarship = new System.Windows.Forms.Button(); this.buttonRemoveWarship = new System.Windows.Forms.Button();
@ -38,14 +44,15 @@
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.buttonDown = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox(); 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.buttonShowStorage); this.groupBoxTools.Controls.Add(this.buttonShowStorage);
this.groupBoxTools.Controls.Add(this.buttonRemoveWarship); this.groupBoxTools.Controls.Add(this.buttonRemoveWarship);
@ -55,20 +62,82 @@
this.groupBoxTools.Controls.Add(this.buttonLeft); this.groupBoxTools.Controls.Add(this.buttonLeft);
this.groupBoxTools.Controls.Add(this.buttonUp); this.groupBoxTools.Controls.Add(this.buttonUp);
this.groupBoxTools.Controls.Add(this.buttonDown); this.groupBoxTools.Controls.Add(this.buttonDown);
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(787, 0); this.groupBoxTools.Location = new System.Drawing.Point(754, 0);
this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(200, 593); this.groupBoxTools.Size = new System.Drawing.Size(217, 649);
this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Tools"; this.groupBoxTools.Text = "Tools";
// //
// 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(205, 257);
this.groupBoxMaps.TabIndex = 19;
this.groupBoxMaps.TabStop = false;
this.groupBoxMaps.Text = "Maps";
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(14, 80);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(180, 35);
this.buttonAddMap.TabIndex = 2;
this.buttonAddMap.Text = "Add map";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(14, 206);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(180, 35);
this.buttonDeleteMap.TabIndex = 4;
this.buttonDeleteMap.Text = "Delete map";
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(14, 121);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(180, 79);
this.listBoxMaps.TabIndex = 3;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(14, 22);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(180, 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(14, 51);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(180, 23);
this.comboBoxSelectorMap.TabIndex = 9;
//
// buttonShowOnMap // buttonShowOnMap
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(13, 431); this.buttonShowOnMap.Location = new System.Drawing.Point(20, 516);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35); this.buttonShowOnMap.Size = new System.Drawing.Size(180, 35);
this.buttonShowOnMap.TabIndex = 18; this.buttonShowOnMap.TabIndex = 18;
this.buttonShowOnMap.Text = "Show map"; this.buttonShowOnMap.Text = "Show map";
this.buttonShowOnMap.UseVisualStyleBackColor = true; this.buttonShowOnMap.UseVisualStyleBackColor = true;
@ -76,9 +145,9 @@
// //
// buttonShowStorage // buttonShowStorage
// //
this.buttonShowStorage.Location = new System.Drawing.Point(13, 323); this.buttonShowStorage.Location = new System.Drawing.Point(20, 475);
this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35); this.buttonShowStorage.Size = new System.Drawing.Size(180, 35);
this.buttonShowStorage.TabIndex = 17; this.buttonShowStorage.TabIndex = 17;
this.buttonShowStorage.Text = "Show storage"; this.buttonShowStorage.Text = "Show storage";
this.buttonShowStorage.UseVisualStyleBackColor = true; this.buttonShowStorage.UseVisualStyleBackColor = true;
@ -86,9 +155,9 @@
// //
// buttonRemoveWarship // buttonRemoveWarship
// //
this.buttonRemoveWarship.Location = new System.Drawing.Point(13, 208); this.buttonRemoveWarship.Location = new System.Drawing.Point(20, 434);
this.buttonRemoveWarship.Name = "buttonRemoveWarship"; this.buttonRemoveWarship.Name = "buttonRemoveWarship";
this.buttonRemoveWarship.Size = new System.Drawing.Size(175, 35); this.buttonRemoveWarship.Size = new System.Drawing.Size(180, 35);
this.buttonRemoveWarship.TabIndex = 16; this.buttonRemoveWarship.TabIndex = 16;
this.buttonRemoveWarship.Text = "Remove warship"; this.buttonRemoveWarship.Text = "Remove warship";
this.buttonRemoveWarship.UseVisualStyleBackColor = true; this.buttonRemoveWarship.UseVisualStyleBackColor = true;
@ -96,18 +165,18 @@
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
this.maskedTextBoxPosition.Location = new System.Drawing.Point(13, 177); this.maskedTextBoxPosition.Location = new System.Drawing.Point(20, 405);
this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23); this.maskedTextBoxPosition.Size = new System.Drawing.Size(180, 23);
this.maskedTextBoxPosition.TabIndex = 15; this.maskedTextBoxPosition.TabIndex = 15;
this.maskedTextBoxPosition.ValidatingType = typeof(int); this.maskedTextBoxPosition.ValidatingType = typeof(int);
// //
// buttonAddWarship // buttonAddWarship
// //
this.buttonAddWarship.Location = new System.Drawing.Point(13, 114); this.buttonAddWarship.Location = new System.Drawing.Point(20, 364);
this.buttonAddWarship.Name = "buttonAddWarship"; this.buttonAddWarship.Name = "buttonAddWarship";
this.buttonAddWarship.Size = new System.Drawing.Size(175, 35); this.buttonAddWarship.Size = new System.Drawing.Size(180, 35);
this.buttonAddWarship.TabIndex = 14; this.buttonAddWarship.TabIndex = 14;
this.buttonAddWarship.Text = "Add warship"; this.buttonAddWarship.Text = "Add warship";
this.buttonAddWarship.UseVisualStyleBackColor = true; this.buttonAddWarship.UseVisualStyleBackColor = true;
@ -118,7 +187,7 @@
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::AircraftCarrier.Properties.Resources.ArrowRight; this.buttonRight.BackgroundImage = global::AircraftCarrier.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(121, 553); this.buttonRight.Location = new System.Drawing.Point(126, 609);
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 = 13; this.buttonRight.TabIndex = 13;
@ -131,7 +200,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::AircraftCarrier.Properties.Resources.ArrowLeft; this.buttonLeft.BackgroundImage = global::AircraftCarrier.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(49, 553); this.buttonLeft.Location = new System.Drawing.Point(54, 609);
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 = 12; this.buttonLeft.TabIndex = 12;
@ -144,7 +213,7 @@
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::AircraftCarrier.Properties.Resources.ArrowUp; this.buttonUp.BackgroundImage = global::AircraftCarrier.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(85, 517); this.buttonUp.Location = new System.Drawing.Point(90, 573);
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 = 11; this.buttonUp.TabIndex = 11;
@ -157,7 +226,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::AircraftCarrier.Properties.Resources.ArrowDown; this.buttonDown.BackgroundImage = global::AircraftCarrier.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(85, 553); this.buttonDown.Location = new System.Drawing.Point(90, 609);
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 = 10; this.buttonDown.TabIndex = 10;
@ -165,25 +234,12 @@
this.buttonDown.UseVisualStyleBackColor = true; this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click); this.buttonDown.Click += new System.EventHandler(this.ButtonMove_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(13, 22);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
this.comboBoxSelectorMap.TabIndex = 9;
this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
//
// pictureBox // pictureBox
// //
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.pictureBox.Location = new System.Drawing.Point(0, 0); this.pictureBox.Location = new System.Drawing.Point(0, 0);
this.pictureBox.Name = "pictureBox"; this.pictureBox.Name = "pictureBox";
this.pictureBox.Size = new System.Drawing.Size(787, 593); this.pictureBox.Size = new System.Drawing.Size(754, 649);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -191,13 +247,15 @@
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(987, 593); this.ClientSize = new System.Drawing.Size(971, 649);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetWarships"; this.Name = "FormMapWithSetWarships";
this.Text = "FormMapWithSetWarships"; this.Text = "FormMapWithSetWarships";
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);
@ -217,5 +275,10 @@
private Button buttonRemoveWarship; private Button buttonRemoveWarship;
private MaskedTextBox maskedTextBoxPosition; private MaskedTextBox maskedTextBoxPosition;
private Button buttonAddWarship; private Button buttonAddWarship;
private GroupBox groupBoxMaps;
private Button buttonAddMap;
private Button buttonDeleteMap;
private ListBox listBoxMaps;
private TextBox textBoxNewMapName;
} }
} }

View File

@ -14,36 +14,97 @@ namespace AircraftCarrier
public partial class FormMapWithSetWarships : Form public partial class FormMapWithSetWarships : Form
{ {
/// <summary> /// <summary>
/// Объект от класса карты с набором объектов /// Словарь для выпадающего списка
/// </summary> /// </summary>
private MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap> _mapWarshipsCollectionGeneric; private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Простая карта", new SimpleMap() },
{ "Преграды-линии", new LineMap() }
};
/// <summary>
/// Объект от коллекции карт
/// </summary>
private readonly MapsCollection _mapsCollection;
/// <summary> /// <summary>
/// Конструктор /// Конструктор
/// </summary> /// </summary>
public FormMapWithSetWarships() public FormMapWithSetWarships()
{ {
InitializeComponent(); InitializeComponent();
_mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
comboBoxSelectorMap.Items.Clear();
foreach (var elem in _mapsDict)
{
comboBoxSelectorMap.Items.Add(elem.Key);
}
} }
private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) /// <summary>
/// Заполнение listBoxMaps
/// </summary>
private void ReloadMaps()
{ {
AbstractMap map = null; int index = listBoxMaps.SelectedIndex;
switch (comboBoxSelectorMap.Text)
listBoxMaps.Items.Clear();
for (int i = 0; i < _mapsCollection.Keys.Count; i++)
{ {
case "Простая карта": listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
map = new SimpleMap();
break;
case "Преграды-линии":
map = new LineMap();
break;
} }
if (map != null)
if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
{ {
_mapWarshipsCollectionGeneric = new MapWithSetWarshipsGeneric<DrawingObjectWarship, AbstractMap>( listBoxMaps.SelectedIndex = 0;
pictureBox.Width, pictureBox.Height, map);
} }
else else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
{ {
_mapWarshipsCollectionGeneric = null; listBoxMaps.SelectedIndex = index;
}
}
/// <summary>
/// Добавление карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
}
/// <summary>
/// Выбор карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
{
pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
/// <summary>
/// Удаление карты
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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();
} }
} }
/// <summary> /// <summary>
@ -53,7 +114,7 @@ namespace AircraftCarrier
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonAddWarship_Click(object sender, EventArgs e) private void ButtonAddWarship_Click(object sender, EventArgs e)
{ {
if (_mapWarshipsCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -61,10 +122,10 @@ namespace AircraftCarrier
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
DrawingObjectWarship warship = new(form.SelectedWarship); DrawingObjectWarship warship = new(form.SelectedWarship);
if (_mapWarshipsCollectionGeneric + warship >= 0) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + warship >= 0)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapWarshipsCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -79,6 +140,10 @@ namespace AircraftCarrier
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonRemoveWarship_Click(object sender, EventArgs e) private void ButtonRemoveWarship_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{ {
return; return;
@ -88,10 +153,10 @@ namespace AircraftCarrier
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapWarshipsCollectionGeneric - pos != null) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapWarshipsCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -105,11 +170,11 @@ namespace AircraftCarrier
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonShowStorage_Click(object sender, EventArgs e) private void ButtonShowStorage_Click(object sender, EventArgs e)
{ {
if (_mapWarshipsCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapWarshipsCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
/// <summary> /// <summary>
/// Вывод карты /// Вывод карты
@ -118,11 +183,11 @@ namespace AircraftCarrier
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonShowOnMap_Click(object sender, EventArgs e) private void ButtonShowOnMap_Click(object sender, EventArgs e)
{ {
if(_mapWarshipsCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapWarshipsCollectionGeneric.ShowOnMap(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
} }
/// <summary> /// <summary>
/// Перемещение /// Перемещение
@ -131,7 +196,7 @@ namespace AircraftCarrier
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonMove_Click(object sender, EventArgs e) private void ButtonMove_Click(object sender, EventArgs e)
{ {
if (_mapWarshipsCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -153,7 +218,7 @@ namespace AircraftCarrier
dir = Direction.Right; dir = Direction.Right;
break; break;
} }
pictureBox.Image = _mapWarshipsCollectionGeneric.MoveObject(dir); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
} }
} }
} }

View File

@ -149,12 +149,13 @@ namespace AircraftCarrier
g.FillRectangle(Brushes.Aqua, 0, 0, _pictureWidth, _pictureHeight); g.FillRectangle(Brushes.Aqua, 0, 0, _pictureWidth, _pictureHeight);
for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
{ {
for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) for (int j = 0; j < _pictureHeight / _placeSizeHeight; ++j)
{//линия рамзетки места {//линия рамзетки места
g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2); g.DrawLine(pen, i * _placeSizeWidth + 20, j * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2);
g.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth * 2, j * _placeSizeHeight * 2); g.DrawLine(pen, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + 2, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2);
g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + _placeSizeHeight / 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), j * _placeSizeHeight + _placeSizeHeight);
} }
g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); g.DrawLine(pen, i * _placeSizeWidth + 20, _pictureHeight / _placeSizeHeight * _placeSizeHeight + 2, i * _placeSizeWidth + (int)(_placeSizeWidth * 0.8), _pictureHeight / _placeSizeHeight * _placeSizeHeight + 2);
} }
} }
/// <summary> /// <summary>