diff --git a/SelfPropelledArtilleryUnit/AbstractMap.cs b/SelfPropelledArtilleryUnit/AbstractMap.cs
new file mode 100644
index 0000000..ac916bb
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/AbstractMap.cs
@@ -0,0 +1,126 @@
+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)
+ {
+ _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();
+ }
+
+ private bool SetObjectOnMap()
+ {
+ if (_drawingObject == null || _map == null)
+ {
+ return false;
+ }
+
+ for (int i = 2; i < _map.GetLength(0); i++)
+ {
+ 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;
+ }
+ }
+
+ 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);
+ 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/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/DrawingAdvancedArtillery.cs b/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs
new file mode 100644
index 0000000..ae60223
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/DrawingAdvancedArtillery.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.AccessControl;
+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);
+ }
+ 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);
+ }
+ }
+}
diff --git a/SelfPropelledArtilleryUnit/DrawingArtillery.cs b/SelfPropelledArtilleryUnit/DrawingArtillery.cs
index bc793c4..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,18 +10,25 @@ 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;
- public void Init(int speed, float weight, Color bodyColor)
+ protected readonly int _artilleryWidth = 80;
+ protected readonly int _artilleryHeight = 50;
+
+ public DrawingArtillery(int speed, float weight, Color bodyColor)
{
- Artillery = new EntityArtillery();
- Artillery.Init(speed, weight, 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)
@@ -74,14 +83,14 @@ namespace Artilleries
}
}
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue)
{
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);
@@ -114,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..7efa81c
--- /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 : IDrawingObject
+ {
+ 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/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/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/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/FormArtillery.cs b/SelfPropelledArtilleryUnit/FormArtillery.cs
index 718c34a..56fe28f 100644
--- a/SelfPropelledArtilleryUnit/FormArtillery.cs
+++ b/SelfPropelledArtilleryUnit/FormArtillery.cs
@@ -20,12 +20,11 @@ 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);
- SpeedStatusLabel.Text = $"Скорость: {_artillery.Artillery.Speed}";
- WeightStatusLabel.Text = $"Вес: {_artillery.Artillery.Weight}";
- ColorStatusLabel.Text = $"Цвет: {_artillery.Artillery.BodyColor.Name}";
+ _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}";
Draw();
}
diff --git a/SelfPropelledArtilleryUnit/FormMap.Designer.cs b/SelfPropelledArtilleryUnit/FormMap.Designer.cs
new file mode 100644
index 0000000..61dcc5c
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/FormMap.Designer.cs
@@ -0,0 +1,208 @@
+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..016c4bc
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/FormMap.cs
@@ -0,0 +1,88 @@
+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.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/IDrawingObject.cs b/SelfPropelledArtilleryUnit/IDrawingObject.cs
new file mode 100644
index 0000000..4f7acc3
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/IDrawingObject.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 IDrawingObject
+ {
+ 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();
+ }
+}
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
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++;
+ }
+ }
+ }
+ }
+}