From a0ffa4e20518d57f4eae1f007cc2abf8d2783c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Fri, 30 Sep 2022 16:33:17 +0400 Subject: [PATCH 01/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20SetArtilleriesG?= =?UTF-8?q?eneric?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SetArtilleriesGeneric.cs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs diff --git a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs new file mode 100644 index 0000000..07163b6 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Artilleries +{ + internal class SetArtilleriesGeneric + where T : class + { + private readonly T[] _places; + public int Count => _places.Length; + + public SetArtilleriesGeneric(int count) + { + _places = new T[count]; + } + + public bool Insert(T artillery) + { + return true; // TODO + } + + public bool Insert(T artillery, int position) + { + _places[position] = artillery; + return true; // TODO + } + + public bool Remove(int position) + { + return true; // TODO + } + + public T Get(int position) + { + return _places[position]; + } + } +} -- 2.25.1 From d8c763c582bb3778c6ace84bd8b4630b65b2e467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Fri, 30 Sep 2022 17:24:13 +0400 Subject: [PATCH 02/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20MapWithArtiller?= =?UTF-8?q?iesGeneric?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapWithArtilleriesGeneric.cs | 112 ++++++++++++++++++ .../SetArtilleriesGeneric.cs | 22 +++- 2 files changed, 132 insertions(+), 2 deletions(-) create mode 100644 SelfPropelledArtilleryUnit/MapWithArtilleriesGeneric.cs diff --git a/SelfPropelledArtilleryUnit/MapWithArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/MapWithArtilleriesGeneric.cs new file mode 100644 index 0000000..5c9d2c7 --- /dev/null +++ b/SelfPropelledArtilleryUnit/MapWithArtilleriesGeneric.cs @@ -0,0 +1,112 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Artilleries +{ + internal class MapWithArtilleriesGeneric + where T : class, IDrawingObject + where U : AbstractMap + { + private readonly int _pictureWidth; + private readonly int _pictureHeight; + private readonly int _placeSizeWidth = 210; + private readonly int _placeSizeHeight = 90; + private readonly SetArtilleriesGeneric _setArtilleries; + private readonly U _map; + + public MapWithArtilleriesGeneric(int picWidth, int picHeight, U map) + { + int width = picWidth / _placeSizeWidth; + int height = picHeight / _placeSizeHeight; + _setArtilleries = new SetArtilleriesGeneric(width * height); + _pictureWidth = picWidth; + _pictureHeight = picHeight; + _map = map; + } + + public static bool operator +(MapWithArtilleriesGeneric map, T artillery) + { + return map._setArtilleries.Insert(artillery); // TODO + } + + public static bool operator -(MapWithArtilleriesGeneric map, int position) + { + return map._setArtilleries.Remove(position); // TODO + } + + public Bitmap ShowOnMap() + { + Shaking(); + for (int i = 0; i < _setArtilleries.Count; i++) + { + var car = _setArtilleries.Get(i); + if (car != null) + { + return _map.CreateMap(_pictureWidth, _pictureHeight, car); + } + } + return new(_pictureWidth, _pictureHeight); + } + + public Bitmap MoveObject(Direction direction) + { + if (_map != null) + { + return _map.MoveObject(direction); + } + return new(_pictureWidth, _pictureHeight); + } + + private void Shaking() + { + int j = _setArtilleries.Count - 1; + for (int i = 0; i < _setArtilleries.Count; i++) + { + if (_setArtilleries.Get(i) == null) + { + for (; j > i; j--) + { + var car = _setArtilleries.Get(j); + if (car != null) + { + _setArtilleries.Insert(car, i); + _setArtilleries.Remove(j); + break; + } + } + if (j <= i) + { + return; + } + } + } + } + + private void DrawBackground(Graphics g) + { + Pen pen = new(Color.Black, 3); + for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) + {// TODO + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * + _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + } + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, + (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + } + } + + private void DrawArtilleries(Graphics g) + { + for (int i = 0; i < _setArtilleries.Count; i++) + { + // TODO установка позиции + _setArtilleries.Get(i)?.DrawingObject(g); + } + } + } +} diff --git a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs index 07163b6..71672f8 100644 --- a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs +++ b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs @@ -19,22 +19,40 @@ namespace Artilleries public bool Insert(T artillery) { - return true; // TODO + return Insert(artillery, 0); } public bool Insert(T artillery, int position) { + if (position < 0 || position >= Count) + { + return false; + } + + + _places[position] = artillery; return true; // TODO } public bool Remove(int position) { - return true; // TODO + if (position < 0 || position >= Count || _places[position] == null) + { + return false; + } + + _places[position] = null; + return true; } public T Get(int position) { + if (position < 0 || position >= Count) + { + return null; + } + return _places[position]; } } -- 2.25.1 From 5965acca14c910b184f8f9225dac6355c662d878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Fri, 30 Sep 2022 20:17:08 +0400 Subject: [PATCH 03/11] =?UTF-8?q?=D0=9D=D0=B5=D0=BA=D0=BE=D1=82=D0=BE?= =?UTF-8?q?=D1=80=D1=8B=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D1=8B=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D0=BB=D0=B8=20=D0=BF=D1=83=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=87=D0=BD=D1=8B=D0=BC=D0=B8.=20=D0=98=D0=B7=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D1=91=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20FormArtil?= =?UTF-8?q?lery.=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=BE=20?= =?UTF-8?q?=D0=B3=D0=BB=D0=B0=D0=B2=D0=BD=D0=BE=D0=B5=20=D0=BE=D0=BA=D0=BD?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/Direction.cs | 2 +- .../DrawingArtillery.cs | 2 +- SelfPropelledArtilleryUnit/EntityArtillery.cs | 2 +- .../FormArtillery.Designer.cs | 28 +++++++++ SelfPropelledArtilleryUnit/FormArtillery.cs | 57 +++++++++++++++++-- .../SetArtilleriesGeneric.cs | 27 ++++++++- 6 files changed, 109 insertions(+), 9 deletions(-) diff --git a/SelfPropelledArtilleryUnit/Direction.cs b/SelfPropelledArtilleryUnit/Direction.cs index 00b7082..191fe7d 100644 --- a/SelfPropelledArtilleryUnit/Direction.cs +++ b/SelfPropelledArtilleryUnit/Direction.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Artilleries { - internal enum Direction + public enum Direction { Up = 1, Down = 2, diff --git a/SelfPropelledArtilleryUnit/DrawingArtillery.cs b/SelfPropelledArtilleryUnit/DrawingArtillery.cs index ff31752..52f941c 100644 --- a/SelfPropelledArtilleryUnit/DrawingArtillery.cs +++ b/SelfPropelledArtilleryUnit/DrawingArtillery.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace Artilleries { - internal class DrawingArtillery + public class DrawingArtillery { public EntityArtillery Artillery { protected set; get; } protected float _startPosX; diff --git a/SelfPropelledArtilleryUnit/EntityArtillery.cs b/SelfPropelledArtilleryUnit/EntityArtillery.cs index df6fbf5..19b79b7 100644 --- a/SelfPropelledArtilleryUnit/EntityArtillery.cs +++ b/SelfPropelledArtilleryUnit/EntityArtillery.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Artilleries { - internal class EntityArtillery + public class EntityArtillery { public int Speed { get; private set; } public float Weight { get; private set; } diff --git a/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs b/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs index 04e9c76..4e465f1 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs @@ -39,6 +39,8 @@ this.buttonUp = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonRight = new System.Windows.Forms.Button(); + this.createAdvancedButton = new System.Windows.Forms.Button(); + this.selectArtilleryButton = new System.Windows.Forms.Button(); this.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit(); this.SuspendLayout(); @@ -147,11 +149,35 @@ this.buttonRight.UseVisualStyleBackColor = true; this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); // + // createAdvancedButton + // + this.createAdvancedButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); + this.createAdvancedButton.Location = new System.Drawing.Point(106, 382); + this.createAdvancedButton.Name = "createAdvancedButton"; + this.createAdvancedButton.Size = new System.Drawing.Size(113, 23); + this.createAdvancedButton.TabIndex = 7; + this.createAdvancedButton.Text = "Модифицировать"; + this.createAdvancedButton.UseVisualStyleBackColor = true; + this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_Click); + // + // selectArtilleryButton + // + this.selectArtilleryButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.selectArtilleryButton.Location = new System.Drawing.Point(410, 379); + this.selectArtilleryButton.Name = "selectArtilleryButton"; + this.selectArtilleryButton.Size = new System.Drawing.Size(75, 23); + this.selectArtilleryButton.TabIndex = 8; + this.selectArtilleryButton.Text = "Выбрать"; + this.selectArtilleryButton.UseVisualStyleBackColor = true; + this.selectArtilleryButton.Click += new System.EventHandler(this.selectArtilleryButton_Click); + // // FormArtillery // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(624, 441); + this.Controls.Add(this.selectArtilleryButton); + this.Controls.Add(this.createAdvancedButton); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonUp); @@ -183,5 +209,7 @@ private Button buttonUp; private Button buttonDown; private Button buttonRight; + private Button createAdvancedButton; + private Button selectArtilleryButton; } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/FormArtillery.cs b/SelfPropelledArtilleryUnit/FormArtillery.cs index 56fe28f..e130400 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.cs @@ -4,6 +4,8 @@ namespace Artilleries { private DrawingArtillery _artillery; + public DrawingArtillery SelectedArtillery { get; private set; } + public FormArtillery() { InitializeComponent(); @@ -17,14 +19,53 @@ namespace Artilleries pictureBoxArtilleries.Image = bmp; } + private void SetData(DrawingArtillery artillery) + { + Random rnd = new(); + artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); + SpeedStatusLabel.Text = $": {artillery.Artillery.Speed}"; + WeightStatusLabel.Text = $": {artillery.Artillery.Weight}"; + ColorStatusLabel.Text = $": {artillery.Artillery.BodyColor.Name}"; + } + private void buttonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _artillery = new DrawingArtillery(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - _artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); - SpeedStatusLabel.Text = $": {_artillery.Artillery.Speed}"; - WeightStatusLabel.Text = $": {_artillery.Artillery.Weight}"; - ColorStatusLabel.Text = $": {_artillery.Artillery.BodyColor.Name}"; + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + _artillery = new DrawingArtillery(rnd.Next(100, 300), rnd.Next(1000, 2000), color); + SetData(_artillery); + Draw(); + } + + private void createAdvancedButton_Click(object sender, EventArgs e) + { + Random rnd = new(); + Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialog = new(); + if (dialog.ShowDialog() == DialogResult.OK) + { + color = dialog.Color; + } + + Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)); + ColorDialog dialogDop = new(); + if (dialogDop.ShowDialog() == DialogResult.OK) + { + dopColor = dialogDop.Color; + } + _artillery = new DrawingAdvancedArtillery( + rnd.Next(100, 300), + rnd.Next(1000, 2000), + color, + dopColor, + rnd.Next(0, 2) == 1, rnd.Next(0, 2) == 1 + ); + SetData(_artillery); Draw(); } @@ -54,5 +95,11 @@ namespace Artilleries _artillery?.ChangeBorders(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); Draw(); } + + private void selectArtilleryButton_Click(object sender, EventArgs e) + { + SelectedArtillery = _artillery; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs index 71672f8..2f87663 100644 --- a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs +++ b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs @@ -29,10 +29,35 @@ namespace Artilleries return false; } + if (_places[position] == null) + { + _places[position] = artillery; + return true; + } + int firstNull = -1; + + for (int i = position + 1; i < Count; i++) + { + if (_places[i] == null) + { + firstNull = i; + break; + } + } + + if (firstNull == -1) + { + return false; + } + + for (int i = firstNull; i > position; i--) + { + (_places[i], _places[i - 1]) = (_places[i - 1], _places[i]); + } _places[position] = artillery; - return true; // TODO + return true; } public bool Remove(int position) -- 2.25.1 From ccd57fad9b091d69748281de9bca4600721686b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 2 Oct 2022 16:55:05 +0400 Subject: [PATCH 04/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BD=D0=BE=D0=B2=D0=B0=D1=8F=20=D1=84?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/FormMap.cs | 88 ------ ... => FormMapWithSetArtilleries.Designer.cs} | 268 +++++++++--------- .../FormMapWithSetArtilleries.cs | 139 +++++++++ ...ap.resx => FormMapWithSetArtilleries.resx} | 3 - ...ric.cs => MapWithSetArtilleriesGeneric.cs} | 17 +- SelfPropelledArtilleryUnit/Program.cs | 2 +- 6 files changed, 291 insertions(+), 226 deletions(-) delete mode 100644 SelfPropelledArtilleryUnit/FormMap.cs rename SelfPropelledArtilleryUnit/{FormMap.Designer.cs => FormMapWithSetArtilleries.Designer.cs} (54%) create mode 100644 SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs rename SelfPropelledArtilleryUnit/{FormMap.resx => FormMapWithSetArtilleries.resx} (93%) rename SelfPropelledArtilleryUnit/{MapWithArtilleriesGeneric.cs => MapWithSetArtilleriesGeneric.cs} (85%) diff --git a/SelfPropelledArtilleryUnit/FormMap.cs b/SelfPropelledArtilleryUnit/FormMap.cs deleted file mode 100644 index 016c4bc..0000000 --- a/SelfPropelledArtilleryUnit/FormMap.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; - -namespace Artilleries -{ - public partial class FormMap : Form - { - private AbstractMap _abstractMap; - - public FormMap() - { - InitializeComponent(); - _abstractMap = new SimpleMap(); - } - - private void SetData(DrawingArtillery artillery) - { - Random rnd = new(); - artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); - SpeedStatusLabel.Text = $"Скорость: {artillery.Artillery.Speed}"; - WeightStatusLabel.Text = $"Вес: {artillery.Artillery.Weight}"; - ColorStatusLabel.Text = $"Цвет: {artillery.Artillery.BodyColor.Name}"; - pictureBoxArtilleries.Image = _abstractMap.CreateMap(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height, new DrawingObjectArtillery(artillery)); - } - - private void createAdvancedButton_Click(object sender, EventArgs e) - { - Random rnd = new(); - var artillery = new DrawingAdvancedArtillery( - rnd.Next(100, 300), - rnd.Next(1000, 2000), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), - rnd.Next(0, 2) == 1, rnd.Next(0, 2) == 1 - ); - SetData(artillery); - } - - private void buttonCreate_Click(object sender, EventArgs e) - { - Random rnd = new(); - var artillery = new DrawingArtillery(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); - SetData(artillery); - } - - private void buttonMove_Click(object sender, EventArgs e) - { - string name = ((Button)sender)?.Name ?? string.Empty; - Direction dir = Direction.None; - switch (name) - { - case "buttonUp": - dir = Direction.Up; - break; - case "buttonDown": - dir = Direction.Down; - break; - case "buttonLeft": - dir = Direction.Left; - break; - case "buttonRight": - dir = Direction.Right; - break; - } - pictureBoxArtilleries.Image = _abstractMap?.MoveObject(dir); - } - - private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) - { - switch (comboBoxSelectorMap.Text) - { - case "Простая карта": - _abstractMap = new SimpleMap(); - break; - case "Лесная карта": - _abstractMap = new ForestMap(); - break; - } - } - } -} diff --git a/SelfPropelledArtilleryUnit/FormMap.Designer.cs b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.Designer.cs similarity index 54% rename from SelfPropelledArtilleryUnit/FormMap.Designer.cs rename to SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.Designer.cs index 61dcc5c..89100c3 100644 --- a/SelfPropelledArtilleryUnit/FormMap.Designer.cs +++ b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.Designer.cs @@ -1,6 +1,6 @@ namespace Artilleries { - partial class FormMap + partial class FormMapWithSetArtilleries { /// /// Required designer variable. @@ -28,130 +28,89 @@ /// private void InitializeComponent() { - this.createAdvancedButton = new System.Windows.Forms.Button(); + this.toolsGroupBox = new System.Windows.Forms.GroupBox(); + this.buttonShowOnMap = new System.Windows.Forms.Button(); + this.buttonShowStorage = new System.Windows.Forms.Button(); + this.buttonRemoveArtillery = new System.Windows.Forms.Button(); + this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox(); + this.buttonAddArtillery = new System.Windows.Forms.Button(); + this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); this.buttonRight = new System.Windows.Forms.Button(); this.buttonDown = new System.Windows.Forms.Button(); this.buttonUp = new System.Windows.Forms.Button(); this.buttonLeft = new System.Windows.Forms.Button(); - this.buttonCreate = new System.Windows.Forms.Button(); this.pictureBoxArtilleries = new System.Windows.Forms.PictureBox(); - this.statusStrip1 = new System.Windows.Forms.StatusStrip(); - this.SpeedStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); - this.WeightStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); - this.ColorStatusLabel = new System.Windows.Forms.ToolStripStatusLabel(); - this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox(); + this.toolsGroupBox.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit(); - this.statusStrip1.SuspendLayout(); this.SuspendLayout(); // - // createAdvancedButton + // toolsGroupBox // - this.createAdvancedButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.createAdvancedButton.Location = new System.Drawing.Point(105, 382); - this.createAdvancedButton.Name = "createAdvancedButton"; - this.createAdvancedButton.Size = new System.Drawing.Size(95, 23); - this.createAdvancedButton.TabIndex = 15; - this.createAdvancedButton.Text = "Модификация"; - this.createAdvancedButton.UseVisualStyleBackColor = true; - this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_Click); + this.toolsGroupBox.Controls.Add(this.buttonShowOnMap); + this.toolsGroupBox.Controls.Add(this.buttonShowStorage); + this.toolsGroupBox.Controls.Add(this.buttonRemoveArtillery); + this.toolsGroupBox.Controls.Add(this.maskedTextBoxPosition); + this.toolsGroupBox.Controls.Add(this.buttonAddArtillery); + this.toolsGroupBox.Controls.Add(this.comboBoxSelectorMap); + this.toolsGroupBox.Controls.Add(this.buttonRight); + this.toolsGroupBox.Controls.Add(this.buttonDown); + this.toolsGroupBox.Controls.Add(this.buttonUp); + this.toolsGroupBox.Controls.Add(this.buttonLeft); + this.toolsGroupBox.Dock = System.Windows.Forms.DockStyle.Right; + this.toolsGroupBox.Location = new System.Drawing.Point(600, 0); + this.toolsGroupBox.Name = "toolsGroupBox"; + this.toolsGroupBox.Size = new System.Drawing.Size(200, 450); + this.toolsGroupBox.TabIndex = 0; + this.toolsGroupBox.TabStop = false; + this.toolsGroupBox.Text = "Инструменты"; // - // buttonRight + // buttonShowOnMap // - this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonRight.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowRight; - this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonRight.Location = new System.Drawing.Point(579, 375); - this.buttonRight.Name = "buttonRight"; - this.buttonRight.Size = new System.Drawing.Size(30, 30); - this.buttonRight.TabIndex = 14; - this.buttonRight.UseVisualStyleBackColor = true; - this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); + this.buttonShowOnMap.Location = new System.Drawing.Point(13, 315); + this.buttonShowOnMap.Name = "buttonShowOnMap"; + this.buttonShowOnMap.Size = new System.Drawing.Size(175, 32); + this.buttonShowOnMap.TabIndex = 24; + this.buttonShowOnMap.Text = "Посмотреть карту"; + this.buttonShowOnMap.UseVisualStyleBackColor = true; + this.buttonShowOnMap.Click += new System.EventHandler(this.buttonShowOnMap_Click); // - // buttonDown + // buttonShowStorage // - this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonDown.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowDown; - this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonDown.Location = new System.Drawing.Point(543, 375); - this.buttonDown.Name = "buttonDown"; - this.buttonDown.Size = new System.Drawing.Size(30, 30); - this.buttonDown.TabIndex = 13; - this.buttonDown.UseVisualStyleBackColor = true; - this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); + this.buttonShowStorage.Location = new System.Drawing.Point(13, 249); + this.buttonShowStorage.Name = "buttonShowStorage"; + this.buttonShowStorage.Size = new System.Drawing.Size(175, 32); + this.buttonShowStorage.TabIndex = 23; + this.buttonShowStorage.Text = "Посмотреть хранилище"; + this.buttonShowStorage.UseVisualStyleBackColor = true; + this.buttonShowStorage.Click += new System.EventHandler(this.buttonShowStorage_Click); // - // buttonUp + // buttonRemoveArtillery // - this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonUp.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowUp; - this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonUp.Location = new System.Drawing.Point(543, 342); - this.buttonUp.Name = "buttonUp"; - this.buttonUp.Size = new System.Drawing.Size(30, 30); - this.buttonUp.TabIndex = 12; - this.buttonUp.UseVisualStyleBackColor = true; - this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); + this.buttonRemoveArtillery.Location = new System.Drawing.Point(13, 177); + this.buttonRemoveArtillery.Name = "buttonRemoveArtillery"; + this.buttonRemoveArtillery.Size = new System.Drawing.Size(175, 32); + this.buttonRemoveArtillery.TabIndex = 22; + this.buttonRemoveArtillery.Text = "Удалить артиллерию"; + this.buttonRemoveArtillery.UseVisualStyleBackColor = true; + this.buttonRemoveArtillery.Click += new System.EventHandler(this.buttonRemoveArtillery_Click); // - // buttonLeft + // maskedTextBoxPosition // - this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this.buttonLeft.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowLeft; - this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; - this.buttonLeft.Location = new System.Drawing.Point(509, 375); - this.buttonLeft.Name = "buttonLeft"; - this.buttonLeft.Size = new System.Drawing.Size(30, 30); - this.buttonLeft.TabIndex = 11; - this.buttonLeft.UseVisualStyleBackColor = true; - this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click); + this.maskedTextBoxPosition.Location = new System.Drawing.Point(13, 148); + this.maskedTextBoxPosition.Mask = "00"; + this.maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23); + this.maskedTextBoxPosition.TabIndex = 21; // - // buttonCreate + // buttonAddArtillery // - this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); - this.buttonCreate.Location = new System.Drawing.Point(12, 382); - this.buttonCreate.Name = "buttonCreate"; - this.buttonCreate.Size = new System.Drawing.Size(75, 23); - this.buttonCreate.TabIndex = 10; - this.buttonCreate.Text = "Создать"; - this.buttonCreate.UseVisualStyleBackColor = true; - this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click); - // - // pictureBoxArtilleries - // - this.pictureBoxArtilleries.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxArtilleries.Location = new System.Drawing.Point(0, 0); - this.pictureBoxArtilleries.Name = "pictureBoxArtilleries"; - this.pictureBoxArtilleries.Size = new System.Drawing.Size(624, 419); - this.pictureBoxArtilleries.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; - this.pictureBoxArtilleries.TabIndex = 9; - this.pictureBoxArtilleries.TabStop = false; - // - // statusStrip1 - // - this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.SpeedStatusLabel, - this.WeightStatusLabel, - this.ColorStatusLabel}); - this.statusStrip1.Location = new System.Drawing.Point(0, 419); - this.statusStrip1.Name = "statusStrip1"; - this.statusStrip1.Size = new System.Drawing.Size(624, 22); - this.statusStrip1.TabIndex = 8; - // - // SpeedStatusLabel - // - this.SpeedStatusLabel.Name = "SpeedStatusLabel"; - this.SpeedStatusLabel.Size = new System.Drawing.Size(62, 17); - this.SpeedStatusLabel.Text = "Скорость:"; - // - // WeightStatusLabel - // - this.WeightStatusLabel.Name = "WeightStatusLabel"; - this.WeightStatusLabel.Size = new System.Drawing.Size(29, 17); - this.WeightStatusLabel.Text = "Вес:"; - // - // ColorStatusLabel - // - this.ColorStatusLabel.Name = "ColorStatusLabel"; - this.ColorStatusLabel.Size = new System.Drawing.Size(36, 17); - this.ColorStatusLabel.Text = "Цвет:"; + this.buttonAddArtillery.Location = new System.Drawing.Point(13, 83); + this.buttonAddArtillery.Name = "buttonAddArtillery"; + this.buttonAddArtillery.Size = new System.Drawing.Size(175, 32); + this.buttonAddArtillery.TabIndex = 20; + this.buttonAddArtillery.Text = "Добавить артиллерию"; + this.buttonAddArtillery.UseVisualStyleBackColor = true; + this.buttonAddArtillery.Click += new System.EventHandler(this.buttonAddArtillery_Click); // // comboBoxSelectorMap // @@ -160,49 +119,98 @@ this.comboBoxSelectorMap.Items.AddRange(new object[] { "Простая карта", "Лесная карта"}); - this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(13, 22); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; - this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); - this.comboBoxSelectorMap.TabIndex = 16; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23); + this.comboBoxSelectorMap.TabIndex = 19; this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); // - // FormMap + // buttonRight + // + this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonRight.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowRight; + this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonRight.Location = new System.Drawing.Point(124, 399); + this.buttonRight.Name = "buttonRight"; + this.buttonRight.Size = new System.Drawing.Size(30, 30); + this.buttonRight.TabIndex = 18; + this.buttonRight.UseVisualStyleBackColor = true; + this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonDown + // + this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonDown.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowDown; + this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonDown.Location = new System.Drawing.Point(88, 399); + this.buttonDown.Name = "buttonDown"; + this.buttonDown.Size = new System.Drawing.Size(30, 30); + this.buttonDown.TabIndex = 17; + this.buttonDown.UseVisualStyleBackColor = true; + this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonUp + // + this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonUp.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowUp; + this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonUp.Location = new System.Drawing.Point(88, 366); + this.buttonUp.Name = "buttonUp"; + this.buttonUp.Size = new System.Drawing.Size(30, 30); + this.buttonUp.TabIndex = 16; + this.buttonUp.UseVisualStyleBackColor = true; + this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click); + // + // buttonLeft + // + this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonLeft.BackgroundImage = global::SelfPropelledArtilleryUnit.Properties.Resources.ArrowLeft; + this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom; + this.buttonLeft.Location = new System.Drawing.Point(54, 399); + this.buttonLeft.Name = "buttonLeft"; + this.buttonLeft.Size = new System.Drawing.Size(30, 30); + this.buttonLeft.TabIndex = 15; + this.buttonLeft.UseVisualStyleBackColor = true; + this.buttonLeft.Click += new System.EventHandler(this.buttonMove_Click); + // + // pictureBoxArtilleries + // + this.pictureBoxArtilleries.Dock = System.Windows.Forms.DockStyle.Fill; + this.pictureBoxArtilleries.Location = new System.Drawing.Point(0, 0); + this.pictureBoxArtilleries.Name = "pictureBoxArtilleries"; + this.pictureBoxArtilleries.Size = new System.Drawing.Size(600, 450); + this.pictureBoxArtilleries.TabIndex = 1; + this.pictureBoxArtilleries.TabStop = false; + // + // FormMapWithSetArtilleries // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(624, 441); - this.Controls.Add(this.comboBoxSelectorMap); - this.Controls.Add(this.createAdvancedButton); - this.Controls.Add(this.buttonRight); - this.Controls.Add(this.buttonDown); - this.Controls.Add(this.buttonUp); - this.Controls.Add(this.buttonLeft); - this.Controls.Add(this.buttonCreate); + this.ClientSize = new System.Drawing.Size(800, 450); this.Controls.Add(this.pictureBoxArtilleries); - this.Controls.Add(this.statusStrip1); - this.Name = "FormMap"; + this.Controls.Add(this.toolsGroupBox); + this.Name = "FormMapWithSetArtilleries"; this.Text = "Artillery"; + this.toolsGroupBox.ResumeLayout(false); + this.toolsGroupBox.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).EndInit(); - this.statusStrip1.ResumeLayout(false); - this.statusStrip1.PerformLayout(); this.ResumeLayout(false); - this.PerformLayout(); } #endregion - private Button createAdvancedButton; + private GroupBox toolsGroupBox; + private PictureBox pictureBoxArtilleries; private Button buttonRight; private Button buttonDown; private Button buttonUp; private Button buttonLeft; - private Button buttonCreate; - private PictureBox pictureBoxArtilleries; - private StatusStrip statusStrip1; - private ToolStripStatusLabel SpeedStatusLabel; - private ToolStripStatusLabel WeightStatusLabel; - private ToolStripStatusLabel ColorStatusLabel; private ComboBox comboBoxSelectorMap; + private Button buttonShowOnMap; + private Button buttonShowStorage; + private Button buttonRemoveArtillery; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonAddArtillery; } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs new file mode 100644 index 0000000..a755fdd --- /dev/null +++ b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static System.Windows.Forms.DataFormats; + +namespace Artilleries +{ + public partial class FormMapWithSetArtilleries : Form + { + private MapWithSetArtilleriesGeneric +_mapArtilleriesCollectionGeneric; + + public FormMapWithSetArtilleries() + { + InitializeComponent(); + } + + private void comboBoxSelectorMap_SelectedIndexChanged(object sender, +EventArgs e) + { + AbstractMap map = null; + switch (comboBoxSelectorMap.Text) + { + case "Простая карта": + map = new SimpleMap(); + break; + case "Лесная карта": + map = new ForestMap(); + break; + } + if (map != null) + { + _mapArtilleriesCollectionGeneric = new + MapWithSetArtilleriesGeneric( + pictureBoxArtilleries.Width, pictureBoxArtilleries.Height, map); + } + else + { + _mapArtilleriesCollectionGeneric = null; + } + } + + private void buttonAddArtillery_Click(object sender, EventArgs e) + { + if (_mapArtilleriesCollectionGeneric == null) + { + return; + } + FormArtillery form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + DrawingObjectArtillery car = new(form.SelectedArtillery); + if (_mapArtilleriesCollectionGeneric + car) + { + MessageBox.Show("Объект добавлен"); + pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + + private void buttonRemoveArtillery_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text)) + { + return; + } + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_mapArtilleriesCollectionGeneric - pos) + { + MessageBox.Show("Объект удален"); + pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + private void buttonShowStorage_Click(object sender, EventArgs e) + { + if (_mapArtilleriesCollectionGeneric == null) + { + return; + } + pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet(); + } + + private void buttonShowOnMap_Click(object sender, EventArgs e) + { + if (_mapArtilleriesCollectionGeneric == null) + { + return; + } + pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowOnMap(); + } + + private void buttonMove_Click(object sender, EventArgs e) + { + if (_mapArtilleriesCollectionGeneric == null) + { + return; + } + + string name = ((Button)sender)?.Name ?? string.Empty; + Direction dir = Direction.None; + switch (name) + { + case "buttonUp": + dir = Direction.Up; + break; + case "buttonDown": + dir = Direction.Down; + break; + case "buttonLeft": + dir = Direction.Left; + break; + case "buttonRight": + dir = Direction.Right; + break; + } + pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.MoveObject(dir); + } + } +} diff --git a/SelfPropelledArtilleryUnit/FormMap.resx b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.resx similarity index 93% rename from SelfPropelledArtilleryUnit/FormMap.resx rename to SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.resx index 5cb320f..f298a7b 100644 --- a/SelfPropelledArtilleryUnit/FormMap.resx +++ b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.resx @@ -57,7 +57,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 17, 17 - \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/MapWithArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs similarity index 85% rename from SelfPropelledArtilleryUnit/MapWithArtilleriesGeneric.cs rename to SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs index 5c9d2c7..b1cddb9 100644 --- a/SelfPropelledArtilleryUnit/MapWithArtilleriesGeneric.cs +++ b/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Artilleries { - internal class MapWithArtilleriesGeneric + internal class MapWithSetArtilleriesGeneric where T : class, IDrawingObject where U : AbstractMap { @@ -17,7 +17,7 @@ namespace Artilleries private readonly SetArtilleriesGeneric _setArtilleries; private readonly U _map; - public MapWithArtilleriesGeneric(int picWidth, int picHeight, U map) + public MapWithSetArtilleriesGeneric(int picWidth, int picHeight, U map) { int width = picWidth / _placeSizeWidth; int height = picHeight / _placeSizeHeight; @@ -27,16 +27,25 @@ namespace Artilleries _map = map; } - public static bool operator +(MapWithArtilleriesGeneric map, T artillery) + public static bool operator +(MapWithSetArtilleriesGeneric map, T artillery) { return map._setArtilleries.Insert(artillery); // TODO } - public static bool operator -(MapWithArtilleriesGeneric map, int position) + public static bool operator -(MapWithSetArtilleriesGeneric map, int position) { return map._setArtilleries.Remove(position); // TODO } + public Bitmap ShowSet() + { + Bitmap bmp = new(_pictureWidth, _pictureHeight); + Graphics gr = Graphics.FromImage(bmp); + DrawBackground(gr); + DrawArtilleries(gr); + return bmp; + } + public Bitmap ShowOnMap() { Shaking(); diff --git a/SelfPropelledArtilleryUnit/Program.cs b/SelfPropelledArtilleryUnit/Program.cs index 2b37e99..5f48e30 100644 --- a/SelfPropelledArtilleryUnit/Program.cs +++ b/SelfPropelledArtilleryUnit/Program.cs @@ -6,7 +6,7 @@ namespace Artilleries static void Main() { ApplicationConfiguration.Initialize(); - Application.Run(new FormMap()); + Application.Run(new FormMapWithSetArtilleries()); } } } \ No newline at end of file -- 2.25.1 From f803dc89dde69c64bf9c42970d67542509796a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 2 Oct 2022 17:42:23 +0400 Subject: [PATCH 05/11] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BE=D1=82=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B0=D1=80=D1=82=D0=B8=D0=BB=D0=BB=D0=B5=D1=80=D0=B8?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapWithSetArtilleriesGeneric.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs index b1cddb9..6bcce92 100644 --- a/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs +++ b/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs @@ -111,10 +111,17 @@ namespace Artilleries private void DrawArtilleries(Graphics g) { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + for (int i = 0; i < _setArtilleries.Count; i++) { - // TODO установка позиции - _setArtilleries.Get(i)?.DrawingObject(g); + var artillery = _setArtilleries.Get(i); + if (artillery != null) + { + artillery.SetObject(i % width * _placeSizeWidth + 10, (height - 1 - i / width) * _placeSizeHeight + 10, _pictureWidth, _pictureHeight); + artillery.DrawingObject(g); + } } } } -- 2.25.1 From 8894238c90540b4586b62e41a8f7591a092970c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 2 Oct 2022 22:17:57 +0400 Subject: [PATCH 06/11] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs index a755fdd..c77c1b1 100644 --- a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs +++ b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs @@ -13,8 +13,7 @@ namespace Artilleries { public partial class FormMapWithSetArtilleries : Form { - private MapWithSetArtilleriesGeneric -_mapArtilleriesCollectionGeneric; + private MapWithSetArtilleriesGeneric _mapArtilleriesCollectionGeneric; public FormMapWithSetArtilleries() { -- 2.25.1 From 5ffa496f6f2031e38ad1c446338da886d6f8baea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Sun, 2 Oct 2022 22:19:25 +0400 Subject: [PATCH 07/11] =?UTF-8?q?=D0=95=D1=89=D1=91=20=D0=B8=D1=81=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetArtilleries.cs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs index c77c1b1..2317b42 100644 --- a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs +++ b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs @@ -20,8 +20,7 @@ namespace Artilleries InitializeComponent(); } - private void comboBoxSelectorMap_SelectedIndexChanged(object sender, -EventArgs e) + private void comboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e) { AbstractMap map = null; switch (comboBoxSelectorMap.Text) @@ -35,9 +34,7 @@ EventArgs e) } if (map != null) { - _mapArtilleriesCollectionGeneric = new - MapWithSetArtilleriesGeneric( - pictureBoxArtilleries.Width, pictureBoxArtilleries.Height, map); + _mapArtilleriesCollectionGeneric = new MapWithSetArtilleriesGeneric(pictureBoxArtilleries.Width, pictureBoxArtilleries.Height, map); } else { @@ -73,8 +70,7 @@ EventArgs e) { return; } - if (MessageBox.Show("Удалить объект?", "Удаление", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } -- 2.25.1 From 66371369da0bc814c8b0b300b281752cf07cac62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Mon, 3 Oct 2022 00:55:54 +0400 Subject: [PATCH 08/11] =?UTF-8?q?=D0=94=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0?= =?UTF-8?q?=D0=BD=20DrawBackground?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../MapWithSetArtilleriesGeneric.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs index 6bcce92..d53c409 100644 --- a/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs +++ b/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs @@ -97,15 +97,21 @@ namespace Artilleries private void DrawBackground(Graphics g) { Pen pen = new(Color.Black, 3); + Brush boxBrush = new SolidBrush(Color.DarkGreen); + Pen thinPen = new Pen(Color.Black, 2); + Brush flagBrush = new SolidBrush(Color.Red); for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++) { for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j) - {// TODO - g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * - _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + { + g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight); + g.FillRectangle(boxBrush, i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5, _placeSizeWidth / 3 - 5, _placeSizeHeight / 3 - 5); + g.DrawLine(thinPen, i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5, i * _placeSizeWidth + _placeSizeWidth / 3, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 + _placeSizeHeight / 3 - 10); + g.DrawLine(thinPen, i * _placeSizeWidth + 5, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 + _placeSizeHeight / 3 - 10, i * _placeSizeWidth + _placeSizeWidth / 3, j * _placeSizeHeight + _placeSizeHeight * 3 / 4 - 5); + g.FillRectangle(flagBrush, i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight * 5 / 8 - 5, _placeSizeWidth / 5, _placeSizeHeight / 5); + g.DrawLine(thinPen, i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight - 5, i * _placeSizeWidth + _placeSizeWidth * 5 / 12, j * _placeSizeHeight + _placeSizeHeight * 5 / 8 - 5); } - g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, - (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); + g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight); } } -- 2.25.1 From c1dbdd80ed275dc0f602f53da7e2b8cd4131c091 Mon Sep 17 00:00:00 2001 From: Katerina881 Date: Mon, 3 Oct 2022 16:01:05 +0400 Subject: [PATCH 09/11] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=82=D0=B8=D0=BF=D1=8B=20=D0=B2=D0=BE=D0=B7?= =?UTF-8?q?=D0=B2=D1=80=D0=B0=D1=89=D0=B0=D0=B5=D0=BC=D1=8B=D1=85=20=D0=B7?= =?UTF-8?q?=D0=BD=D0=B0=D1=87=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormMapWithSetArtilleries.cs | 4 ++-- .../MapWithSetArtilleriesGeneric.cs | 8 +++---- .../SetArtilleriesGeneric.cs | 24 ++++++++++--------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs index 2317b42..47f71e5 100644 --- a/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs +++ b/SelfPropelledArtilleryUnit/FormMapWithSetArtilleries.cs @@ -52,7 +52,7 @@ namespace Artilleries if (form.ShowDialog() == DialogResult.OK) { DrawingObjectArtillery car = new(form.SelectedArtillery); - if (_mapArtilleriesCollectionGeneric + car) + if (_mapArtilleriesCollectionGeneric + car != -1) { MessageBox.Show("Объект добавлен"); pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet(); @@ -75,7 +75,7 @@ namespace Artilleries return; } int pos = Convert.ToInt32(maskedTextBoxPosition.Text); - if (_mapArtilleriesCollectionGeneric - pos) + if (_mapArtilleriesCollectionGeneric - pos != null) { MessageBox.Show("Объект удален"); pictureBoxArtilleries.Image = _mapArtilleriesCollectionGeneric.ShowSet(); diff --git a/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs index d53c409..4c03bfe 100644 --- a/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs +++ b/SelfPropelledArtilleryUnit/MapWithSetArtilleriesGeneric.cs @@ -27,14 +27,14 @@ namespace Artilleries _map = map; } - public static bool operator +(MapWithSetArtilleriesGeneric map, T artillery) + public static int operator +(MapWithSetArtilleriesGeneric map, T artillery) { - return map._setArtilleries.Insert(artillery); // TODO + return map._setArtilleries.Insert(artillery); } - public static bool operator -(MapWithSetArtilleriesGeneric map, int position) + public static T operator -(MapWithSetArtilleriesGeneric map, int position) { - return map._setArtilleries.Remove(position); // TODO + return map._setArtilleries.Remove(position); } public Bitmap ShowSet() diff --git a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs index 2f87663..35c69f5 100644 --- a/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs +++ b/SelfPropelledArtilleryUnit/SetArtilleriesGeneric.cs @@ -17,22 +17,22 @@ namespace Artilleries _places = new T[count]; } - public bool Insert(T artillery) + public int Insert(T artillery) { return Insert(artillery, 0); } - public bool Insert(T artillery, int position) + public int Insert(T artillery, int position) { if (position < 0 || position >= Count) { - return false; + return -1; } if (_places[position] == null) { _places[position] = artillery; - return true; + return position; } int firstNull = -1; @@ -48,27 +48,29 @@ namespace Artilleries if (firstNull == -1) { - return false; + return -1; } for (int i = firstNull; i > position; i--) { - (_places[i], _places[i - 1]) = (_places[i - 1], _places[i]); + _places[i] = _places[i - 1]; } _places[position] = artillery; - return true; + return position; } - public bool Remove(int position) + public T Remove(int position) { - if (position < 0 || position >= Count || _places[position] == null) + if (position < 0 || position >= Count) { - return false; + return null; } + var result = _places[position]; + _places[position] = null; - return true; + return result; } public T Get(int position) -- 2.25.1 From b25aaeb08190aec85ae11961c1fd2ea9b0673172 Mon Sep 17 00:00:00 2001 From: ChipsEater Date: Mon, 3 Oct 2022 16:26:19 +0400 Subject: [PATCH 10/11] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/FormArtillery.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SelfPropelledArtilleryUnit/FormArtillery.cs b/SelfPropelledArtilleryUnit/FormArtillery.cs index e130400..b8c03dc 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.cs @@ -23,9 +23,9 @@ namespace Artilleries { Random rnd = new(); artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); - SpeedStatusLabel.Text = $": {artillery.Artillery.Speed}"; - WeightStatusLabel.Text = $": {artillery.Artillery.Weight}"; - ColorStatusLabel.Text = $": {artillery.Artillery.BodyColor.Name}"; + SpeedStatusLabel.Text = $"Скорость: {artillery.Artillery.Speed}"; + WeightStatusLabel.Text = $"Вес: {artillery.Artillery.Weight}"; + ColorStatusLabel.Text = $"Цвет: {artillery.Artillery.BodyColor.Name}"; } private void buttonCreate_Click(object sender, EventArgs e) -- 2.25.1 From a42103499a551f1f3f286e4c8c93df4dbc4e70cc Mon Sep 17 00:00:00 2001 From: Overlordddd Date: Mon, 3 Oct 2022 16:30:06 +0400 Subject: [PATCH 11/11] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/FormArtillery.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/SelfPropelledArtilleryUnit/FormArtillery.cs b/SelfPropelledArtilleryUnit/FormArtillery.cs index b8c03dc..e130400 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.cs @@ -23,9 +23,9 @@ namespace Artilleries { Random rnd = new(); artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); - SpeedStatusLabel.Text = $"Скорость: {artillery.Artillery.Speed}"; - WeightStatusLabel.Text = $"Вес: {artillery.Artillery.Weight}"; - ColorStatusLabel.Text = $"Цвет: {artillery.Artillery.BodyColor.Name}"; + SpeedStatusLabel.Text = $": {artillery.Artillery.Speed}"; + WeightStatusLabel.Text = $": {artillery.Artillery.Weight}"; + ColorStatusLabel.Text = $": {artillery.Artillery.BodyColor.Name}"; } private void buttonCreate_Click(object sender, EventArgs e) -- 2.25.1