From d9e184ca89949115b490269e22e98e5c4875a806 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, 26 Sep 2022 17:35:01 +0400 Subject: [PATCH 01/10] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/DrawingArtillery.cs | 5 ++--- SelfPropelledArtilleryUnit/EntityArtillery.cs | 2 +- SelfPropelledArtilleryUnit/FormArtillery.cs | 5 ++--- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/SelfPropelledArtilleryUnit/DrawingArtillery.cs b/SelfPropelledArtilleryUnit/DrawingArtillery.cs index bc793c4..38abc72 100644 --- a/SelfPropelledArtilleryUnit/DrawingArtillery.cs +++ b/SelfPropelledArtilleryUnit/DrawingArtillery.cs @@ -15,10 +15,9 @@ namespace Artilleries private int? _pictureHeight = null; private readonly int _artilleryWidth = 80; private readonly int _artilleryHeight = 50; - public void Init(int speed, float weight, Color bodyColor) + public DrawingArtillery(int speed, float weight, Color bodyColor) { - Artillery = new EntityArtillery(); - Artillery.Init(speed, weight, bodyColor); + Artillery = new EntityArtillery(speed, weight, bodyColor); } public void SetPosition(int x, int y, int width, int height) { diff --git a/SelfPropelledArtilleryUnit/EntityArtillery.cs b/SelfPropelledArtilleryUnit/EntityArtillery.cs index d3254ca..df6fbf5 100644 --- a/SelfPropelledArtilleryUnit/EntityArtillery.cs +++ b/SelfPropelledArtilleryUnit/EntityArtillery.cs @@ -12,7 +12,7 @@ namespace Artilleries public float Weight { get; private set; } public Color BodyColor { get; private set; } public float Step => Speed * 100 / Weight; - public void Init(int speed, float weight, Color bodyColor) + public EntityArtillery(int speed, float weight, Color bodyColor) { Random rnd = new(); Speed = speed <= 0 ? rnd.Next(50, 150) : speed; diff --git a/SelfPropelledArtilleryUnit/FormArtillery.cs b/SelfPropelledArtilleryUnit/FormArtillery.cs index 718c34a..6d8038b 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.cs @@ -20,9 +20,8 @@ namespace Artilleries private void buttonCreate_Click(object sender, EventArgs e) { Random rnd = new(); - _artillery = new DrawingArtillery(); - _artillery.Init(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(pictureBoxArtilleries.Width - 161, pictureBoxArtilleries.Width - 81), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); + _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}"; From 40820059a5e7eb736280912458b4c12b25ed6e45 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, 26 Sep 2022 18:28:05 +0400 Subject: [PATCH 02/10] =?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=BF=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD?= =?UTF-8?q?=D1=83=D1=82=D0=B0=D1=8F=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B8=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84?= =?UTF-8?q?=D0=B5=D0=B9=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EntityAdvancedArtillery.cs | 21 +++++++++++++++++++ SelfPropelledArtilleryUnit/IDrawningObject.cs | 17 +++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 SelfPropelledArtilleryUnit/EntityAdvancedArtillery.cs create mode 100644 SelfPropelledArtilleryUnit/IDrawningObject.cs diff --git a/SelfPropelledArtilleryUnit/EntityAdvancedArtillery.cs b/SelfPropelledArtilleryUnit/EntityAdvancedArtillery.cs new file mode 100644 index 0000000..dd67cd2 --- /dev/null +++ b/SelfPropelledArtilleryUnit/EntityAdvancedArtillery.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Artilleries +{ + internal class EntityAdvancedArtillery : EntityArtillery + { + public Color DopColor { get; private set; } + public bool Weapon { get; private set; } + public bool SalvoBattery { get; private set; } + public EntityAdvancedArtillery(int speed, float weight, Color bodyColor, Color dopColor, bool weapon, bool salvoBattery) : base(speed, weight, bodyColor) + { + DopColor = dopColor; + Weapon = weapon; + SalvoBattery = salvoBattery; + } + } +} diff --git a/SelfPropelledArtilleryUnit/IDrawningObject.cs b/SelfPropelledArtilleryUnit/IDrawningObject.cs new file mode 100644 index 0000000..67cae91 --- /dev/null +++ b/SelfPropelledArtilleryUnit/IDrawningObject.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Artilleries +{ + internal interface IDrawningObject + { + public float Step { get; } + void SetObject(int x, int y, int width, int height); + void MoveObject(Direction direction); + void DrawingObject(Graphics g); + (float Left, float Right, float Top, float Bottom) GetCurrentPosition(); + } +} From fbd570c22dbfcbca8fb56cfab895697ca143764e 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, 26 Sep 2022 18:36:46 +0400 Subject: [PATCH 03/10] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B4=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82?= =?UTF-8?q?=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=20=D0=B8=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=B4=20=D1=81=D1=82=D0=B0=D0=BB=20virtual?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/DrawingArtillery.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/SelfPropelledArtilleryUnit/DrawingArtillery.cs b/SelfPropelledArtilleryUnit/DrawingArtillery.cs index 38abc72..0ef8ae4 100644 --- a/SelfPropelledArtilleryUnit/DrawingArtillery.cs +++ b/SelfPropelledArtilleryUnit/DrawingArtillery.cs @@ -15,10 +15,18 @@ namespace Artilleries private int? _pictureHeight = null; private readonly int _artilleryWidth = 80; private readonly int _artilleryHeight = 50; + public DrawingArtillery(int speed, float weight, Color bodyColor) { Artillery = new EntityArtillery(speed, weight, bodyColor); } + + protected DrawingArtillery(int speed, float weight, Color bodyColor, int artilleryWidth, int artilleryHeight) : this(speed, weight, bodyColor) + { + _artilleryWidth = artilleryWidth; + _artilleryHeight = artilleryHeight; + } + public void SetPosition(int x, int y, int width, int height) { if (x < 0 || x + _artilleryWidth >= width) @@ -73,7 +81,7 @@ namespace Artilleries } } - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) { From 0b3de31bdbee336c884c78591a1ecd68630eda47 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, 26 Sep 2022 19:55:09 +0400 Subject: [PATCH 04/10] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9?= =?UTF-8?q?=D1=81=20=D0=B8=20=D0=BF=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD?= =?UTF-8?q?=D1=83=D1=82=D1=8B=D0=B9=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawingAdvancedArtillery.cs | 39 ++++++++++++++++++ .../DrawingArtillery.cs | 19 ++++++--- .../DrawingObjectArtillery.cs | 40 +++++++++++++++++++ .../FormArtillery.Designer.cs | 14 +++++++ SelfPropelledArtilleryUnit/FormArtillery.cs | 28 +++++++++++-- 5 files changed, 130 insertions(+), 10 deletions(-) create mode 100644 SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs create mode 100644 SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs diff --git a/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs b/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs new file mode 100644 index 0000000..1f86d5e --- /dev/null +++ b/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Artilleries +{ + internal class DrawingAdvancedArtillery : DrawingArtillery + { + public DrawingAdvancedArtillery(int speed, float weight, Color bodyColor, Color dopColor, bool weapon, bool salvoBattery) : base(speed, weight, bodyColor, 80, 50) + { + Artillery = new EntityAdvancedArtillery(speed, weight, bodyColor, dopColor, weapon, salvoBattery); + } + + public override void DrawTransport(Graphics g) + { + if (Artillery is not EntityAdvancedArtillery advancedArtillery) + { + return; + } + + Pen pen = new Pen(advancedArtillery.DopColor, 8); + Brush brush = new SolidBrush(advancedArtillery.DopColor); + + if (advancedArtillery.Weapon) + { + g.DrawLine(pen, _startPosX + _artilleryWidth / 2, _startPosY + _artilleryHeight / 10, _startPosX + _artilleryWidth, _startPosY); + } + + if (advancedArtillery.SalvoBattery) + { + + } + + base.DrawTransport(g); + } + } +} diff --git a/SelfPropelledArtilleryUnit/DrawingArtillery.cs b/SelfPropelledArtilleryUnit/DrawingArtillery.cs index 0ef8ae4..ff31752 100644 --- a/SelfPropelledArtilleryUnit/DrawingArtillery.cs +++ b/SelfPropelledArtilleryUnit/DrawingArtillery.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; @@ -8,13 +10,13 @@ namespace Artilleries { internal class DrawingArtillery { - public EntityArtillery Artillery { private set; get; } - private float _startPosX; - private float _startPosY; + public EntityArtillery Artillery { protected set; get; } + protected float _startPosX; + protected float _startPosY; private int? _pictureWidth = null; private int? _pictureHeight = null; - private readonly int _artilleryWidth = 80; - private readonly int _artilleryHeight = 50; + protected readonly int _artilleryWidth = 80; + protected readonly int _artilleryHeight = 50; public DrawingArtillery(int speed, float weight, Color bodyColor) { @@ -88,7 +90,7 @@ namespace Artilleries return; } Brush brush = new SolidBrush(Artillery?.BodyColor ?? Color.Black); - g.FillRectangle(brush, _startPosX + _artilleryWidth / 8 * 2, _startPosY, _artilleryWidth / 8 * 4, _artilleryWidth / 5); + g.FillRectangle(brush, _startPosX + _artilleryWidth / 8 * 2, _startPosY, _artilleryWidth / 8 * 4, _artilleryHeight / 5); g.FillRectangle(brush, _startPosX, _startPosY + _artilleryHeight / 5, _artilleryWidth, _artilleryHeight / 3); Brush blackBrush = new SolidBrush(Color.Black); @@ -121,5 +123,10 @@ namespace Artilleries _startPosY = _pictureHeight.Value - _artilleryHeight; } } + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosX + _artilleryWidth - 1, _startPosY, _startPosY + _artilleryHeight - 1); + } } } diff --git a/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs b/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs new file mode 100644 index 0000000..34133c9 --- /dev/null +++ b/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Artilleries +{ + internal class DrawingObjectArtillery : IDrawningObject + { + private DrawingArtillery _artillery = null; + + public DrawingObjectArtillery(DrawingArtillery artillery) + { + _artillery = artillery; + } + + public float Step => _artillery?.Artillery?.Step ?? 0; + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return _artillery?.GetCurrentPosition() ?? default; + } + + public void MoveObject(Direction direction) + { + _artillery?.MoveTransport(direction); + } + + public void SetObject(int x, int y, int width, int height) + { + _artillery.SetPosition(x, y, width, height); + } + + public void DrawingObject(Graphics g) + { + _artillery.DrawTransport(g); + } + } +} diff --git a/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs b/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs index 04e9c76..24c8c47 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs @@ -39,6 +39,7 @@ 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.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit(); this.SuspendLayout(); @@ -147,11 +148,23 @@ 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(105, 382); + this.createAdvancedButton.Name = "createAdvancedButton"; + this.createAdvancedButton.Size = new System.Drawing.Size(142, 23); + this.createAdvancedButton.TabIndex = 7; + this.createAdvancedButton.Text = "Создать модификацию"; + this.createAdvancedButton.UseVisualStyleBackColor = true; + this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_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.createAdvancedButton); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonUp); @@ -183,5 +196,6 @@ private Button buttonUp; private Button buttonDown; private Button buttonRight; + private Button createAdvancedButton; } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/FormArtillery.cs b/SelfPropelledArtilleryUnit/FormArtillery.cs index 6d8038b..785ba5f 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.cs @@ -17,14 +17,34 @@ namespace Artilleries pictureBoxArtilleries.Image = bmp; } + private void Prepair() + { + 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}"; + Prepair(); + Draw(); + } + + private void createAdvancedButton_Click(object sender, EventArgs e) + { + Random rnd = new(); + _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 + ); + Prepair(); Draw(); } From cf030e5d6b058c8d441db1071f66de816a29a096 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, 26 Sep 2022 20:23:23 +0400 Subject: [PATCH 05/10] =?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=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs b/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs index 1f86d5e..ae60223 100644 --- a/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs +++ b/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.AccessControl; using System.Text; using System.Threading.Tasks; @@ -27,10 +28,12 @@ namespace Artilleries { g.DrawLine(pen, _startPosX + _artilleryWidth / 2, _startPosY + _artilleryHeight / 10, _startPosX + _artilleryWidth, _startPosY); } - + pen.Width = 6; if (advancedArtillery.SalvoBattery) { - + g.DrawLine(pen, _startPosX + _artilleryWidth / 4, _startPosY + _artilleryHeight / 4, _startPosX + _artilleryWidth / 4 + _artilleryHeight / 4, _startPosY - 5); + g.DrawLine(pen, _startPosX + _artilleryWidth / 4 - _artilleryHeight / 4, _startPosY + _artilleryHeight / 4, _startPosX + _artilleryWidth / 4, _startPosY - 5); + g.DrawLine(pen, _startPosX + _artilleryWidth / 4 - _artilleryHeight / 2, _startPosY + _artilleryHeight / 4, _startPosX + _artilleryWidth / 4 - _artilleryHeight / 4, _startPosY - 5); } base.DrawTransport(g); From e84730b951fecf70f39d87a6cf5a0937d89cb726 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, 26 Sep 2022 20:56:35 +0400 Subject: [PATCH 06/10] =?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=D1=8F=20=D0=B8=20=D0=B0=D0=B1=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D0=BA=D1=82=D0=BD=D0=B0=D1=8F=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/AbstractMap.cs | 84 +++++++++++++++++++ SelfPropelledArtilleryUnit/FormArtillery.cs | 6 +- .../{IDrawningObject.cs => IDrawingObject.cs} | 2 +- 3 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 SelfPropelledArtilleryUnit/AbstractMap.cs rename SelfPropelledArtilleryUnit/{IDrawningObject.cs => IDrawingObject.cs} (91%) diff --git a/SelfPropelledArtilleryUnit/AbstractMap.cs b/SelfPropelledArtilleryUnit/AbstractMap.cs new file mode 100644 index 0000000..4d24792 --- /dev/null +++ b/SelfPropelledArtilleryUnit/AbstractMap.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Artilleries +{ + internal abstract class AbstractMap + { + private IDrawingObject _drawingObject = null; + protected int[,] _map = null; + protected int _width; + protected int _height; + protected float _size_x; + protected float _size_y; + protected readonly Random _random = new Random(); + protected readonly int _freeRoad = 0; + protected readonly int _barrier = 1; + + public Bitmap CreateMap(int width, int height, IDrawingObject drawingObject) + { + _width = width; + _height = height; + _drawingObject = drawingObject; + do + { + GenerateMap(); + } + while (!SetObjectOnMap()); + return DrawMapWithObject(); + } + + public Bitmap MoveObject(Direction direction) + { + // TODO доделать коллизию + _drawingObject.MoveObject(direction); + return DrawMapWithObject(); + } + + private bool SetObjectOnMap() + { + if (_drawingObject == null || _map == null) + { + return false; + } + + int x = _random.Next(0, 10); + int y = _random.Next(0, 10); + _drawingObject.SetObject(x, y, _width, _height); + // TODO проверка на налажение + return true; + } + + private Bitmap DrawMapWithObject() + { + Bitmap bmp = new Bitmap(_width, _height); + if (_drawingObject == null || _map == null) + { + return bmp; + } + Graphics g = Graphics.FromImage(bmp); + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + if (_map[i, j] == _freeRoad) + { + DrawRoadPart(g, i, j); + } else if (_map[i, j] == _barrier) + { + DrawBarrierPart(g, i, j); + } + } + } + _drawingObject.DrawingObject(g); + return bmp; + } + + protected abstract void GenerateMap(); + protected abstract void DrawRoadPart(Graphics g, int i, int j); + protected abstract void DrawBarrierPart(Graphics g, int i, int j); + } +} diff --git a/SelfPropelledArtilleryUnit/FormArtillery.cs b/SelfPropelledArtilleryUnit/FormArtillery.cs index 785ba5f..dbdbc43 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.cs @@ -17,7 +17,7 @@ namespace Artilleries pictureBoxArtilleries.Image = bmp; } - private void Prepair() + private void SetData() { Random rnd = new(); _artillery.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxArtilleries.Width, pictureBoxArtilleries.Height); @@ -30,7 +30,7 @@ namespace Artilleries { 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))); - Prepair(); + SetData(); Draw(); } @@ -44,7 +44,7 @@ namespace Artilleries Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)), rnd.Next(0, 2) == 1, rnd.Next(0, 2) == 1 ); - Prepair(); + SetData(); Draw(); } diff --git a/SelfPropelledArtilleryUnit/IDrawningObject.cs b/SelfPropelledArtilleryUnit/IDrawingObject.cs similarity index 91% rename from SelfPropelledArtilleryUnit/IDrawningObject.cs rename to SelfPropelledArtilleryUnit/IDrawingObject.cs index 67cae91..4f7acc3 100644 --- a/SelfPropelledArtilleryUnit/IDrawningObject.cs +++ b/SelfPropelledArtilleryUnit/IDrawingObject.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Artilleries { - internal interface IDrawningObject + internal interface IDrawingObject { public float Step { get; } void SetObject(int x, int y, int width, int height); From a97a85a7a2c89318492ddbe4f366a90ad8f5333c 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, 26 Sep 2022 21:05:31 +0400 Subject: [PATCH 07/10] =?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=BF=D1=80=D0=BE=D1=81=D1=82=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=BA=D0=B0=D1=80=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/SimpleMap.cs | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 SelfPropelledArtilleryUnit/SimpleMap.cs diff --git a/SelfPropelledArtilleryUnit/SimpleMap.cs b/SelfPropelledArtilleryUnit/SimpleMap.cs new file mode 100644 index 0000000..2240c46 --- /dev/null +++ b/SelfPropelledArtilleryUnit/SimpleMap.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Artilleries +{ + internal class SimpleMap : AbstractMap + { + private readonly Brush barrierColor = new SolidBrush(Color.Black); + private readonly Brush roadColor = new SolidBrush(Color.Gray); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void GenerateMap() + { + _map = new int[100, 100]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 50) + { + int x = _random.Next(0, 100); + int y = _random.Next(0, 100); + if (_map[x, y] == _freeRoad) + { + _map[x, y] = _barrier; + counter++; + } + } + } + } +} From 5de212b4342e32b151682261a9d0658c05f602b5 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, 26 Sep 2022 22:02:22 +0400 Subject: [PATCH 08/10] =?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/Direction.cs | 3 +- .../DrawingObjectArtillery.cs | 2 +- .../FormArtillery.Designer.cs | 14 -- SelfPropelledArtilleryUnit/FormArtillery.cs | 28 +-- .../FormMap.Designer.cs | 207 ++++++++++++++++++ SelfPropelledArtilleryUnit/FormMap.cs | 85 +++++++ SelfPropelledArtilleryUnit/FormMap.resx | 63 ++++++ SelfPropelledArtilleryUnit/Program.cs | 2 +- 8 files changed, 363 insertions(+), 41 deletions(-) create mode 100644 SelfPropelledArtilleryUnit/FormMap.Designer.cs create mode 100644 SelfPropelledArtilleryUnit/FormMap.cs create mode 100644 SelfPropelledArtilleryUnit/FormMap.resx diff --git a/SelfPropelledArtilleryUnit/Direction.cs b/SelfPropelledArtilleryUnit/Direction.cs index 8d54af8..00b7082 100644 --- a/SelfPropelledArtilleryUnit/Direction.cs +++ b/SelfPropelledArtilleryUnit/Direction.cs @@ -11,6 +11,7 @@ namespace Artilleries Up = 1, Down = 2, Left = 3, - Right = 4 + Right = 4, + None } } diff --git a/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs b/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs index 34133c9..7efa81c 100644 --- a/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs +++ b/SelfPropelledArtilleryUnit/DrawingObjectArtillery.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Artilleries { - internal class DrawingObjectArtillery : IDrawningObject + internal class DrawingObjectArtillery : IDrawingObject { private DrawingArtillery _artillery = null; diff --git a/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs b/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs index 24c8c47..04e9c76 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.Designer.cs @@ -39,7 +39,6 @@ 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.statusStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit(); this.SuspendLayout(); @@ -148,23 +147,11 @@ 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(105, 382); - this.createAdvancedButton.Name = "createAdvancedButton"; - this.createAdvancedButton.Size = new System.Drawing.Size(142, 23); - this.createAdvancedButton.TabIndex = 7; - this.createAdvancedButton.Text = "Создать модификацию"; - this.createAdvancedButton.UseVisualStyleBackColor = true; - this.createAdvancedButton.Click += new System.EventHandler(this.createAdvancedButton_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.createAdvancedButton); this.Controls.Add(this.buttonRight); this.Controls.Add(this.buttonDown); this.Controls.Add(this.buttonUp); @@ -196,6 +183,5 @@ private Button buttonUp; private Button buttonDown; private Button buttonRight; - private Button createAdvancedButton; } } \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/FormArtillery.cs b/SelfPropelledArtilleryUnit/FormArtillery.cs index dbdbc43..56fe28f 100644 --- a/SelfPropelledArtilleryUnit/FormArtillery.cs +++ b/SelfPropelledArtilleryUnit/FormArtillery.cs @@ -17,34 +17,14 @@ namespace Artilleries pictureBoxArtilleries.Image = bmp; } - private void SetData() - { - 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))); - SetData(); - Draw(); - } - - private void createAdvancedButton_Click(object sender, EventArgs e) - { - Random rnd = new(); - _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.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}"; Draw(); } diff --git a/SelfPropelledArtilleryUnit/FormMap.Designer.cs b/SelfPropelledArtilleryUnit/FormMap.Designer.cs new file mode 100644 index 0000000..c44fd36 --- /dev/null +++ b/SelfPropelledArtilleryUnit/FormMap.Designer.cs @@ -0,0 +1,207 @@ +namespace Artilleries +{ + partial class FormMap + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.createAdvancedButton = new System.Windows.Forms.Button(); + 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(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).BeginInit(); + this.statusStrip1.SuspendLayout(); + this.SuspendLayout(); + // + // 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(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); + // + // 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(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); + // + // 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(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); + // + // 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(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); + // + // 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(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); + // + // buttonCreate + // + 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 = "Цвет:"; + // + // comboBoxSelectorMap + // + this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.comboBoxSelectorMap.FormattingEnabled = true; + this.comboBoxSelectorMap.Items.AddRange(new object[] { + "Простая карта"}); + this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); + this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; + this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); + this.comboBoxSelectorMap.TabIndex = 16; + this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.comboBoxSelectorMap_SelectedIndexChanged); + // + // FormMap + // + 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.Controls.Add(this.pictureBoxArtilleries); + this.Controls.Add(this.statusStrip1); + this.Name = "FormMap"; + this.Text = "Artillery"; + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxArtilleries)).EndInit(); + this.statusStrip1.ResumeLayout(false); + this.statusStrip1.PerformLayout(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Button createAdvancedButton; + 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; + } +} \ No newline at end of file diff --git a/SelfPropelledArtilleryUnit/FormMap.cs b/SelfPropelledArtilleryUnit/FormMap.cs new file mode 100644 index 0000000..daa8dce --- /dev/null +++ b/SelfPropelledArtilleryUnit/FormMap.cs @@ -0,0 +1,85 @@ +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; + } + } + } +} diff --git a/SelfPropelledArtilleryUnit/FormMap.resx b/SelfPropelledArtilleryUnit/FormMap.resx new file mode 100644 index 0000000..5cb320f --- /dev/null +++ b/SelfPropelledArtilleryUnit/FormMap.resx @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 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/Program.cs b/SelfPropelledArtilleryUnit/Program.cs index e993022..2b37e99 100644 --- a/SelfPropelledArtilleryUnit/Program.cs +++ b/SelfPropelledArtilleryUnit/Program.cs @@ -6,7 +6,7 @@ namespace Artilleries static void Main() { ApplicationConfiguration.Initialize(); - Application.Run(new FormArtillery()); + Application.Run(new FormMap()); } } } \ No newline at end of file From ceea6b50107446615a04e1f7d7651583f35714d4 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, 26 Sep 2022 23:12:22 +0400 Subject: [PATCH 09/10] =?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=BB=D0=B5=D1=81=D0=BD=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BA=D0=B0=D1=80=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/AbstractMap.cs | 52 ++++++++++++++++-- SelfPropelledArtilleryUnit/ForestMap.cs | 53 +++++++++++++++++++ .../FormMap.Designer.cs | 3 +- SelfPropelledArtilleryUnit/FormMap.cs | 3 ++ 4 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 SelfPropelledArtilleryUnit/ForestMap.cs diff --git a/SelfPropelledArtilleryUnit/AbstractMap.cs b/SelfPropelledArtilleryUnit/AbstractMap.cs index 4d24792..410f259 100644 --- a/SelfPropelledArtilleryUnit/AbstractMap.cs +++ b/SelfPropelledArtilleryUnit/AbstractMap.cs @@ -33,8 +33,25 @@ namespace Artilleries public Bitmap MoveObject(Direction direction) { - // TODO доделать коллизию _drawingObject.MoveObject(direction); + if (ObjectIntersects()) + { + switch (direction) + { + case Direction.Left: + _drawingObject.MoveObject(Direction.Right); + break; + case Direction.Right: + _drawingObject.MoveObject(Direction.Left); + break; + case Direction.Up: + _drawingObject.MoveObject(Direction.Down); + break; + case Direction.Down: + _drawingObject.MoveObject(Direction.Up); + break; + } + } return DrawMapWithObject(); } @@ -45,13 +62,38 @@ namespace Artilleries return false; } - int x = _random.Next(0, 10); - int y = _random.Next(0, 10); - _drawingObject.SetObject(x, y, _width, _height); - // TODO проверка на налажение + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + _drawingObject.SetObject((int) (i * _size_x), (int) (j * _size_y), _width, _height); + if (!ObjectIntersects()) return true; + } + } + return true; } + private bool ObjectIntersects() + { + var location = _drawingObject.GetCurrentPosition(); + for (int i = 0; i < _map.GetLength(0); i++) + { + for (int j = 0; j < _map.GetLength(1); j++) + { + if (_map[i, j] == _barrier) + { + if (i * _size_x >= location.Left && (i + 1) * _size_x <= location.Right && j * _size_y >= location.Top && (j + 1) * _size_y <= location.Bottom) + { + return true; + } + } + } + } + + return false; + } + private Bitmap DrawMapWithObject() { Bitmap bmp = new Bitmap(_width, _height); diff --git a/SelfPropelledArtilleryUnit/ForestMap.cs b/SelfPropelledArtilleryUnit/ForestMap.cs new file mode 100644 index 0000000..667c452 --- /dev/null +++ b/SelfPropelledArtilleryUnit/ForestMap.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Artilleries +{ + internal class ForestMap : AbstractMap + { + private readonly Brush barrierColor = new SolidBrush(Color.Green); + private readonly Brush roadColor = new SolidBrush(Color.Brown); + protected override void DrawBarrierPart(Graphics g, int i, int j) + { + g.FillRectangle(barrierColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void DrawRoadPart(Graphics g, int i, int j) + { + g.FillRectangle(roadColor, i * _size_x, j * _size_y, i * (_size_x + 1), j * (_size_y + 1)); + } + protected override void GenerateMap() + { + _map = new int[50, 50]; + _size_x = (float)_width / _map.GetLength(0); + _size_y = (float)_height / _map.GetLength(1); + int counter = 0; + for (int i = 0; i < _map.GetLength(0); ++i) + { + for (int j = 0; j < _map.GetLength(1); ++j) + { + _map[i, j] = _freeRoad; + } + } + while (counter < 20) + { + int x = _random.Next(2, 49); + int y = _random.Next(3, 50); + var points = new int[] { _map[x, y], _map[x, y - 1], _map[x, y - 2], _map[x - 1, y - 2], _map[x + 1, y - 2], _map[x, y - 3] }; + var forComparison = new int[] { _freeRoad, _freeRoad, _freeRoad, _freeRoad, _freeRoad, _freeRoad }; + if (points.SequenceEqual(forComparison)) + { + _map[x, y] = _barrier; + _map[x, y - 1] = _barrier; + _map[x, y - 2] = _barrier; + _map[x - 1, y - 2] = _barrier; + _map[x + 1, y - 2] = _barrier; + _map[x, y - 3] = _barrier; + counter++; + } + } + } + } +} diff --git a/SelfPropelledArtilleryUnit/FormMap.Designer.cs b/SelfPropelledArtilleryUnit/FormMap.Designer.cs index c44fd36..61dcc5c 100644 --- a/SelfPropelledArtilleryUnit/FormMap.Designer.cs +++ b/SelfPropelledArtilleryUnit/FormMap.Designer.cs @@ -158,7 +158,8 @@ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBoxSelectorMap.FormattingEnabled = true; this.comboBoxSelectorMap.Items.AddRange(new object[] { - "Простая карта"}); + "Простая карта", + "Лесная карта"}); this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12); this.comboBoxSelectorMap.Name = "comboBoxSelectorMap"; this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23); diff --git a/SelfPropelledArtilleryUnit/FormMap.cs b/SelfPropelledArtilleryUnit/FormMap.cs index daa8dce..016c4bc 100644 --- a/SelfPropelledArtilleryUnit/FormMap.cs +++ b/SelfPropelledArtilleryUnit/FormMap.cs @@ -79,6 +79,9 @@ namespace Artilleries case "Простая карта": _abstractMap = new SimpleMap(); break; + case "Лесная карта": + _abstractMap = new ForestMap(); + break; } } } From 396df2c24c83c10152564bdeda1d465169a00dd3 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, 26 Sep 2022 23:57:25 +0400 Subject: [PATCH 10/10] =?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=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SelfPropelledArtilleryUnit/AbstractMap.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SelfPropelledArtilleryUnit/AbstractMap.cs b/SelfPropelledArtilleryUnit/AbstractMap.cs index 410f259..ac916bb 100644 --- a/SelfPropelledArtilleryUnit/AbstractMap.cs +++ b/SelfPropelledArtilleryUnit/AbstractMap.cs @@ -62,9 +62,9 @@ namespace Artilleries return false; } - for (int i = 0; i < _map.GetLength(0); i++) + for (int i = 2; i < _map.GetLength(0); i++) { - for (int j = 0; j < _map.GetLength(1); j++) + for (int j = 2; j < _map.GetLength(1); j++) { _drawingObject.SetObject((int) (i * _size_x), (int) (j * _size_y), _width, _height); if (!ObjectIntersects()) return true;