From e6d43c47657988ef8223da5d4ed2f9e35d86c57e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Mon, 10 Oct 2022 19:23:32 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=A1=D0=BC=D0=B5=D0=BD=D0=B0=20=D0=BC?= =?UTF-8?q?=D0=B0=D1=81=D1=81=D0=B8=D0=B2=D0=B0=20=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapWithSetPlainGeneric.cs | 28 +++--- .../AirPlaneWithRadar/SetPlaneGeneric.cs | 87 +++++++------------ 2 files changed, 46 insertions(+), 69 deletions(-) diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs index 58687aa..457fbe3 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs @@ -55,13 +55,9 @@ namespace AirPlaneWithRadar public Bitmap ShowOnMap() { Shaking(); - for (int i = 0; i < _setPlains.Count; i++) + foreach (var plain in _setPlains.GetPlains()) { - var plain = _setPlains.Get(i); - if (plain != null) - { - return _map.CreateMap(_pictureWidth, _pictureHeight, plain); - } + return _map.CreateMap(_pictureWidth, _pictureHeight, plain); } return new(_pictureWidth, _pictureHeight); } @@ -80,11 +76,11 @@ namespace AirPlaneWithRadar int j = _setPlains.Count - 1; for (int i = 0; i < _setPlains.Count; i++) { - if (_setPlains.Get(i) == null) + if (_setPlains[i] == null) { for (; j > i; j--) { - var plain = _setPlains.Get(j); + var plain = _setPlains[i]; if (plain != null) { _setPlains.Insert(plain, i); @@ -117,32 +113,34 @@ namespace AirPlaneWithRadar } private void DrawPlains(Graphics g) { + + int CountWidth = _pictureWidth / _placeSizeWidth; - int x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4; + int x = _pictureWidth - _placeSizeWidth; int y = _placeSizeHeight / 4; for (int k = 0; k < _setPlains.Count; k++) { - if (_setPlains.Get(k) != null) + if (_setPlains[k] != null) { if ((k + 1) % CountWidth != 0 || k == 0) { - _setPlains.Get(k)?.SetObject(x, y, _pictureWidth, _pictureHeight); - _setPlains.Get(k)?.DrawningObject(g); + _setPlains[k]?.SetObject(x, y, _pictureWidth, _pictureHeight); + _setPlains[k]?.DrawningObject(g); x -= _placeSizeWidth; } else { - _setPlains.Get(k)?.SetObject(x, y, _pictureWidth, _pictureHeight); - _setPlains.Get(k)?.DrawningObject(g); + _setPlains[k]?.SetObject(x, y, _pictureWidth, _pictureHeight); + _setPlains[k]?.DrawningObject(g); x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4; y += _placeSizeHeight; } } - if (_setPlains.Get(k) == null) + if (_setPlains[k] == null) { if ((k + 1) % CountWidth != 0 || k == 0) x -= _placeSizeWidth; diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs index 4196693..4e83bdd 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs @@ -10,74 +10,53 @@ namespace AirPlaneWithRadar where T : class { - private readonly T[] _places; - public int Count => _places.Length; + private readonly List _places; + public int Count => _places.Count; + private readonly int _maxCount; public SetPlaneGeneric(int count) { - _places = new T[count]; + _maxCount = count; + _places = new List(); } public int Insert(T plain) { - int i; - for (i = 0; i < Count; i++) - { - if (_places[i] == null) - { - for (int j = i; j >= 1; j--) - { - _places[j] = _places[j - 1]; - } - _places[0] = plain; - return i; - } - } + - return -1; + return 1; } - public int Insert(T plain, int position) + public bool Insert(T plain, int position) { - if (position > Count || position < 0) - return -1; - if (_places[position] == null) - { - _places[position] = plain; - return position; - } - else - { - for (int i = position; i < Count; i++) - { - if (_places[i] == null) - { - for (int j = i; j >= position + 1; j--) - { - _places[j] = _places[j - 1]; - } - _places[position] = plain; - return position; - } - } - } - return -1; + + return true; } public T Remove(int position) { - T mid; - if (_places[position] != null && position < _places.Length) - { - mid = _places[position]; - _places[position] = null; - return mid; - - } - else - return null; - } - public T Get(int position) - { + return _places[position]; } + public T this[int position] + { + get + { + + return _places[position]; + } + set + { + + } + } + public IEnumerable GetPlains() + { + foreach (var plain in _places) + { + if (plain != null) + yield return plain; + else + yield break; + } + } } } -- 2.25.1 From d26269fb7916f4322aae450ae2d720667b74cc5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Mon, 10 Oct 2022 19:32:17 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=81=D0=BB=D0=BE=D0=B2=D0=B0=D1=80=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirPlaneWithRadar/MapsCollection.cs | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs new file mode 100644 index 0000000..0dfb5ea --- /dev/null +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirPlaneWithRadar +{ + 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) + { + + + } + + public void DelMap(string name) + { + + } + + public MapWithSetPlainGeneric this[string ind] + { + get + { + + + return _mapStorages[ind]; + } + } + } +} -- 2.25.1 From 18c877f93b500707398b25f01cb87f7f030d1661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Mon, 10 Oct 2022 19:39:08 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetPlains.Designer.cs | 123 +++++++++++++----- .../AirPlaneWithRadar/FormMapWithSetPlains.cs | 100 +++++++++----- 2 files changed, 162 insertions(+), 61 deletions(-) diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs index 4b19b7f..8389521 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { 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.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.buttonRemovePlain = new System.Windows.Forms.Button(); this.buttonShowStorage = new System.Windows.Forms.Button(); @@ -38,14 +44,15 @@ this.buttonUp = new System.Windows.Forms.Button(); this.buttonShowOnMap = new System.Windows.Forms.Button(); this.buttonAddPlain = new System.Windows.Forms.Button(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.pictureBox = new System.Windows.Forms.PictureBox(); this.groupBoxTools.SuspendLayout(); + this.groupBoxMaps.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit(); this.SuspendLayout(); // // groupBoxTools // + this.groupBoxTools.Controls.Add(this.groupBoxMaps); this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition); this.groupBoxTools.Controls.Add(this.buttonRemovePlain); this.groupBoxTools.Controls.Add(this.buttonShowStorage); @@ -55,27 +62,88 @@ this.groupBoxTools.Controls.Add(this.buttonUp); this.groupBoxTools.Controls.Add(this.buttonShowOnMap); this.groupBoxTools.Controls.Add(this.buttonAddPlain); - this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(1057, 0); + this.groupBoxTools.Location = new System.Drawing.Point(811, 0); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(204, 668); + this.groupBoxTools.Size = new System.Drawing.Size(204, 632); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Инструменты"; // + // 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(192, 248); + this.groupBoxMaps.TabIndex = 0; + this.groupBoxMaps.TabStop = false; + this.groupBoxMaps.Text = "Карты"; + // + // buttonAddMap + // + this.buttonAddMap.Location = new System.Drawing.Point(11, 80); + this.buttonAddMap.Name = "buttonAddMap"; + this.buttonAddMap.Size = new System.Drawing.Size(175, 35); + 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(11, 206); + this.buttonDeleteMap.Name = "buttonDeleteMap"; + this.buttonDeleteMap.Size = new System.Drawing.Size(175, 35); + 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 = 15; + this.listBoxMaps.Location = new System.Drawing.Point(11, 121); + this.listBoxMaps.Name = "listBoxMaps"; + this.listBoxMaps.Size = new System.Drawing.Size(175, 79); + this.listBoxMaps.TabIndex = 3; + this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged); + // + // textBoxNewMapName + // + this.textBoxNewMapName.Location = new System.Drawing.Point(11, 22); + this.textBoxNewMapName.Name = "textBoxNewMapName"; + this.textBoxNewMapName.Size = new System.Drawing.Size(175, 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(11, 51); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23); + this.comboBoxSelectorMap.TabIndex = 1; + // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 166); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 355); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 27); + this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23); this.maskedTextBoxPosition.TabIndex = 2; this.maskedTextBoxPosition.ValidatingType = typeof(int); // // buttonRemovePlain // - this.buttonRemovePlain.Location = new System.Drawing.Point(17, 195); + this.buttonRemovePlain.Location = new System.Drawing.Point(17, 384); this.buttonRemovePlain.Name = "buttonRemovePlain"; this.buttonRemovePlain.Size = new System.Drawing.Size(175, 35); this.buttonRemovePlain.TabIndex = 3; @@ -85,7 +153,7 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(17, 287); + this.buttonShowStorage.Location = new System.Drawing.Point(17, 437); this.buttonShowStorage.Name = "buttonShowStorage"; this.buttonShowStorage.Size = new System.Drawing.Size(175, 35); this.buttonShowStorage.TabIndex = 4; @@ -98,7 +166,7 @@ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonDown.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.down; this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonDown.Location = new System.Drawing.Point(91, 618); + this.buttonDown.Location = new System.Drawing.Point(91, 582); this.buttonDown.Name = "buttonDown"; this.buttonDown.Size = new System.Drawing.Size(30, 30); this.buttonDown.TabIndex = 10; @@ -110,7 +178,7 @@ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonRight.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.right; this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonRight.Location = new System.Drawing.Point(127, 618); + this.buttonRight.Location = new System.Drawing.Point(127, 582); this.buttonRight.Name = "buttonRight"; this.buttonRight.Size = new System.Drawing.Size(30, 30); this.buttonRight.TabIndex = 9; @@ -122,7 +190,7 @@ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonLeft.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.left; this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonLeft.Location = new System.Drawing.Point(55, 618); + this.buttonLeft.Location = new System.Drawing.Point(55, 582); this.buttonLeft.Name = "buttonLeft"; this.buttonLeft.Size = new System.Drawing.Size(30, 30); this.buttonLeft.TabIndex = 8; @@ -134,7 +202,7 @@ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.buttonUp.BackgroundImage = global::AirPlaneWithRadar.Properties.Resources.up; this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.buttonUp.Location = new System.Drawing.Point(91, 582); + this.buttonUp.Location = new System.Drawing.Point(91, 546); this.buttonUp.Name = "buttonUp"; this.buttonUp.Size = new System.Drawing.Size(30, 30); this.buttonUp.TabIndex = 7; @@ -143,7 +211,7 @@ // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(17, 391); + this.buttonShowOnMap.Location = new System.Drawing.Point(17, 487); this.buttonShowOnMap.Name = "buttonShowOnMap"; this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35); this.buttonShowOnMap.TabIndex = 5; @@ -153,7 +221,7 @@ // // buttonAddPlain // - this.buttonAddPlain.Location = new System.Drawing.Point(17, 106); + this.buttonAddPlain.Location = new System.Drawing.Point(17, 314); this.buttonAddPlain.Name = "buttonAddPlain"; this.buttonAddPlain.Size = new System.Drawing.Size(175, 35); this.buttonAddPlain.TabIndex = 1; @@ -161,40 +229,28 @@ this.buttonAddPlain.UseVisualStyleBackColor = true; this.buttonAddPlain.Click += new System.EventHandler(this.ButtonAddPlain_Click); // - // comboBoxSelectorMap - // - this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.comboBoxSelectorMap.FormattingEnabled = true; - this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта", - "Пользовательская карта №1", - "Пользовательская карта №2"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 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(1057, 668); + this.pictureBox.Size = new System.Drawing.Size(811, 632); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // // FormMapWithSetPlains // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1261, 668); + this.ClientSize = new System.Drawing.Size(1015, 632); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); this.Name = "FormMapWithSetPlains"; this.Text = "Карта с набором объектов"; this.groupBoxTools.ResumeLayout(false); this.groupBoxTools.PerformLayout(); + this.groupBoxMaps.ResumeLayout(false); + this.groupBoxMaps.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); this.ResumeLayout(false); } @@ -212,5 +268,10 @@ private Button buttonShowStorage; private Button buttonRemovePlain; private MaskedTextBox maskedTextBoxPosition; + private GroupBox groupBoxMaps; + private Button buttonDeleteMap; + private ListBox listBoxMaps; + private TextBox textBoxNewMapName; + private Button buttonAddMap; } } \ No newline at end of file diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs index e45d9f6..2febce7 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs @@ -12,41 +12,81 @@ namespace AirPlaneWithRadar { public partial class FormMapWithSetPlains : Form { - private MapWithSetPlainGeneric _mapPlainsCollectionGeneric; + private readonly Dictionary _mapsDict = new() + { + { "Простая карта", new SimpleMap()},{"Карта с большими коробками", new UserMap_BigBox()},{"Карта со стенами", new UserMap_Colums()} + }; + private readonly MapsCollection _mapsCollection; + public FormMapWithSetPlains() { 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 ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) + private void ButtonAddMap_Click(object sender, EventArgs e) { - AbstractMap map = null; - switch (comboBoxSelectorMap.Text) + if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) { - case "Простая карта": - map = new SimpleMap(); - break; - case "Пользовательская карта №1": - map = new UserMap_BigBox(); - break; - case "Пользовательская карта №2": - map = new UserMap_Colums(); - break; + MessageBox.Show("Не все данные заполнены", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; } - if (map != null) + if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text)) { - _mapPlainsCollectionGeneric = new MapWithSetPlainGeneric( - pictureBox.Width, pictureBox.Height, map); + MessageBox.Show("Нет такой карты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; } - else + _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) { - _mapPlainsCollectionGeneric = null; + return; + } + + if (MessageBox.Show($"Удалить карту {listBoxMaps.SelectedItem}?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + ReloadMaps(); } } + private void ButtonAddPlain_Click(object sender, EventArgs e) { - if (_mapPlainsCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -56,10 +96,10 @@ namespace AirPlaneWithRadar { DrawingObjectPlane plain = new(form.SelectedPlain); - if ((_mapPlainsCollectionGeneric + plain) >= 0) + if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + plain) >= 0) { MessageBox.Show("Объект добавлен"); - pictureBox.Image = _mapPlainsCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -69,7 +109,7 @@ namespace AirPlaneWithRadar } private void ButtonRemovePlain_Click(object sender, EventArgs e) { - if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -78,10 +118,10 @@ namespace AirPlaneWithRadar return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if ((_mapPlainsCollectionGeneric - (pos - 1)) != null) + if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - (pos - 1)) != null) { MessageBox.Show("Объект удален"); - pictureBox.Image = _mapPlainsCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -90,23 +130,23 @@ namespace AirPlaneWithRadar } private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapPlainsCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapPlainsCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (_mapPlainsCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } - pictureBox.Image = _mapPlainsCollectionGeneric.ShowOnMap(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } private void ButtonMove_Click(object sender, EventArgs e) { - if (_mapPlainsCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -128,7 +168,7 @@ namespace AirPlaneWithRadar dir = Direction.Right; break; } - pictureBox.Image = _mapPlainsCollectionGeneric.MoveObject(dir); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir); } } -- 2.25.1 From 412fab79a205f3059b3c8fcb179f4ebf852c09da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Mon, 10 Oct 2022 20:23:23 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirPlaneWithRadar/FormMapWithSetPlains.cs | 2 + .../MapWithSetPlainGeneric.cs | 33 +++++--------- .../AirPlaneWithRadar/MapsCollection.cs | 14 ++++-- .../AirPlaneWithRadar/SetPlaneGeneric.cs | 44 +++++++++++++++---- 4 files changed, 59 insertions(+), 34 deletions(-) diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs index 2febce7..8624783 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/FormMapWithSetPlains.cs @@ -117,6 +117,8 @@ namespace AirPlaneWithRadar { return; } + if (maskedTextBoxPosition.Text == null) + return; int pos = Convert.ToInt32(maskedTextBoxPosition.Text); if ((_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - (pos - 1)) != null) { diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs index 457fbe3..37316eb 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapWithSetPlainGeneric.cs @@ -113,44 +113,33 @@ namespace AirPlaneWithRadar } private void DrawPlains(Graphics g) { - - int CountWidth = _pictureWidth / _placeSizeWidth; int x = _pictureWidth - _placeSizeWidth; int y = _placeSizeHeight / 4; - - for (int k = 0; k < _setPlains.Count; k++) + int k = 0; + foreach(var plain in _setPlains.GetPlains()) { - if (_setPlains[k] != null) - { + if ((k + 1) % CountWidth != 0 || k == 0) { - _setPlains[k]?.SetObject(x, y, _pictureWidth, _pictureHeight); - _setPlains[k]?.DrawningObject(g); + plain?.SetObject(x, y, _pictureWidth, _pictureHeight); + plain?.DrawningObject(g); x -= _placeSizeWidth; } else { - _setPlains[k]?.SetObject(x, y, _pictureWidth, _pictureHeight); - _setPlains[k]?.DrawningObject(g); - x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4; + plain?.SetObject(x, y, _pictureWidth, _pictureHeight); + plain?.DrawningObject(g); + x = _pictureWidth - _placeSizeWidth ; y += _placeSizeHeight; } - } - if (_setPlains[k] == null) - { - if ((k + 1) % CountWidth != 0 || k == 0) - x -= _placeSizeWidth; - else - { - x = _pictureWidth - _placeSizeWidth - _placeSizeWidth / 2 - _placeSizeWidth / 4; - y += _placeSizeHeight; - } - } + + k++; } + } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs b/AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs index 0dfb5ea..abbd72a 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/MapsCollection.cs @@ -25,13 +25,19 @@ namespace AirPlaneWithRadar public void AddMap(string name, AbstractMap map) { - + if (_mapStorages.ContainsKey(name)) + return; + Keys.Add(name); + _mapStorages.Add(name, new MapWithSetPlainGeneric(_pictureWidth, _pictureHeight, map)); } public void DelMap(string name) { - + if (!_mapStorages.ContainsKey(name)) + return; + Keys.Remove(name); + _mapStorages.Remove(name); } public MapWithSetPlainGeneric this[string ind] @@ -39,7 +45,9 @@ namespace AirPlaneWithRadar get { - + if (!_mapStorages.ContainsKey(ind)) + return null; + else return _mapStorages[ind]; } } diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs index 4e83bdd..45b9dc2 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs @@ -20,31 +20,57 @@ namespace AirPlaneWithRadar } public int Insert(T plain) { - + if (_places.Count == _maxCount) + { + return -1; + } + _places.Insert(0, plain); - return 1; + return _places.Count; } - public bool Insert(T plain, int position) + public int Insert(T plain, int position) { - - return true; + if (position < 0 || _places.Count < position||position > _maxCount) + return -1; + else if (plain == null) + return -1; + _places.Insert(position, plain); + return position; } public T Remove(int position) { - - return _places[position]; + T mid; + if (position < 0 || _places.Count < position || position > _maxCount) + return null; + else if (_places[position] == null) + return null; + else + { + mid = _places[position]; + _places.RemoveAt(position); + } + return mid; } public T this[int position] { get { - + if (position < 0 || _places.Count < position || position > _maxCount) + return null; + else if (_places[position] == null) + return null; + else return _places[position]; } set { - + if (position < 0 || _places.Count < position || position > _maxCount) + return; + else if (_places.Count == _maxCount) + return; + else + _places[position] = value; } } public IEnumerable GetPlains() -- 2.25.1 From 98421f8d63217e0c6e74183d1dcf33ff7cf6872c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=BE=D0=BB=D0=BE=D0=B4=D1=8F?= Date: Fri, 11 Nov 2022 11:05:26 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0?= =?UTF-8?q?=20=D0=B2=D1=81=D1=82=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B2=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B5=20SetPlaneGeneric?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs index 45b9dc2..291aa24 100644 --- a/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs +++ b/AirPlaneWithRadar/AirPlaneWithRadar/SetPlaneGeneric.cs @@ -20,17 +20,13 @@ namespace AirPlaneWithRadar } public int Insert(T plain) { - if (_places.Count == _maxCount) - { - return -1; - } - _places.Insert(0, plain); - + + Insert(plain, 0); return _places.Count; } public int Insert(T plain, int position) { - if (position < 0 || _places.Count < position||position > _maxCount) + if (position < 0 || _places.Count < position||position > _maxCount || _places.Count == _maxCount) return -1; else if (plain == null) return -1; -- 2.25.1