Этап 3. Обновление формы

This commit is contained in:
Данила Мочалов 2022-10-10 19:03:51 +04:00
parent a9d7e440cc
commit f755c40397
2 changed files with 170 additions and 60 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.groupBox1 = new System.Windows.Forms.GroupBox();
this.buttonDeleteMap = new System.Windows.Forms.Button();
this.listBoxMaps = new System.Windows.Forms.ListBox();
this.buttonAddMap = new System.Windows.Forms.Button();
this.textBoxNewMapName = new System.Windows.Forms.TextBox();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonLeft = new System.Windows.Forms.Button(); this.buttonLeft = 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();
@ -38,14 +44,15 @@
this.buttonRemoveLocomotive = new System.Windows.Forms.Button(); this.buttonRemoveLocomotive = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddLocomotive = new System.Windows.Forms.Button(); this.buttonAddLocomotive = 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.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// groupBoxTools // groupBoxTools
// //
this.groupBoxTools.Controls.Add(this.groupBox1);
this.groupBoxTools.Controls.Add(this.buttonLeft); this.groupBoxTools.Controls.Add(this.buttonLeft);
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,20 +62,82 @@
this.groupBoxTools.Controls.Add(this.buttonRemoveLocomotive); this.groupBoxTools.Controls.Add(this.buttonRemoveLocomotive);
this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
this.groupBoxTools.Controls.Add(this.buttonAddLocomotive); this.groupBoxTools.Controls.Add(this.buttonAddLocomotive);
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(580, 0); this.groupBoxTools.Location = new System.Drawing.Point(580, 0);
this.groupBoxTools.Name = "groupBoxTools"; this.groupBoxTools.Name = "groupBoxTools";
this.groupBoxTools.Size = new System.Drawing.Size(220, 504); this.groupBoxTools.Size = new System.Drawing.Size(220, 546);
this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false; this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Tools"; this.groupBoxTools.Text = "Tools";
// //
// groupBox1
//
this.groupBox1.Controls.Add(this.buttonDeleteMap);
this.groupBox1.Controls.Add(this.listBoxMaps);
this.groupBox1.Controls.Add(this.buttonAddMap);
this.groupBox1.Controls.Add(this.textBoxNewMapName);
this.groupBox1.Controls.Add(this.comboBoxSelectorMap);
this.groupBox1.Location = new System.Drawing.Point(6, 26);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(208, 250);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Maps";
//
// buttonDeleteMap
//
this.buttonDeleteMap.Location = new System.Drawing.Point(6, 198);
this.buttonDeleteMap.Name = "buttonDeleteMap";
this.buttonDeleteMap.Size = new System.Drawing.Size(196, 29);
this.buttonDeleteMap.TabIndex = 3;
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 = 20;
this.listBoxMaps.Location = new System.Drawing.Point(6, 128);
this.listBoxMaps.Name = "listBoxMaps";
this.listBoxMaps.Size = new System.Drawing.Size(196, 64);
this.listBoxMaps.TabIndex = 2;
this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged);
//
// buttonAddMap
//
this.buttonAddMap.Location = new System.Drawing.Point(6, 93);
this.buttonAddMap.Name = "buttonAddMap";
this.buttonAddMap.Size = new System.Drawing.Size(196, 29);
this.buttonAddMap.TabIndex = 1;
this.buttonAddMap.Text = "Add Map";
this.buttonAddMap.UseVisualStyleBackColor = true;
this.buttonAddMap.Click += new System.EventHandler(this.buttonAddMap_Click);
//
// textBoxNewMapName
//
this.textBoxNewMapName.Location = new System.Drawing.Point(6, 26);
this.textBoxNewMapName.Name = "textBoxNewMapName";
this.textBoxNewMapName.Size = new System.Drawing.Size(196, 27);
this.textBoxNewMapName.TabIndex = 0;
//
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Simple Map",
"Spike Map",
"Rail Map"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 59);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(196, 28);
this.comboBoxSelectorMap.TabIndex = 0;
//
// buttonLeft // buttonLeft
// //
this.buttonLeft.BackgroundImage = global::Locomotive.Properties.Resources.left_arrow; this.buttonLeft.BackgroundImage = global::Locomotive.Properties.Resources.left_arrow;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonLeft.Location = new System.Drawing.Point(42, 446); this.buttonLeft.Location = new System.Drawing.Point(42, 502);
this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(40, 40); this.buttonLeft.Size = new System.Drawing.Size(40, 40);
this.buttonLeft.TabIndex = 7; this.buttonLeft.TabIndex = 7;
@ -79,7 +148,7 @@
// //
this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow; this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonRight.Location = new System.Drawing.Point(134, 446); this.buttonRight.Location = new System.Drawing.Point(134, 502);
this.buttonRight.Name = "buttonRight"; this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(40, 40); this.buttonRight.Size = new System.Drawing.Size(40, 40);
this.buttonRight.TabIndex = 7; this.buttonRight.TabIndex = 7;
@ -90,7 +159,7 @@
// //
this.buttonDown.BackgroundImage = global::Locomotive.Properties.Resources.down_arrow; this.buttonDown.BackgroundImage = global::Locomotive.Properties.Resources.down_arrow;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonDown.Location = new System.Drawing.Point(88, 446); this.buttonDown.Location = new System.Drawing.Point(88, 502);
this.buttonDown.Name = "buttonDown"; this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(40, 40); this.buttonDown.Size = new System.Drawing.Size(40, 40);
this.buttonDown.TabIndex = 7; this.buttonDown.TabIndex = 7;
@ -101,7 +170,7 @@
// //
this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow; this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
this.buttonUp.Location = new System.Drawing.Point(88, 400); this.buttonUp.Location = new System.Drawing.Point(88, 456);
this.buttonUp.Name = "buttonUp"; this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(40, 40); this.buttonUp.Size = new System.Drawing.Size(40, 40);
this.buttonUp.TabIndex = 6; this.buttonUp.TabIndex = 6;
@ -110,7 +179,7 @@
// //
// buttonShowOnMap // buttonShowOnMap
// //
this.buttonShowOnMap.Location = new System.Drawing.Point(7, 282); this.buttonShowOnMap.Location = new System.Drawing.Point(7, 421);
this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(207, 29); this.buttonShowOnMap.Size = new System.Drawing.Size(207, 29);
this.buttonShowOnMap.TabIndex = 5; this.buttonShowOnMap.TabIndex = 5;
@ -120,9 +189,9 @@
// //
// buttonShowStorage // buttonShowStorage
// //
this.buttonShowStorage.Location = new System.Drawing.Point(7, 247); this.buttonShowStorage.Location = new System.Drawing.Point(6, 386);
this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(207, 29); this.buttonShowStorage.Size = new System.Drawing.Size(208, 29);
this.buttonShowStorage.TabIndex = 4; this.buttonShowStorage.TabIndex = 4;
this.buttonShowStorage.Text = "Show Storage"; this.buttonShowStorage.Text = "Show Storage";
this.buttonShowStorage.UseVisualStyleBackColor = true; this.buttonShowStorage.UseVisualStyleBackColor = true;
@ -130,7 +199,7 @@
// //
// buttonRemoveLocomotive // buttonRemoveLocomotive
// //
this.buttonRemoveLocomotive.Location = new System.Drawing.Point(7, 211); this.buttonRemoveLocomotive.Location = new System.Drawing.Point(7, 350);
this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive"; this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
this.buttonRemoveLocomotive.Size = new System.Drawing.Size(207, 30); this.buttonRemoveLocomotive.Size = new System.Drawing.Size(207, 30);
this.buttonRemoveLocomotive.TabIndex = 3; this.buttonRemoveLocomotive.TabIndex = 3;
@ -140,7 +209,7 @@
// //
// maskedTextBoxPosition // maskedTextBoxPosition
// //
this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 159); this.maskedTextBoxPosition.Location = new System.Drawing.Point(6, 317);
this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(208, 27); this.maskedTextBoxPosition.Size = new System.Drawing.Size(208, 27);
@ -148,7 +217,7 @@
// //
// buttonAddLocomotive // buttonAddLocomotive
// //
this.buttonAddLocomotive.Location = new System.Drawing.Point(6, 96); this.buttonAddLocomotive.Location = new System.Drawing.Point(6, 282);
this.buttonAddLocomotive.Name = "buttonAddLocomotive"; this.buttonAddLocomotive.Name = "buttonAddLocomotive";
this.buttonAddLocomotive.Size = new System.Drawing.Size(208, 29); this.buttonAddLocomotive.Size = new System.Drawing.Size(208, 29);
this.buttonAddLocomotive.TabIndex = 1; this.buttonAddLocomotive.TabIndex = 1;
@ -156,25 +225,12 @@
this.buttonAddLocomotive.UseVisualStyleBackColor = true; this.buttonAddLocomotive.UseVisualStyleBackColor = true;
this.buttonAddLocomotive.Click += new System.EventHandler(this.buttonAddLocomotive_Click); this.buttonAddLocomotive.Click += new System.EventHandler(this.buttonAddLocomotive_Click);
// //
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.FormattingEnabled = true;
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Simple Map",
"Spike Map",
"Rail Map"});
this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 39);
this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
this.comboBoxSelectorMap.Size = new System.Drawing.Size(208, 28);
this.comboBoxSelectorMap.TabIndex = 0;
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(580, 504); this.pictureBox.Size = new System.Drawing.Size(580, 546);
this.pictureBox.TabIndex = 1; this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false; this.pictureBox.TabStop = false;
// //
@ -182,13 +238,15 @@
// //
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(800, 504); this.ClientSize = new System.Drawing.Size(800, 546);
this.Controls.Add(this.pictureBox); this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools); this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetLocomotives"; this.Name = "FormMapWithSetLocomotives";
this.Text = "FormMapWithSetLocomotives"; this.Text = "FormMapWithSetLocomotives";
this.groupBoxTools.ResumeLayout(false); this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout(); this.groupBoxTools.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
@ -208,5 +266,10 @@
private Button buttonDown; private Button buttonDown;
private Button buttonRight; private Button buttonRight;
private Button buttonLeft; private Button buttonLeft;
private GroupBox groupBox1;
private TextBox textBoxNewMapName;
private Button buttonAddMap;
private Button buttonDeleteMap;
private ListBox listBoxMaps;
} }
} }

View File

@ -12,42 +12,82 @@ namespace Locomotive
{ {
public partial class FormMapWithSetLocomotives : Form public partial class FormMapWithSetLocomotives : Form
{ {
/// Объект от класса карты с набором объектов /// Словарь для выпадающего списка
private MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap> _mapLocomotivesCollectionGeneric; private readonly Dictionary<string, AbstractMap> _mapsDict = new()
{
{ "Simple Map", new SimpleMap() },
{ "Spike Map", new SpikeMap() },
{ "Rail Map", new RailroadMap() }
};
/// Объект от коллекции карт
private readonly MapsCollection _mapsCollection;
/// Конструктор
public FormMapWithSetLocomotives() public FormMapWithSetLocomotives()
{ {
InitializeComponent(); 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; pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
switch (comboBoxSelectorMap.Text) }
/// Удаление карты
private void buttonDeleteMap_Click(object sender, EventArgs e)
{
if (listBoxMaps.SelectedIndex == -1)
{ {
case "Simple Map": return;
map = new SimpleMap();
break;
case "Spike Map":
map = new SpikeMap();
break;
case "Rail Map":
map = new RailroadMap();
break;
} }
if (map != null) if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?","Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{ {
_mapLocomotivesCollectionGeneric = new MapWithSetLocomotivesGeneric<DrawningObjectLocomotive, AbstractMap> _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
(pictureBox.Width, pictureBox.Height, map); ReloadMaps();
}
else
{
_mapLocomotivesCollectionGeneric = null;
} }
} }
/// Добавление объекта /// Добавление объекта
private void buttonAddLocomotive_Click(object sender, EventArgs e) private void buttonAddLocomotive_Click(object sender, EventArgs e)
{ {
if (_mapLocomotivesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -55,10 +95,10 @@ namespace Locomotive
if (form.ShowDialog() == DialogResult.OK) if (form.ShowDialog() == DialogResult.OK)
{ {
DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive); DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive);
if (_mapLocomotivesCollectionGeneric + locomotive != -1) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1)
{ {
MessageBox.Show("Объект добавлен"); MessageBox.Show("Объект добавлен");
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -69,6 +109,10 @@ namespace Locomotive
/// Удаление объекта /// Удаление объекта
private void buttonRemoveLocomotive_Click(object sender, EventArgs e) private void buttonRemoveLocomotive_Click(object sender, EventArgs e)
{ {
if (listBoxMaps.SelectedIndex == -1)
{
return;
}
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{ {
return; return;
@ -78,10 +122,10 @@ namespace Locomotive
return; return;
} }
int pos = Convert.ToInt32(maskedTextBoxPosition.Text); int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
if (_mapLocomotivesCollectionGeneric - pos is not null) if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{ {
MessageBox.Show("Объект удален"); MessageBox.Show("Объект удален");
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
} }
else else
{ {
@ -91,25 +135,27 @@ namespace Locomotive
/// Вывод набора /// Вывод набора
private void buttonShowStorage_Click(object sender, EventArgs e) private void buttonShowStorage_Click(object sender, EventArgs e)
{ {
if (_mapLocomotivesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapLocomotivesCollectionGeneric.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 (_mapLocomotivesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowOnMap(); pictureBox.Image =
_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
} }
/// Перемещение /// Перемещение
private void buttonMove_Click(object sender, EventArgs e) private void buttonMove_Click(object sender, EventArgs e)
{ {
if (_mapLocomotivesCollectionGeneric == null) if (listBoxMaps.SelectedIndex == -1)
{ {
return; return;
} }
@ -131,7 +177,8 @@ namespace Locomotive
dir = Direction.Right; dir = Direction.Right;
break; break;
} }
pictureBox.Image = _mapLocomotivesCollectionGeneric.MoveObject(dir); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
} }
} }
} }