From 5f2bc387d9070f2c2b96f7563b242e62a4000288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sat, 15 Oct 2022 22:41:24 +0400 Subject: [PATCH 1/4] :( --- .../FormMapWithSetGasolineTanker.Designer.cs | 64 ++++++---- .../MapWithSetGasolienTankerGeneric.cs | 30 ++--- .../GasolineTanker/MapsCollection.cs | 45 +++++++ .../SetGasolineTankerGeneric.cs | 112 +++++++++--------- 4 files changed, 152 insertions(+), 99 deletions(-) create mode 100644 GasolineTanker/GasolineTanker/MapsCollection.cs diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs index 311cc56..f52e3a7 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs @@ -57,19 +57,22 @@ this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker); this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(600, 0); + this.groupBoxTools.Location = new System.Drawing.Point(685, 0); + this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(200, 450); + this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxTools.Size = new System.Drawing.Size(229, 664); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Tools"; // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(10, 113); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(11, 151); + this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - this.maskedTextBoxPosition.Size = new System.Drawing.Size(184, 23); + this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27); this.maskedTextBoxPosition.TabIndex = 11; // // keyRight @@ -77,9 +80,10 @@ this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight; this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyRight.Location = new System.Drawing.Point(122, 408); + this.keyRight.Location = new System.Drawing.Point(139, 608); + this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyRight.Name = "keyRight"; - this.keyRight.Size = new System.Drawing.Size(30, 30); + this.keyRight.Size = new System.Drawing.Size(34, 40); this.keyRight.TabIndex = 10; this.keyRight.UseVisualStyleBackColor = true; this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); @@ -89,9 +93,10 @@ this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft; this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyLeft.Location = new System.Drawing.Point(50, 408); + this.keyLeft.Location = new System.Drawing.Point(57, 608); + this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyLeft.Name = "keyLeft"; - this.keyLeft.Size = new System.Drawing.Size(30, 30); + this.keyLeft.Size = new System.Drawing.Size(34, 40); this.keyLeft.TabIndex = 9; this.keyLeft.UseVisualStyleBackColor = true; this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); @@ -101,9 +106,10 @@ this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp; this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyUp.Location = new System.Drawing.Point(86, 372); + this.keyUp.Location = new System.Drawing.Point(98, 560); + this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyUp.Name = "keyUp"; - this.keyUp.Size = new System.Drawing.Size(30, 30); + this.keyUp.Size = new System.Drawing.Size(34, 40); this.keyUp.TabIndex = 8; this.keyUp.UseVisualStyleBackColor = true; this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); @@ -113,18 +119,20 @@ this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown; this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyDown.Location = new System.Drawing.Point(86, 408); + this.keyDown.Location = new System.Drawing.Point(98, 608); + this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyDown.Name = "keyDown"; - this.keyDown.Size = new System.Drawing.Size(30, 30); + this.keyDown.Size = new System.Drawing.Size(34, 40); this.keyDown.TabIndex = 7; this.keyDown.UseVisualStyleBackColor = true; this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(8, 326); + this.buttonShowOnMap.Location = new System.Drawing.Point(9, 435); + this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowOnMap.Name = "buttonShowOnMap"; - this.buttonShowOnMap.Size = new System.Drawing.Size(186, 34); + this.buttonShowOnMap.Size = new System.Drawing.Size(213, 45); this.buttonShowOnMap.TabIndex = 4; this.buttonShowOnMap.Text = "Show on map"; this.buttonShowOnMap.UseVisualStyleBackColor = true; @@ -132,9 +140,10 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(8, 241); + this.buttonShowStorage.Location = new System.Drawing.Point(9, 321); + this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowStorage.Name = "buttonShowStorage"; - this.buttonShowStorage.Size = new System.Drawing.Size(186, 34); + this.buttonShowStorage.Size = new System.Drawing.Size(213, 45); this.buttonShowStorage.TabIndex = 3; this.buttonShowStorage.Text = "Show storage"; this.buttonShowStorage.UseVisualStyleBackColor = true; @@ -142,9 +151,10 @@ // // buttonRemoveGasolineTanker // - this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(10, 142); + this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(11, 189); + this.buttonRemoveGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonRemoveGasolineTanker.Name = "buttonRemoveGasolineTanker"; - this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(186, 34); + this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(213, 45); this.buttonRemoveGasolineTanker.TabIndex = 2; this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker"; this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true; @@ -152,9 +162,10 @@ // // buttonAddGasolineTanker // - this.buttonAddGasolineTanker.Location = new System.Drawing.Point(8, 73); + this.buttonAddGasolineTanker.Location = new System.Drawing.Point(9, 97); + this.buttonAddGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonAddGasolineTanker.Name = "buttonAddGasolineTanker"; - this.buttonAddGasolineTanker.Size = new System.Drawing.Size(186, 34); + this.buttonAddGasolineTanker.Size = new System.Drawing.Size(213, 45); this.buttonAddGasolineTanker.TabIndex = 1; this.buttonAddGasolineTanker.Text = "Add gasoline tanker"; this.buttonAddGasolineTanker.UseVisualStyleBackColor = true; @@ -165,9 +176,10 @@ this.comboBoxSelectorMap.Items.AddRange(new object[] { "Simple map", "Long map"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 22); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 29); + this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(188, 23); + this.comboBoxSelectorMap.Size = new System.Drawing.Size(214, 28); this.comboBoxSelectorMap.TabIndex = 12; this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); // @@ -175,18 +187,20 @@ // this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Location = new System.Drawing.Point(0, 0); + this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(600, 450); + this.pictureBox.Size = new System.Drawing.Size(685, 664); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // // FormMapWithSetGasolineTanker // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); + this.ClientSize = new System.Drawing.Size(914, 664); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormMapWithSetGasolineTanker"; this.Text = "FormMapWithSetGasolineTanker"; this.groupBoxTools.ResumeLayout(false); diff --git a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs index f25a19d..ba46416 100644 --- a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs @@ -49,13 +49,11 @@ namespace GasolineTanker public Bitmap ShowOnMap() { Shaking(); - for (int i = 0; i < _setGasolineTanker.Count; i++) + foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker()) { - var gasolineTanker = _setGasolineTanker.Get(i); - if (gasolineTanker != null) - { - return _map.CreateMap(_pictureWidth, _pictureHeight, gasolineTanker); - } + + return _map.CreateMap(_pictureWidth, _pictureHeight, gasolineTanker); + } return new(_pictureWidth, _pictureHeight); } @@ -74,11 +72,11 @@ namespace GasolineTanker int j = _setGasolineTanker.Count - 1; for (int i = 0; i < _setGasolineTanker.Count; i++) { - if (_setGasolineTanker.Get(i) == null) + if (_setGasolineTanker[i] == null) { for (; j > i; j--) { - var gasolineTanker = _setGasolineTanker.Get(j); + var gasolineTanker = _setGasolineTanker[j]; if (gasolineTanker != null) { _setGasolineTanker.Insert(gasolineTanker, i); @@ -110,15 +108,17 @@ namespace GasolineTanker private void DrawGasolineTanker(Graphics g) { - int width = _pictureWidth / _placeSizeWidth; - int height = _pictureHeight / _placeSizeHeight; - - for (int i = 0; i < _setGasolineTanker.Count; i++) + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker()) { - if (_setGasolineTanker.Get(i) != null) + gasolineTanker.SetObject(width, height, _pictureWidth, _pictureHeight); + gasolineTanker.DrawningObject(g); + width += _placeSizeWidth; + if (width > _pictureWidth - _placeSizeWidth) { - _setGasolineTanker.Get(i).SetObject(i % width * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); - _setGasolineTanker.Get(i)?.DrawningObject(g); + width = _placeSizeWidth / 10; + height += _placeSizeHeight; } } } diff --git a/GasolineTanker/GasolineTanker/MapsCollection.cs b/GasolineTanker/GasolineTanker/MapsCollection.cs new file mode 100644 index 0000000..473b2bc --- /dev/null +++ b/GasolineTanker/GasolineTanker/MapsCollection.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace GasolineTanker +{ + 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 MapWithSetGasolienTankerGeneric(_pictureWidth, _pictureHeight, map)); + } + + public void DelMap(string name) + { + _mapStorages.Remove(name); + } + + public MapWithSetGasolienTankerGeneric this[string ind] + { + get + { + if (_mapStorages.TryGetValue(ind, out var map)) return map; + return null; + } + } + } +} diff --git a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs index c546fa5..e6a5ae0 100644 --- a/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/SetGasolineTankerGeneric.cs @@ -9,72 +9,66 @@ namespace GasolineTanker internal class SetGasolineTankerGeneric 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 SetGasolineTankerGeneric(int count) { - _places = new T[count]; + _maxCount = count; + _places = new List(); } public int Insert(T gasolineTanker) { - if (_places[Count - 1] == null) - { - for (int i = Count - 1; i > 0; i--) - { - _places[i] = _places[i - 1]; - } - _places[0] = gasolineTanker; - return 0; - } - return -1; - } + if (_places.Count < _maxCount) + { + _places.Add(gasolineTanker); + for (int i = 0; i < _places.Count; i++) + { + if (_places[i] == gasolineTanker) return i; + } + } + return -1; + } public int Insert(T gasolineTanker, int position) { - if (position < 0 || position >= Count) return -1; - if (_places[position] == null) - { - _places[position] = gasolineTanker; - return position; - } - else - { - if (_places[Count - 1] == null) - { - for (int i = Count - 1; i > position; i--) - { - _places[i] = _places[i - 1]; - } - _places[position] = gasolineTanker; - return position; - } - return -1; - } - } + if (position < 0 || position >= _places.Count) return -1; + _places.Insert(position, gasolineTanker); + return position; + } public T Remove(int position) { - if (position < 0 || position >= Count) - return null; - if (_places[position] != null) - { - T removed = _places[position]; - _places[position] = null; - if (position < Count - 1) - { - for (int k = position; k < Count - 1; k++) - { - _places[k] = _places[k + 1]; - } - } - return removed; - } - return null; - } - public T Get(int position) - { - if (position >= Count || position < 0) - return null; - - return _places[position]; - } - } + if (position < 0 || position >= _places.Count) return null; + if (_places[position] == null) return null; + T removed = _places[position]; + _places.RemoveAt(position); + return removed; + } + public T this[int position] + { + get + { + if (position < 0 || position >= _places.Count) return null; + return _places[position]; + } + set + { + if (position < 0 || position >= _places.Count) return; + _places.Insert(position, value); + } + } + public IEnumerable GetGasolineTanker() + { + foreach (var gasolineTanker in _places) + { + if (gasolineTanker != null) + { + yield return gasolineTanker; + } + else + { + yield break; + } + } + } + } } -- 2.25.1 From 8bd7a3ee39164ef269967481f42803891efb730e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Sun, 16 Oct 2022 21:36:34 +0400 Subject: [PATCH 2/4] :) --- .../FormMapWithSetGasolineTanker.Designer.cs | 153 ++++++++++++------ .../FormMapWithSetGasolineTanker.cs | 114 +++++++++---- .../MapWithSetGasolienTankerGeneric.cs | 4 +- 3 files changed, 188 insertions(+), 83 deletions(-) diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs index f52e3a7..9e65eb2 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs @@ -29,6 +29,12 @@ private void InitializeComponent() { this.groupBoxTools = new System.Windows.Forms.GroupBox(); + this.groupBoxMaps = 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.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); this.keyRight = new System.Windows.Forms.Button(); this.keyLeft = new System.Windows.Forms.Button(); @@ -38,14 +44,15 @@ this.buttonShowStorage = new System.Windows.Forms.Button(); this.buttonRemoveGasolineTanker = new System.Windows.Forms.Button(); this.buttonAddGasolineTanker = 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.keyRight); this.groupBoxTools.Controls.Add(this.keyLeft); @@ -55,24 +62,84 @@ this.groupBoxTools.Controls.Add(this.buttonShowStorage); this.groupBoxTools.Controls.Add(this.buttonRemoveGasolineTanker); this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker); - this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(685, 0); - this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxTools.Location = new System.Drawing.Point(694, 0); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.groupBoxTools.Size = new System.Drawing.Size(229, 664); + this.groupBoxTools.Size = new System.Drawing.Size(200, 629); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Tools"; // + // groupBoxMaps + // + this.groupBoxMaps.Controls.Add(this.buttonDeleteMap); + this.groupBoxMaps.Controls.Add(this.listBoxMaps); + this.groupBoxMaps.Controls.Add(this.buttonAddMap); + this.groupBoxMaps.Controls.Add(this.textBoxNewMapName); + this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); + this.groupBoxMaps.Location = new System.Drawing.Point(6, 22); + this.groupBoxMaps.Name = "groupBoxMaps"; + this.groupBoxMaps.Size = new System.Drawing.Size(190, 305); + this.groupBoxMaps.TabIndex = 13; + this.groupBoxMaps.TabStop = false; + this.groupBoxMaps.Text = "Maps"; + // + // buttonDeleteMap + // + this.buttonDeleteMap.Location = new System.Drawing.Point(6, 241); + this.buttonDeleteMap.Name = "buttonDeleteMap"; + this.buttonDeleteMap.Size = new System.Drawing.Size(175, 49); + this.buttonDeleteMap.TabIndex = 16; + 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(6, 141); + this.listBoxMaps.Name = "listBoxMaps"; + this.listBoxMaps.Size = new System.Drawing.Size(176, 94); + this.listBoxMaps.TabIndex = 15; + this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged); + // + // buttonAddMap + // + this.buttonAddMap.Location = new System.Drawing.Point(6, 84); + this.buttonAddMap.Name = "buttonAddMap"; + this.buttonAddMap.Size = new System.Drawing.Size(176, 51); + this.buttonAddMap.TabIndex = 14; + 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, 24); + this.textBoxNewMapName.Name = "textBoxNewMapName"; + this.textBoxNewMapName.Size = new System.Drawing.Size(178, 23); + this.textBoxNewMapName.TabIndex = 13; + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Simple map", + "Long map"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 53); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(178, 23); + this.comboBoxSelectorMap.TabIndex = 12; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); + // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(11, 151); - this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(10, 391); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27); + this.maskedTextBoxPosition.Size = new System.Drawing.Size(184, 23); this.maskedTextBoxPosition.TabIndex = 11; // // keyRight @@ -80,10 +147,9 @@ this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight; this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyRight.Location = new System.Drawing.Point(139, 608); - this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyRight.Location = new System.Drawing.Point(122, 587); this.keyRight.Name = "keyRight"; - this.keyRight.Size = new System.Drawing.Size(34, 40); + this.keyRight.Size = new System.Drawing.Size(30, 30); this.keyRight.TabIndex = 10; this.keyRight.UseVisualStyleBackColor = true; this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); @@ -93,10 +159,9 @@ this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft; this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyLeft.Location = new System.Drawing.Point(57, 608); - this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyLeft.Location = new System.Drawing.Point(50, 587); this.keyLeft.Name = "keyLeft"; - this.keyLeft.Size = new System.Drawing.Size(34, 40); + this.keyLeft.Size = new System.Drawing.Size(30, 30); this.keyLeft.TabIndex = 9; this.keyLeft.UseVisualStyleBackColor = true; this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); @@ -106,10 +171,9 @@ this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp; this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyUp.Location = new System.Drawing.Point(98, 560); - this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyUp.Location = new System.Drawing.Point(86, 551); this.keyUp.Name = "keyUp"; - this.keyUp.Size = new System.Drawing.Size(34, 40); + this.keyUp.Size = new System.Drawing.Size(30, 30); this.keyUp.TabIndex = 8; this.keyUp.UseVisualStyleBackColor = true; this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); @@ -119,20 +183,18 @@ this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown; this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyDown.Location = new System.Drawing.Point(98, 608); - this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.keyDown.Location = new System.Drawing.Point(86, 587); this.keyDown.Name = "keyDown"; - this.keyDown.Size = new System.Drawing.Size(34, 40); + this.keyDown.Size = new System.Drawing.Size(30, 30); this.keyDown.TabIndex = 7; this.keyDown.UseVisualStyleBackColor = true; this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(9, 435); - this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonShowOnMap.Location = new System.Drawing.Point(8, 500); this.buttonShowOnMap.Name = "buttonShowOnMap"; - this.buttonShowOnMap.Size = new System.Drawing.Size(213, 45); + this.buttonShowOnMap.Size = new System.Drawing.Size(186, 34); this.buttonShowOnMap.TabIndex = 4; this.buttonShowOnMap.Text = "Show on map"; this.buttonShowOnMap.UseVisualStyleBackColor = true; @@ -140,10 +202,9 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(9, 321); - this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonShowStorage.Location = new System.Drawing.Point(8, 460); this.buttonShowStorage.Name = "buttonShowStorage"; - this.buttonShowStorage.Size = new System.Drawing.Size(213, 45); + this.buttonShowStorage.Size = new System.Drawing.Size(186, 34); this.buttonShowStorage.TabIndex = 3; this.buttonShowStorage.Text = "Show storage"; this.buttonShowStorage.UseVisualStyleBackColor = true; @@ -151,60 +212,45 @@ // // buttonRemoveGasolineTanker // - this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(11, 189); - this.buttonRemoveGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(8, 420); this.buttonRemoveGasolineTanker.Name = "buttonRemoveGasolineTanker"; - this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(213, 45); + this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(186, 34); this.buttonRemoveGasolineTanker.TabIndex = 2; this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker"; this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true; - this.buttonRemoveGasolineTanker.Click += new System.EventHandler(this.ButtonRemoveGasolineTanker_Click); // // buttonAddGasolineTanker // - this.buttonAddGasolineTanker.Location = new System.Drawing.Point(9, 97); - this.buttonAddGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.buttonAddGasolineTanker.Location = new System.Drawing.Point(10, 351); this.buttonAddGasolineTanker.Name = "buttonAddGasolineTanker"; - this.buttonAddGasolineTanker.Size = new System.Drawing.Size(213, 45); + this.buttonAddGasolineTanker.Size = new System.Drawing.Size(186, 34); this.buttonAddGasolineTanker.TabIndex = 1; this.buttonAddGasolineTanker.Text = "Add gasoline tanker"; this.buttonAddGasolineTanker.UseVisualStyleBackColor = true; this.buttonAddGasolineTanker.Click += new System.EventHandler(this.ButtonAddGasolineTanker_Click); // - // comboBoxSelectorMap - // - this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Simple map", - "Long map"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 29); - this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); - this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(214, 28); - this.comboBoxSelectorMap.TabIndex = 12; - 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(685, 664); + this.pictureBox.Size = new System.Drawing.Size(694, 629); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // // FormMapWithSetGasolineTanker // - 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(914, 664); + this.ClientSize = new System.Drawing.Size(894, 629); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); - this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormMapWithSetGasolineTanker"; this.Text = "FormMapWithSetGasolineTanker"; this.groupBoxTools.ResumeLayout(false); this.groupBoxTools.PerformLayout(); + this.groupBoxMaps.ResumeLayout(false); + this.groupBoxMaps.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit(); this.ResumeLayout(false); @@ -224,5 +270,10 @@ private Button keyUp; private Button keyDown; private MaskedTextBox maskedTextBoxPosition; + private GroupBox groupBoxMaps; + private Button buttonAddMap; + private TextBox textBoxNewMapName; + private Button buttonDeleteMap; + private ListBox listBoxMaps; } } \ No newline at end of file diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs index e7b9072..9fa2688 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs @@ -12,25 +12,67 @@ namespace GasolineTanker { public partial class FormMapWithSetGasolineTanker : Form { + private readonly Dictionary _mapsDict = new() + { + { "Simple map", new SimpleMap() }, + { "Long map", new LongMap() } + }; private MapWithSetGasolienTankerGeneric _mapGasolineTankerCollectionGeneric; + private readonly MapsCollection _mapsCollection; public FormMapWithSetGasolineTanker() { 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 ButtonDeleteMap_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + ReloadMaps(); + } + } private void ButtonAddGasolineTanker_Click(object sender, EventArgs e) { - if (_mapGasolineTankerCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } FormGasolineTanker form = new(); if (form.ShowDialog() == DialogResult.OK) { - DrawingObjectGasolineTanker GasolineTanker = new(form.SelectedGasolineTanker); - if (_mapGasolineTankerCollectionGeneric + GasolineTanker >= 0) + DrawingObjectGasolineTanker antiAircraftGun = new(form.SelectedGasolineTanker); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + antiAircraftGun >= 0) { MessageBox.Show("Object added"); - pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } else { @@ -39,31 +81,9 @@ namespace GasolineTanker } } - private void ButtonRemoveGasolineTanker_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) - { - return; - } - if (MessageBox.Show("Delete object?", "Removal", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) - { - return; - } - int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapGasolineTankerCollectionGeneric - pos != null) - { - MessageBox.Show("Object deleted"); - pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowSet(); - } - else - { - MessageBox.Show("Failed to delete object"); - } - } - private void ButtonShowStorage_Click(object sender, EventArgs e) { - if (_mapGasolineTankerCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -72,7 +92,7 @@ namespace GasolineTanker private void ButtonShowOnMap_Click(object sender, EventArgs e) { - if (_mapGasolineTankerCollectionGeneric == null) + if(listBoxMaps.SelectedIndex == -1) { return; } @@ -80,7 +100,7 @@ namespace GasolineTanker } private void ButtonMove_Click(object sender, EventArgs e) { - if (_mapGasolineTankerCollectionGeneric == null) + if (listBoxMaps.SelectedIndex == -1) { return; } @@ -127,5 +147,39 @@ namespace GasolineTanker _mapGasolineTankerCollectionGeneric = null; } } + + private void buttonAddMap_Click(object sender, EventArgs e) + { + if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text)) + { + MessageBox.Show("Not all data saved", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text)) + { + MessageBox.Show("No such card", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]); + ReloadMaps(); + } + + private void buttonDeleteMap_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + if (MessageBox.Show($"Delete map {listBoxMaps.SelectedItem}?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty); + ReloadMaps(); + } + } + + private void listBoxMaps_SelectedIndexChanged(object sender, EventArgs e) + { + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } } } diff --git a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs index ba46416..fe0cb2f 100644 --- a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs @@ -117,8 +117,8 @@ namespace GasolineTanker width += _placeSizeWidth; if (width > _pictureWidth - _placeSizeWidth) { - width = _placeSizeWidth / 10; - height += _placeSizeHeight; + width = _pictureWidth / _placeSizeWidth; + height -= _placeSizeHeight; } } } -- 2.25.1 From 74ae24d23ba68d30c3e2f0f8b51428cf92e45b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Wed, 19 Oct 2022 09:03:11 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetGasolineTanker.Designer.cs | 93 ++++++++++++------- .../FormMapWithSetGasolineTanker.cs | 28 +++++- .../MapWithSetGasolienTankerGeneric.cs | 15 ++- 3 files changed, 90 insertions(+), 46 deletions(-) diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs index 9e65eb2..ac96937 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.Designer.cs @@ -63,9 +63,11 @@ this.groupBoxTools.Controls.Add(this.buttonRemoveGasolineTanker); this.groupBoxTools.Controls.Add(this.buttonAddGasolineTanker); this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right; - this.groupBoxTools.Location = new System.Drawing.Point(694, 0); + this.groupBoxTools.Location = new System.Drawing.Point(793, 0); + this.groupBoxTools.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBoxTools.Name = "groupBoxTools"; - this.groupBoxTools.Size = new System.Drawing.Size(200, 629); + this.groupBoxTools.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxTools.Size = new System.Drawing.Size(229, 839); this.groupBoxTools.TabIndex = 0; this.groupBoxTools.TabStop = false; this.groupBoxTools.Text = "Tools"; @@ -77,18 +79,21 @@ this.groupBoxMaps.Controls.Add(this.buttonAddMap); this.groupBoxMaps.Controls.Add(this.textBoxNewMapName); this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap); - this.groupBoxMaps.Location = new System.Drawing.Point(6, 22); + this.groupBoxMaps.Location = new System.Drawing.Point(7, 29); + this.groupBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.groupBoxMaps.Name = "groupBoxMaps"; - this.groupBoxMaps.Size = new System.Drawing.Size(190, 305); + this.groupBoxMaps.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4); + this.groupBoxMaps.Size = new System.Drawing.Size(217, 407); this.groupBoxMaps.TabIndex = 13; this.groupBoxMaps.TabStop = false; this.groupBoxMaps.Text = "Maps"; // // buttonDeleteMap // - this.buttonDeleteMap.Location = new System.Drawing.Point(6, 241); + this.buttonDeleteMap.Location = new System.Drawing.Point(7, 321); + this.buttonDeleteMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonDeleteMap.Name = "buttonDeleteMap"; - this.buttonDeleteMap.Size = new System.Drawing.Size(175, 49); + this.buttonDeleteMap.Size = new System.Drawing.Size(200, 65); this.buttonDeleteMap.TabIndex = 16; this.buttonDeleteMap.Text = "Delete Map"; this.buttonDeleteMap.UseVisualStyleBackColor = true; @@ -97,18 +102,20 @@ // listBoxMaps // this.listBoxMaps.FormattingEnabled = true; - this.listBoxMaps.ItemHeight = 15; - this.listBoxMaps.Location = new System.Drawing.Point(6, 141); + this.listBoxMaps.ItemHeight = 20; + this.listBoxMaps.Location = new System.Drawing.Point(7, 188); + this.listBoxMaps.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.listBoxMaps.Name = "listBoxMaps"; - this.listBoxMaps.Size = new System.Drawing.Size(176, 94); + this.listBoxMaps.Size = new System.Drawing.Size(201, 124); this.listBoxMaps.TabIndex = 15; this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.listBoxMaps_SelectedIndexChanged); // // buttonAddMap // - this.buttonAddMap.Location = new System.Drawing.Point(6, 84); + this.buttonAddMap.Location = new System.Drawing.Point(7, 112); + this.buttonAddMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonAddMap.Name = "buttonAddMap"; - this.buttonAddMap.Size = new System.Drawing.Size(176, 51); + this.buttonAddMap.Size = new System.Drawing.Size(201, 68); this.buttonAddMap.TabIndex = 14; this.buttonAddMap.Text = "Add Map"; this.buttonAddMap.UseVisualStyleBackColor = true; @@ -116,9 +123,10 @@ // // textBoxNewMapName // - this.textBoxNewMapName.Location = new System.Drawing.Point(6, 24); + this.textBoxNewMapName.Location = new System.Drawing.Point(7, 32); + this.textBoxNewMapName.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.textBoxNewMapName.Name = "textBoxNewMapName"; - this.textBoxNewMapName.Size = new System.Drawing.Size(178, 23); + this.textBoxNewMapName.Size = new System.Drawing.Size(203, 27); this.textBoxNewMapName.TabIndex = 13; // // comboBoxSelectorMap @@ -128,18 +136,20 @@ this.comboBoxSelectorMap.Items.AddRange(new object[] { "Simple map", "Long map"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(6, 53); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(7, 71); + this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(178, 23); + this.comboBoxSelectorMap.Size = new System.Drawing.Size(203, 28); this.comboBoxSelectorMap.TabIndex = 12; this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged); // // maskedTextBoxPosition // - this.maskedTextBoxPosition.Location = new System.Drawing.Point(10, 391); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(11, 521); + this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.maskedTextBoxPosition.Mask = "00"; this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; - this.maskedTextBoxPosition.Size = new System.Drawing.Size(184, 23); + this.maskedTextBoxPosition.Size = new System.Drawing.Size(210, 27); this.maskedTextBoxPosition.TabIndex = 11; // // keyRight @@ -147,9 +157,10 @@ this.keyRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyRight.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyRight; this.keyRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyRight.Location = new System.Drawing.Point(122, 587); + this.keyRight.Location = new System.Drawing.Point(139, 783); + this.keyRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyRight.Name = "keyRight"; - this.keyRight.Size = new System.Drawing.Size(30, 30); + this.keyRight.Size = new System.Drawing.Size(34, 40); this.keyRight.TabIndex = 10; this.keyRight.UseVisualStyleBackColor = true; this.keyRight.Click += new System.EventHandler(this.ButtonMove_Click); @@ -159,9 +170,10 @@ this.keyLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyLeft.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyLeft; this.keyLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyLeft.Location = new System.Drawing.Point(50, 587); + this.keyLeft.Location = new System.Drawing.Point(57, 783); + this.keyLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyLeft.Name = "keyLeft"; - this.keyLeft.Size = new System.Drawing.Size(30, 30); + this.keyLeft.Size = new System.Drawing.Size(34, 40); this.keyLeft.TabIndex = 9; this.keyLeft.UseVisualStyleBackColor = true; this.keyLeft.Click += new System.EventHandler(this.ButtonMove_Click); @@ -171,9 +183,10 @@ this.keyUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyUp.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyUp; this.keyUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyUp.Location = new System.Drawing.Point(86, 551); + this.keyUp.Location = new System.Drawing.Point(98, 735); + this.keyUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyUp.Name = "keyUp"; - this.keyUp.Size = new System.Drawing.Size(30, 30); + this.keyUp.Size = new System.Drawing.Size(34, 40); this.keyUp.TabIndex = 8; this.keyUp.UseVisualStyleBackColor = true; this.keyUp.Click += new System.EventHandler(this.ButtonMove_Click); @@ -183,18 +196,20 @@ this.keyDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.keyDown.BackgroundImage = global::GasolineTanker.Properties.Resources.KeyDown; this.keyDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch; - this.keyDown.Location = new System.Drawing.Point(86, 587); + this.keyDown.Location = new System.Drawing.Point(98, 783); + this.keyDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.keyDown.Name = "keyDown"; - this.keyDown.Size = new System.Drawing.Size(30, 30); + this.keyDown.Size = new System.Drawing.Size(34, 40); this.keyDown.TabIndex = 7; this.keyDown.UseVisualStyleBackColor = true; this.keyDown.Click += new System.EventHandler(this.ButtonMove_Click); // // buttonShowOnMap // - this.buttonShowOnMap.Location = new System.Drawing.Point(8, 500); + this.buttonShowOnMap.Location = new System.Drawing.Point(9, 667); + this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowOnMap.Name = "buttonShowOnMap"; - this.buttonShowOnMap.Size = new System.Drawing.Size(186, 34); + this.buttonShowOnMap.Size = new System.Drawing.Size(213, 45); this.buttonShowOnMap.TabIndex = 4; this.buttonShowOnMap.Text = "Show on map"; this.buttonShowOnMap.UseVisualStyleBackColor = true; @@ -202,9 +217,10 @@ // // buttonShowStorage // - this.buttonShowStorage.Location = new System.Drawing.Point(8, 460); + this.buttonShowStorage.Location = new System.Drawing.Point(9, 613); + this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonShowStorage.Name = "buttonShowStorage"; - this.buttonShowStorage.Size = new System.Drawing.Size(186, 34); + this.buttonShowStorage.Size = new System.Drawing.Size(213, 45); this.buttonShowStorage.TabIndex = 3; this.buttonShowStorage.Text = "Show storage"; this.buttonShowStorage.UseVisualStyleBackColor = true; @@ -212,18 +228,21 @@ // // buttonRemoveGasolineTanker // - this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(8, 420); + this.buttonRemoveGasolineTanker.Location = new System.Drawing.Point(9, 560); + this.buttonRemoveGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonRemoveGasolineTanker.Name = "buttonRemoveGasolineTanker"; - this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(186, 34); + this.buttonRemoveGasolineTanker.Size = new System.Drawing.Size(213, 45); this.buttonRemoveGasolineTanker.TabIndex = 2; this.buttonRemoveGasolineTanker.Text = "Remove gasoline tanker"; this.buttonRemoveGasolineTanker.UseVisualStyleBackColor = true; + this.buttonRemoveGasolineTanker.Click += new System.EventHandler(this.buttonRemoveGasolineTanker_Click); // // buttonAddGasolineTanker // - this.buttonAddGasolineTanker.Location = new System.Drawing.Point(10, 351); + this.buttonAddGasolineTanker.Location = new System.Drawing.Point(11, 468); + this.buttonAddGasolineTanker.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.buttonAddGasolineTanker.Name = "buttonAddGasolineTanker"; - this.buttonAddGasolineTanker.Size = new System.Drawing.Size(186, 34); + this.buttonAddGasolineTanker.Size = new System.Drawing.Size(213, 45); this.buttonAddGasolineTanker.TabIndex = 1; this.buttonAddGasolineTanker.Text = "Add gasoline tanker"; this.buttonAddGasolineTanker.UseVisualStyleBackColor = true; @@ -233,18 +252,20 @@ // this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill; this.pictureBox.Location = new System.Drawing.Point(0, 0); + this.pictureBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.pictureBox.Name = "pictureBox"; - this.pictureBox.Size = new System.Drawing.Size(694, 629); + this.pictureBox.Size = new System.Drawing.Size(793, 839); this.pictureBox.TabIndex = 1; this.pictureBox.TabStop = false; // // FormMapWithSetGasolineTanker // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(894, 629); + this.ClientSize = new System.Drawing.Size(1022, 839); this.Controls.Add(this.pictureBox); this.Controls.Add(this.groupBoxTools); + this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Name = "FormMapWithSetGasolineTanker"; this.Text = "FormMapWithSetGasolineTanker"; this.groupBoxTools.ResumeLayout(false); diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs index 9fa2688..8ecaafc 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs @@ -96,7 +96,7 @@ namespace GasolineTanker { return; } - pictureBox.Image = _mapGasolineTankerCollectionGeneric.ShowOnMap(); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap(); } private void ButtonMove_Click(object sender, EventArgs e) { @@ -181,5 +181,31 @@ namespace GasolineTanker { pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); } + + private void buttonRemoveGasolineTanker_Click(object sender, EventArgs e) + { + if (listBoxMaps.SelectedIndex == -1) + { + return; + } + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) + { + return; + } + if (MessageBox.Show("Delete object?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null) + { + MessageBox.Show("Object delete"); + pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet(); + } + else + { + MessageBox.Show("Errore delete object"); + } + } } } diff --git a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs index fe0cb2f..4a437cc 100644 --- a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs @@ -110,16 +110,13 @@ namespace GasolineTanker { int width = _pictureWidth / _placeSizeWidth; int height = _pictureHeight / _placeSizeHeight; - foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker()) + int i = 0; + + foreach (var warship in _setGasolineTanker.GetGasolineTanker()) { - gasolineTanker.SetObject(width, height, _pictureWidth, _pictureHeight); - gasolineTanker.DrawningObject(g); - width += _placeSizeWidth; - if (width > _pictureWidth - _placeSizeWidth) - { - width = _pictureWidth / _placeSizeWidth; - height -= _placeSizeHeight; - } + warship.SetObject(i % width * _placeSizeWidth+10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); + warship.DrawningObject(g); + i++; } } } -- 2.25.1 From 3c0124841ec9e6837e6af165340865c4cd78049e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Thu, 20 Oct 2022 11:28:49 +0400 Subject: [PATCH 4/4] fix --- .../GasolineTanker/FormMapWithSetGasolineTanker.cs | 2 ++ .../GasolineTanker/MapWithSetGasolienTankerGeneric.cs | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs index 8ecaafc..6df5df9 100644 --- a/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs +++ b/GasolineTanker/GasolineTanker/FormMapWithSetGasolineTanker.cs @@ -33,10 +33,12 @@ namespace GasolineTanker { 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; diff --git a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs index 4a437cc..cd44080 100644 --- a/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs +++ b/GasolineTanker/GasolineTanker/MapWithSetGasolienTankerGeneric.cs @@ -112,10 +112,10 @@ namespace GasolineTanker int height = _pictureHeight / _placeSizeHeight; int i = 0; - foreach (var warship in _setGasolineTanker.GetGasolineTanker()) + foreach (var gasolineTanker in _setGasolineTanker.GetGasolineTanker()) { - warship.SetObject(i % width * _placeSizeWidth+10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); - warship.DrawningObject(g); + gasolineTanker.SetObject(i % width * _placeSizeWidth+10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); + gasolineTanker.DrawningObject(g); i++; } } -- 2.25.1