From 40da0fe01d76398aa858f19fadb765242094e041 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 10 Oct 2022 17:33:07 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=201.=20=D0=9F?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20=D1=81=20=D0=BC=D0=B0?= =?UTF-8?q?=D1=81=D1=81=D0=B8=D0=B2=D0=B0=20=D0=BD=D0=B0=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/FormLocomotive.cs | 2 - .../MapWithSetLocomotivesGeneric.cs | 18 ++--- .../Locomotive/SetLocomotivesGeneric.cs | 74 +++++++++---------- 3 files changed, 43 insertions(+), 51 deletions(-) diff --git a/Locomotive/Locomotive/FormLocomotive.cs b/Locomotive/Locomotive/FormLocomotive.cs index 7d782f5..2acdda2 100644 --- a/Locomotive/Locomotive/FormLocomotive.cs +++ b/Locomotive/Locomotive/FormLocomotive.cs @@ -3,7 +3,6 @@ namespace Locomotive public partial class FormLocomotive : Form { private DrawningLocomotive _locomotive; - public DrawningLocomotive SelectedLocomotive { get; private set; } public FormLocomotive() @@ -41,7 +40,6 @@ namespace Locomotive SetData(); Draw(); } - private void ButtonMove_Click(object sender, EventArgs e) { // diff --git a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs index 71eaad3..8f1b26e 100644 --- a/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/MapWithSetLocomotivesGeneric.cs @@ -55,13 +55,9 @@ namespace Locomotive public Bitmap ShowOnMap() { Shaking(); - for (int i = 0; i < _setLocomotives.Count; i++) + foreach (var locomotive in _setLocomotives.GetLocomotives()) { - var locomotive = _setLocomotives.Get(i); - if (locomotive != null) - { - return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive); - } + return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive); } return new(_pictureWidth, _pictureHeight); } @@ -80,11 +76,11 @@ namespace Locomotive int j = _setLocomotives.Count - 1; for (int i = 0; i < _setLocomotives.Count; i++) { - if (_setLocomotives.Get(i) == null) + if (_setLocomotives[i] == null) { for (; j > i; j--) { - var locomotive = _setLocomotives.Get(j); + var locomotive = _setLocomotives[j]; if (locomotive != null) { _setLocomotives.Insert(locomotive, i); @@ -148,11 +144,11 @@ namespace Locomotive int curWidth = 0; int curHeight = 0; - for (int i = 0; i < _setLocomotives.Count; i++) + foreach (var locomotive in _setLocomotives.GetLocomotives()) { // установка позиции - _setLocomotives.Get(i)?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 15, _pictureWidth, _pictureHeight); - _setLocomotives.Get(i)?.DrawningObject(g); + locomotive?.SetObject(curWidth * _placeSizeWidth + 10, curHeight * _placeSizeHeight + 15, _pictureWidth, _pictureHeight); + locomotive?.DrawningObject(g); if (curWidth < width) curWidth++; else { diff --git a/Locomotive/Locomotive/SetLocomotivesGeneric.cs b/Locomotive/Locomotive/SetLocomotivesGeneric.cs index 5deb455..342fd46 100644 --- a/Locomotive/Locomotive/SetLocomotivesGeneric.cs +++ b/Locomotive/Locomotive/SetLocomotivesGeneric.cs @@ -9,14 +9,18 @@ namespace Locomotive internal class SetLocomotivesGeneric where T : class { - private readonly T[] _places; + /// Список хранимых объектов + private readonly List _places; /// Количество объектов в массиве - public int Count => _places.Length; + public int Count => _places.Count; + // Ограничение на количество + private readonly int _maxCount; /// Конструктор public SetLocomotivesGeneric(int count) { - _places = new T[count]; + _maxCount = count; + _places = new List(); } /// Добавление объекта в набор public int Insert(T locomotive) @@ -26,53 +30,47 @@ namespace Locomotive /// Добавление объекта в набор на конкретную позицию public int Insert(T locomotive, int position) { - if (position >= _places.Length|| position < 0) return -1; + if (position >= _maxCount|| position < 0) return -1; + _places.Insert(position, locomotive); - if (_places[position] == null) - { - _places[position] = locomotive; - return position; - } - - int emptyEl = -1; - - for (int i = position + 1; i < Count; i++) - { - if (_places[i] == null) - { - emptyEl = i; - break; - } - } - - if (emptyEl == -1) - { - return -1; - } - - for (int i = emptyEl; i > position; i--) - { - _places[i] = _places[i - 1]; - } - _places[position] = locomotive; return position; } /// Удаление объекта из набора с конкретной позиции public T Remove(int position) { - if (position >= _places.Length || position < 0) return null; + if (position >= _maxCount || position < 0) return null; T result = _places[position]; - _places[position] = null; + _places.RemoveAt(position); return result; } - /// Получение объекта из набора по позиции - public T Get(int position) + // Индексатор + public T this[int position] { - if (position >= _places.Length || position < 0) + get { - return null; + if (position >= _maxCount || position < 0) return null; + return _places[position]; + } + set + { + if (position >= _maxCount || position < 0) return; + Insert(value, position); + } + } + /// Проход по набору до первого пустого + public IEnumerable GetLocomotives() + { + foreach (var locomotive in _places) + { + if (locomotive != null) + { + yield return locomotive; + } + else + { + yield break; + } } - return _places[position]; } } } From a9d7e440cc0e04f6c29b53c339cc249ec1859a03 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 10 Oct 2022 18:26:35 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=202.=20=D0=94?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D1=81=D1=81=20MapsCollection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Locomotive/Locomotive/MapsCollection.cs | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Locomotive/Locomotive/MapsCollection.cs diff --git a/Locomotive/Locomotive/MapsCollection.cs b/Locomotive/Locomotive/MapsCollection.cs new file mode 100644 index 0000000..1ea1022 --- /dev/null +++ b/Locomotive/Locomotive/MapsCollection.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Locomotive +{ + internal class MapsCollection + { + /// Словарь (хранилище) с картами + readonly Dictionary> _mapStorages; + /// Возвращение списка названий карт + public List Keys => _mapStorages.Keys.ToList(); + /// Ширина окна отрисовки + private readonly int _pictureWidth; + /// Высота окна отрисовки + private readonly int _pictureHeight; + /// Конструктор + public MapsCollection(int pictureWidth, int pictureHeight) + { + _mapStorages = new Dictionary>(); + _pictureWidth = pictureWidth; + _pictureHeight = pictureHeight; + } + /// Добавление карты + public void AddMap(string name, AbstractMap map) + { + // Логика для добавления + if (!_mapStorages.ContainsKey(name)) _mapStorages.Add(name, new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); + } + /// Удаление карты + public void DelMap(string name) + { + // Логика для удаления + if (_mapStorages.ContainsKey(name)) _mapStorages.Remove(name); + } + /// Доступ к парковке + public MapWithSetLocomotivesGeneric this[string ind] + { + get + { + // Логика получения объекта + if (_mapStorages.ContainsKey(ind)) return _mapStorages[ind]; + return null; + } + } + + } +} From f755c4039769ffa2a50f6fefb7bf908d83ec0524 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Mon, 10 Oct 2022 19:03:51 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=AD=D1=82=D0=B0=D0=BF=203.=20=D0=9E?= =?UTF-8?q?=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetLocomotives.Designer.cs | 119 +++++++++++++----- .../Locomotive/FormMapWithSetLocomotives.cs | 111 +++++++++++----- 2 files changed, 170 insertions(+), 60 deletions(-) diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs index 110cc39..c3c2388 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { 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.buttonRight = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); @@ -38,14 +44,15 @@ this.buttonRemoveLocomotive = new System.Windows.Forms.Button(); this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonAddLocomotive = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.pictureBox = new System.Windows.Forms.PictureBox(); this.groupBoxTools.SuspendLayout(); + this.groupBox1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); // // groupBoxTools // + this.groupBoxTools.Controls.Add(this.groupBox1); this.groupBoxTools.Controls.Add(this.buttonLeft); this.groupBoxTools.Controls.Add(this.buttonRight); this.groupBoxTools.Controls.Add(this.buttonDown); @@ -55,20 +62,82 @@ this.groupBoxTools.Controls.Add(this.buttonRemoveLocomotive); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.buttonAddLocomotive); - this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; this.groupBoxTools.Location = new System.Drawing.Point(580, 0); 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.TabStop = false; 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 // this.buttonLeft.BackgroundImage = global::Locomotive.Properties.Resources.left_arrow; 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.Size = new System.Drawing.Size(40, 40); this.buttonLeft.TabIndex = 7; @@ -79,7 +148,7 @@ // this.buttonRight.BackgroundImage = global::Locomotive.Properties.Resources.right_arrow; 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.Size = new System.Drawing.Size(40, 40); this.buttonRight.TabIndex = 7; @@ -90,7 +159,7 @@ // this.buttonDown.BackgroundImage = global::Locomotive.Properties.Resources.down_arrow; 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.Size = new System.Drawing.Size(40, 40); this.buttonDown.TabIndex = 7; @@ -101,7 +170,7 @@ // this.buttonUp.BackgroundImage = global::Locomotive.Properties.Resources.up_arrow; 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.Size = new System.Drawing.Size(40, 40); this.buttonUp.TabIndex = 6; @@ -110,7 +179,7 @@ // // 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.Size = new System.Drawing.Size(207, 29); this.buttonShowOnMap.TabIndex = 5; @@ -120,9 +189,9 @@ // // 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.Size = new System.Drawing.Size(207, 29); + this.buttonShowStorage.Size = new System.Drawing.Size(208, 29); this.buttonShowStorage.TabIndex = 4; this.buttonShowStorage.Text = "Show Storage"; this.buttonShowStorage.UseVisualStyleBackColor = true; @@ -130,7 +199,7 @@ // // 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.Size = new System.Drawing.Size(207, 30); this.buttonRemoveLocomotive.TabIndex = 3; @@ -140,7 +209,7 @@ // // 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.Name = "maskedTextBoxPosition"; this.maskedTextBoxPosition.Size = new System.Drawing.Size(208, 27); @@ -148,7 +217,7 @@ // // 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.Size = new System.Drawing.Size(208, 29); this.buttonAddLocomotive.TabIndex = 1; @@ -156,25 +225,12 @@ this.buttonAddLocomotive.UseVisualStyleBackColor = true; 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 // 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(580, 504); + this.pictureBox.Size = new System.Drawing.Size(580, 546); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // @@ -182,13 +238,15 @@ // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); 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.groupBoxTools); this.Name = "FormMapWithSetLocomotives"; this.Text = "FormMapWithSetLocomotives"; this.groupBoxTools.ResumeLayout(false); this.groupBoxTools.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); this.ResumeLayout(false); @@ -208,5 +266,10 @@ private Button buttonDown; private Button buttonRight; private Button buttonLeft; + private GroupBox groupBox1; + private TextBox textBoxNewMapName; + private Button buttonAddMap; + private Button buttonDeleteMap; + private ListBox listBoxMaps; } } \ No newline at end of file diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs index 34f705f..9628dd9 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs @@ -12,42 +12,82 @@ namespace Locomotive { public partial class FormMapWithSetLocomotives : Form { - /// Объект от класса карты с набором объектов - private MapWithSetLocomotivesGeneric _mapLocomotivesCollectionGeneric; + /// Словарь для выпадающего списка + private readonly Dictionary _mapsDict = new() + { + { "Simple Map", new SimpleMap() }, + { "Spike Map", new SpikeMap() }, + { "Rail Map", new RailroadMap() } + }; + /// Объект от коллекции карт + private readonly MapsCollection _mapsCollection; + /// Конструктор public FormMapWithSetLocomotives() { 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; - switch (comboBoxSelectorMap.Text) + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + /// Удаление карты + private void buttonDeleteMap_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) { - case "Simple Map": - map = new SimpleMap(); - break; - case "Spike Map": - map = new SpikeMap(); - break; - case "Rail Map": - map = new RailroadMap(); - break; + return; } - if (map != null) + if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?","Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { - _mapLocomotivesCollectionGeneric = new MapWithSetLocomotivesGeneric - (pictureBox.Width, pictureBox.Height, map); - } - else - { - _mapLocomotivesCollectionGeneric = null; + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + ReloadMaps(); } } /// Добавление объекта private void buttonAddLocomotive_Click(object sender, EventArgs e) { - if (_mapLocomotivesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -55,10 +95,10 @@ namespace Locomotive if (form.ShowDialog() == DialogResult.OK) { DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive); - if (_mapLocomotivesCollectionGeneric + locomotive != -1) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1) { MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -69,6 +109,10 @@ namespace Locomotive /// Удаление объекта private void buttonRemoveLocomotive_Click(object sender, EventArgs e) { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) { return; @@ -78,10 +122,10 @@ namespace Locomotive return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapLocomotivesCollectionGeneric - pos is not null) + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -91,25 +135,27 @@ namespace Locomotive /// Вывод набора private void buttonShowStorage_Click(object sender, EventArgs e) { - if (_mapLocomotivesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet(); + pictureBox.Image = + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } /// Вывод карты private void buttonShowOnMap_Click(object sender, EventArgs e) { - if (_mapLocomotivesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowOnMap(); + pictureBox.Image = + _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } /// Перемещение private void buttonMove_Click(object sender, EventArgs e) { - if (_mapLocomotivesCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -131,7 +177,8 @@ namespace Locomotive dir = Direction.Right; break; } - pictureBox.Image = _mapLocomotivesCollectionGeneric.MoveObject(dir); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir); } + } } From f4a5cc3dd21af0454924426a6567689174ff3a9a Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Fri, 14 Oct 2022 17:32:23 +0400 Subject: [PATCH 4/4] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=D0=B0?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=B0=D0=BD=D0=B3=D0=BB=D0=B8=D0=B9=D1=81?= =?UTF-8?q?=D0=BA=D0=B8=D0=B9=20=D0=B2=20=D1=81=D0=BE=D0=BE=D1=82=D0=B2?= =?UTF-8?q?=D0=B5=D1=82=D1=81=D1=82=D0=B2=D0=B8=D0=B8=20=D1=81=20=D1=82?= =?UTF-8?q?=D1=80=D0=B5=D0=B1=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Locomotive/FormMapWithSetLocomotives.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs index 9628dd9..a4dcc05 100644 --- a/Locomotive/Locomotive/FormMapWithSetLocomotives.cs +++ b/Locomotive/Locomotive/FormMapWithSetLocomotives.cs @@ -55,12 +55,12 @@ namespace Locomotive { if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) { - MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Not all data is complete", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text)) { - MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("No such map", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); @@ -78,7 +78,7 @@ namespace Locomotive { return; } - if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?","Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?","Deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); ReloadMaps(); @@ -97,12 +97,12 @@ namespace Locomotive DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive); if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + locomotive != -1) { - MessageBox.Show("Объект добавлен"); + MessageBox.Show("Object added"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { - MessageBox.Show("Не удалось добавить объект"); + MessageBox.Show("Failed to add object"); } } } @@ -117,19 +117,19 @@ namespace Locomotive { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Remove object?", "Removing", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) { - MessageBox.Show("Объект удален"); + MessageBox.Show("Object removed"); pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { - MessageBox.Show("Не удалось удалить объект"); + MessageBox.Show("Failed to remove object"); } } /// Вывод набора