diff --git a/ProjectMachine/ProjectMachine/AbstractMap.cs b/ProjectMachine/ProjectMachine/AbstractMap.cs
new file mode 100644
index 0000000..02e3c4c
--- /dev/null
+++ b/ProjectMachine/ProjectMachine/AbstractMap.cs
@@ -0,0 +1,160 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectMachine
+{
+ internal abstract class AbstractMap
+ {
+ private IDrawningObject _drawningObject = null;
+ protected int[,] _map = null;
+ protected int _width;
+ protected int _height;
+ protected float _size_x;
+ protected float _size_y;
+ protected readonly Random _random = new();
+ protected readonly int _freeRoad = 0;
+ protected readonly int _barrier = 1;
+
+ public Bitmap CreateMap(int width, int height, IDrawningObject drawningObject)
+ {
+ _width = width;
+ _height = height;
+ _drawningObject = drawningObject;
+ GenerateMap();
+ while (!SetObjectOnMap())
+ {
+ GenerateMap();
+ }
+ return DrawMapWithObject();
+ }
+
+ public (int LeftCoord, int TopCoord, int RightCoord, int BottomCoord) GetCoord()
+ {
+ return ((int)(_drawningObject.GetCurrentPosition().Left / _size_x), (int)(_drawningObject.GetCurrentPosition().Top / _size_y), (int)(_drawningObject.GetCurrentPosition().Right / _size_x), (int)(_drawningObject.GetCurrentPosition().Bottom / _size_y));
+ }
+
+ public bool CheckMove(Direction dir)
+ {
+ switch (dir)
+ {
+ case Direction.Left:
+ if (GetCoord().LeftCoord <= 0)
+ {
+ return false;
+ }
+ break;
+ case Direction.Right:
+ if (GetCoord().RightCoord + 1 > _map.GetLength(1))
+ {
+ return false;
+ }
+ break;
+ case Direction.Up:
+ if (GetCoord().TopCoord <= 0)
+ {
+ return false;
+ }
+ break;
+ case (Direction.Down):
+ if (GetCoord().BottomCoord -1 > _map.GetLength(0))
+ {
+ return false;
+ }
+ break;
+ }
+ switch (dir)
+ {
+ case Direction.Left:
+ for (int i = GetCoord().TopCoord; i <= GetCoord().BottomCoord; i++)
+ {
+ if (_map[GetCoord().LeftCoord - (int)((_drawningObject.Step) / _size_x) - 1, i] == _barrier)
+ return false;
+ }
+ break;
+ case Direction.Right:
+ for (int i = GetCoord().TopCoord; i < GetCoord().BottomCoord; i++)
+ {
+ if (_map[GetCoord().RightCoord + (int)((_drawningObject.Step) / _size_x) + 1, i] == _barrier)
+ return false;
+ }
+ break;
+ case Direction.Up:
+ for (int i = GetCoord().LeftCoord; i < GetCoord().RightCoord; i++)
+ {
+ if (_map[i, GetCoord().TopCoord - (int)((_drawningObject.Step) / _size_y) - 1] == _barrier)
+ return false;
+ }
+ break;
+ case Direction.Down:
+ for (int i = GetCoord().LeftCoord; i < GetCoord().RightCoord; i++)
+ {
+ if (_map[i, GetCoord().BottomCoord + (int)((_drawningObject.Step) / _size_y) + 1] == _barrier)
+ return false;
+ }
+ break;
+ }
+ return true;
+ }
+ public Bitmap MoveObject(Direction direction)
+ {
+ if (CheckMove(direction))
+ {
+ _drawningObject.MoveObject(direction);
+ }
+ return DrawMapWithObject();
+ }
+ private bool SetObjectOnMap()
+ {
+ if (_drawningObject == null || _map == null)
+ {
+ return false;
+ }
+ int x = _random.Next(0, 10);
+ int y = _random.Next(0, 10);
+ _drawningObject.SetObject(x, y, _width, _height);
+ for (int i = GetCoord().LeftCoord; i <= GetCoord().RightCoord; i++)
+ {
+ for (int j = GetCoord().TopCoord; j <= GetCoord().BottomCoord; j++)
+ {
+ if (_map[i, j] == _barrier)
+ {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ private Bitmap DrawMapWithObject()
+ {
+ Bitmap bmp = new(_width, _height);
+ if (_drawningObject == null || _map == null)
+ {
+ return bmp;
+ }
+ Graphics gr = 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(gr, i, j);
+ }
+ else if (_map[i, j] == _barrier)
+ {
+ DrawBarrierPart(gr, i, j);
+ }
+ }
+ }
+ _drawningObject.DrawningObject(gr);
+ 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);
+ }
+}
\ No newline at end of file
diff --git a/ProjectMachine/ProjectMachine/Direction.cs b/ProjectMachine/ProjectMachine/Direction.cs
index a6156bc..9688957 100644
--- a/ProjectMachine/ProjectMachine/Direction.cs
+++ b/ProjectMachine/ProjectMachine/Direction.cs
@@ -11,6 +11,7 @@ namespace ProjectMachine
///
internal enum Direction
{
+ None = 0,
Up = 1,
Down = 2,
Left = 3,
diff --git a/ProjectMachine/ProjectMachine/DrawningMachine.cs b/ProjectMachine/ProjectMachine/DrawningMachine.cs
index 4ece1c0..b7ab6f2 100644
--- a/ProjectMachine/ProjectMachine/DrawningMachine.cs
+++ b/ProjectMachine/ProjectMachine/DrawningMachine.cs
@@ -14,15 +14,15 @@ namespace ProjectMachine
///
/// Класс-сущность
///
- public EntityMachine Machine { get; private set; }
+ public EntityMachine Machine { get; protected set; }
///
/// Левая координата отрисовки машины
///
- private float _startPosX;
+ protected float _startPosX;
///
/// Верхняя кооридната отрисовки машины
///
- private float _startPosY;
+ protected float _startPosY;
///
/// Ширина окна отрисовки
///
@@ -45,10 +45,9 @@ namespace ProjectMachine
/// Скорость
/// Вес автомобиля
/// Цвет кузова
- public void Init(int speed, float weight, Color bodyColor)
+ public DrawningMachine(int speed, float weight, Color bodyColor)
{
- Machine = new EntityMachine();
- Machine.Init(speed, weight, bodyColor);
+ Machine = new EntityMachine(speed, weight, bodyColor);
}
///
/// Установка позиции машины
@@ -57,6 +56,13 @@ namespace ProjectMachine
/// Координата Y
/// Ширина картинки
/// Высота картинки
+ protected DrawningMachine(int speed, float weight, Color bodyColor, int machineWidth, int machineHeight) :
+ this(speed, weight, bodyColor)
+ {
+ _machineWidth = machineWidth;
+ _machineHeight = machineHeight;
+ }
+
public void SetPosition(int x, int y, int width, int height)
{
if (x < 0 || y < 0 || x + _machineWidth > width || y + _machineHeight > height)
@@ -114,7 +120,7 @@ namespace ProjectMachine
/// Отрисовка машины
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (_startPosX < 0 || _startPosY < 0
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
@@ -163,5 +169,13 @@ namespace ProjectMachine
_startPosY = _pictureHeight.Value - _machineHeight;
}
}
+ ///
+ /// Получение текущей позиции объекта
+ ///
+ ///
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return (_startPosX, _startPosX + _machineWidth, _startPosY, _startPosY + _machineHeight);
+ }
}
}
diff --git a/ProjectMachine/ProjectMachine/DrawningObject.cs b/ProjectMachine/ProjectMachine/DrawningObject.cs
new file mode 100644
index 0000000..64d03d3
--- /dev/null
+++ b/ProjectMachine/ProjectMachine/DrawningObject.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectMachine
+{
+ internal class DrawningObject : IDrawningObject
+ {
+ private DrawningMachine _machine = null;
+
+ public DrawningObject(DrawningMachine machine)
+ {
+ _machine = machine;
+ }
+
+ public float Step => _machine?.Machine?.Step ?? 0;
+
+ public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
+ {
+ return _machine?.GetCurrentPosition() ?? default;
+ }
+
+ public void MoveObject(Direction direction)
+ {
+ _machine?.MoveTransport(direction);
+ }
+
+ public void SetObject(int x, int y, int width, int height)
+ {
+ _machine.SetPosition(x, y, width, height);
+ }
+
+ void IDrawningObject.DrawningObject(Graphics g)
+ {
+ _machine.DrawTransport(g);
+ }
+ }
+}
diff --git a/ProjectMachine/ProjectMachine/DrawningTank.cs b/ProjectMachine/ProjectMachine/DrawningTank.cs
new file mode 100644
index 0000000..9b54b99
--- /dev/null
+++ b/ProjectMachine/ProjectMachine/DrawningTank.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectMachine
+{
+ internal class DrawningTank : DrawningMachine
+ {
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// Признак наличия башни с орудием
+ /// Признак наличия зенитного пулемета
+ public DrawningTank(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool turret, bool gun) :
+ base(speed, weight, bodyColor, 90, 50)
+ {
+ Machine = new EntityTank(speed, weight, bodyColor, dopColor, bodyKit, turret, gun);
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (Machine is not EntityTank tank)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush dopBrush = new SolidBrush(tank.DopColor);
+
+ if (tank.Turret)
+ {
+ g.FillRectangle(dopBrush, _startPosX + 45, _startPosY, 20, 10);
+ g.DrawLine(pen, _startPosX + 65, _startPosY + 2, _startPosX + 85, _startPosY + 2);
+ }
+
+ if (tank.Gun)
+ {
+ g.FillRectangle(dopBrush, _startPosX + 23, _startPosY + 4, 3, 11);
+ g.DrawLine(pen, _startPosX + 23, _startPosY + 8, _startPosX + 5, _startPosY + 8);
+ }
+
+ _startPosX += 10;
+ _startPosY += 5;
+ base.DrawTransport(g);
+ _startPosX -= 10;
+ _startPosY -= 5;
+ }
+ }
+}
diff --git a/ProjectMachine/ProjectMachine/EntityMachine.cs b/ProjectMachine/ProjectMachine/EntityMachine.cs
index 2394f7e..d3266a0 100644
--- a/ProjectMachine/ProjectMachine/EntityMachine.cs
+++ b/ProjectMachine/ProjectMachine/EntityMachine.cs
@@ -34,7 +34,7 @@ namespace ProjectMachine
///
///
///
- public void Init(int speed, float weight, Color bodyColor)
+ public EntityMachine(int speed, float weight, Color bodyColor)
{
Random rnd = new();
Speed = speed <= 0 ? rnd.Next(50, 150) : speed;
diff --git a/ProjectMachine/ProjectMachine/EntityTank.cs b/ProjectMachine/ProjectMachine/EntityTank.cs
new file mode 100644
index 0000000..342293a
--- /dev/null
+++ b/ProjectMachine/ProjectMachine/EntityTank.cs
@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectMachine
+{
+ ///
+ /// Класс-сущность "Танк"
+ ///
+ internal class EntityTank : EntityMachine
+ {
+ ///
+ /// Дополнительный цвет
+ ///
+ public Color DopColor { get; private set; }
+ ///
+ /// Признак наличия обвеса
+ ///
+ public bool BodyKit { get; private set; }
+ ///
+ /// Признак наличия башни с орудием
+ ///
+ public bool Turret { get; private set; }
+ ///
+ /// Признак наличия зенитного пулемета
+ ///
+ public bool Gun { get; private set; }
+ ///
+ /// Инициализация свойств
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Цвет кузова
+ /// Дополнительный цвет
+ /// /// Признак наличия обвеса
+ /// Признак наличия башни с орудием
+ /// Признак наличия зенитного пулемета
+ public EntityTank(int speed, float weight, Color bodyColor, Color dopColor, bool bodyKit, bool turret, bool gun) :
+ base(speed, weight, bodyColor)
+ {
+ DopColor = dopColor;
+ BodyKit = bodyKit;
+ Turret = turret;
+ Gun = gun;
+ }
+
+ }
+}
diff --git a/ProjectMachine/ProjectMachine/FormMachine.Designer.cs b/ProjectMachine/ProjectMachine/FormMachine.Designer.cs
index 5ed5e6b..f7e8390 100644
--- a/ProjectMachine/ProjectMachine/FormMachine.Designer.cs
+++ b/ProjectMachine/ProjectMachine/FormMachine.Designer.cs
@@ -38,6 +38,7 @@
this.buttonRight = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxMachine)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@@ -148,11 +149,22 @@
this.buttonLeft.UseVisualStyleBackColor = true;
this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
//
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Location = new System.Drawing.Point(124, 385);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(130, 29);
+ this.buttonCreateModif.TabIndex = 7;
+ this.buttonCreateModif.Text = "Модификация";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
// FormMachine
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(733, 453);
+ this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
@@ -182,5 +194,6 @@
private Button buttonRight;
private Button buttonUp;
private Button buttonLeft;
+ private Button buttonCreateModif;
}
}
\ No newline at end of file
diff --git a/ProjectMachine/ProjectMachine/FormMachine.cs b/ProjectMachine/ProjectMachine/FormMachine.cs
index 3b402e7..8973582 100644
--- a/ProjectMachine/ProjectMachine/FormMachine.cs
+++ b/ProjectMachine/ProjectMachine/FormMachine.cs
@@ -19,6 +19,17 @@ namespace ProjectMachine
pictureBoxMachine.Image = bmp;
}
///
+ ///
+ ///
+ private void SetData()
+ {
+ Random rnd = new();
+ _machine.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxMachine.Width, pictureBoxMachine.Height);
+ toolStripStatusLabelSpeed.Text = $": {_machine.Machine.Speed}";
+ toolStripStatusLabelWeight.Text = $": {_machine.Machine.Weight}";
+ toolStripStatusLabelBodyColor.Text = $": {_machine.Machine.BodyColor.Name}";
+ }
+ ///
/// ""
///
///
@@ -26,12 +37,8 @@ namespace ProjectMachine
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _machine = new DrawningMachine();
- _machine.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- _machine.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxMachine.Width, pictureBoxMachine.Height);
- toolStripStatusLabelSpeed.Text = $": {_machine.Machine.Speed}";
- toolStripStatusLabelWeight.Text = $": {_machine.Machine.Weight}";
- toolStripStatusLabelBodyColor.Text = $": {_machine.Machine.BodyColor.Name}";
+ _machine = new DrawningMachine(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData();
Draw();
}
///
@@ -70,5 +77,17 @@ namespace ProjectMachine
_machine?.ChangeBorders(pictureBoxMachine.Width, pictureBoxMachine.Height);
Draw();
}
+ ///
+ /// ""
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ _machine = new DrawningTank(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)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
+ SetData();
+ Draw();
+ }
}
}
\ No newline at end of file
diff --git a/ProjectMachine/ProjectMachine/FormMachine.resx b/ProjectMachine/ProjectMachine/FormMachine.resx
index 5cb320f..87c950d 100644
--- a/ProjectMachine/ProjectMachine/FormMachine.resx
+++ b/ProjectMachine/ProjectMachine/FormMachine.resx
@@ -60,4 +60,7 @@
17, 17
+
+ 36
+
\ No newline at end of file
diff --git a/ProjectMachine/ProjectMachine/FormMap.Designer.cs b/ProjectMachine/ProjectMachine/FormMap.Designer.cs
new file mode 100644
index 0000000..a4d9ad3
--- /dev/null
+++ b/ProjectMachine/ProjectMachine/FormMap.Designer.cs
@@ -0,0 +1,215 @@
+namespace ProjectMachine
+{
+ 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.pictureBoxMachine = new System.Windows.Forms.PictureBox();
+ this.statusStrip1 = new System.Windows.Forms.StatusStrip();
+ this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
+ this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
+ this.ButtonCreate = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonCreateModif = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxMachine)).BeginInit();
+ this.statusStrip1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // pictureBoxMachine
+ //
+ this.pictureBoxMachine.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxMachine.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxMachine.MinimumSize = new System.Drawing.Size(1, 1);
+ this.pictureBoxMachine.Name = "pictureBoxMachine";
+ this.pictureBoxMachine.Size = new System.Drawing.Size(732, 441);
+ this.pictureBoxMachine.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBoxMachine.TabIndex = 0;
+ this.pictureBoxMachine.TabStop = false;
+ //
+ // statusStrip1
+ //
+ this.statusStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.toolStripStatusLabelSpeed,
+ this.toolStripStatusLabelWeight,
+ this.toolStripStatusLabelBodyColor});
+ this.statusStrip1.Location = new System.Drawing.Point(0, 441);
+ this.statusStrip1.Name = "statusStrip1";
+ this.statusStrip1.Size = new System.Drawing.Size(732, 26);
+ this.statusStrip1.TabIndex = 1;
+ this.statusStrip1.Text = "statusStrip1";
+ //
+ // toolStripStatusLabelSpeed
+ //
+ this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
+ this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(76, 20);
+ this.toolStripStatusLabelSpeed.Text = "Скорость:";
+ //
+ // toolStripStatusLabelWeight
+ //
+ this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
+ this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(36, 20);
+ this.toolStripStatusLabelWeight.Text = "Вес:";
+ //
+ // toolStripStatusLabelBodyColor
+ //
+ this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
+ this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(45, 20);
+ this.toolStripStatusLabelBodyColor.Text = "Цвет:";
+ //
+ // 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, 385);
+ this.ButtonCreate.Name = "ButtonCreate";
+ this.ButtonCreate.Size = new System.Drawing.Size(94, 29);
+ this.ButtonCreate.TabIndex = 2;
+ this.ButtonCreate.Text = "Создать";
+ this.ButtonCreate.UseVisualStyleBackColor = true;
+ this.ButtonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
+ //
+ // buttonDown
+ //
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImage = global::ProjectMachine.Properties.Resources.вниз;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(651, 384);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 3;
+ this.buttonDown.Text = " \r\n\r\n";
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonRight
+ //
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::ProjectMachine.Properties.Resources.право;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(687, 384);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 4;
+ this.buttonRight.Text = " \r\n\r\n";
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.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::ProjectMachine.Properties.Resources.вверх;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(651, 348);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.TabIndex = 5;
+ this.buttonUp.Text = " \r\n\r\n";
+ 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::ProjectMachine.Properties.Resources.лево;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(615, 384);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
+ this.buttonLeft.TabIndex = 6;
+ this.buttonLeft.Text = " \r\n\r\n";
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonCreateModif
+ //
+ this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreateModif.Location = new System.Drawing.Point(124, 385);
+ this.buttonCreateModif.Name = "buttonCreateModif";
+ this.buttonCreateModif.Size = new System.Drawing.Size(130, 29);
+ this.buttonCreateModif.TabIndex = 7;
+ this.buttonCreateModif.Text = "Модификация";
+ this.buttonCreateModif.UseVisualStyleBackColor = true;
+ this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
+ //
+ // 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(151, 28);
+ this.comboBoxSelectorMap.TabIndex = 8;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
+ //
+ // FormMap
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(732, 467);
+ this.Controls.Add(this.comboBoxSelectorMap);
+ this.Controls.Add(this.buttonCreateModif);
+ this.Controls.Add(this.buttonLeft);
+ this.Controls.Add(this.buttonUp);
+ this.Controls.Add(this.buttonRight);
+ this.Controls.Add(this.buttonDown);
+ this.Controls.Add(this.ButtonCreate);
+ this.Controls.Add(this.pictureBoxMachine);
+ this.Controls.Add(this.statusStrip1);
+ this.Name = "FormMap";
+ this.Text = "Карта";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxMachine)).EndInit();
+ this.statusStrip1.ResumeLayout(false);
+ this.statusStrip1.PerformLayout();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxMachine;
+ private StatusStrip statusStrip1;
+ private ToolStripStatusLabel toolStripStatusLabelSpeed;
+ private ToolStripStatusLabel toolStripStatusLabelWeight;
+ private ToolStripStatusLabel toolStripStatusLabelBodyColor;
+ private Button ButtonCreate;
+ private Button buttonDown;
+ private Button buttonRight;
+ private Button buttonUp;
+ private Button buttonLeft;
+ private Button buttonCreateModif;
+ private ComboBox comboBoxSelectorMap;
+ }
+}
\ No newline at end of file
diff --git a/ProjectMachine/ProjectMachine/FormMap.cs b/ProjectMachine/ProjectMachine/FormMap.cs
new file mode 100644
index 0000000..c0d2c50
--- /dev/null
+++ b/ProjectMachine/ProjectMachine/FormMap.cs
@@ -0,0 +1,101 @@
+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 ProjectMachine
+{
+ public partial class FormMap : Form
+ {
+ private AbstractMap _abstractMap;
+
+ public FormMap()
+ {
+ InitializeComponent();
+ _abstractMap = new SimpleMap();
+ }
+ ///
+ /// Заполнение информации по объекту
+ ///
+ ///
+ private void SetData(DrawningMachine machine)
+ {
+ toolStripStatusLabelSpeed.Text = $"Скорость: {machine.Machine.Speed}";
+ toolStripStatusLabelWeight.Text = $"Вес: {machine.Machine.Weight}";
+ toolStripStatusLabelBodyColor.Text = $"Цвет: {machine.Machine.BodyColor.Name}";
+ pictureBoxMachine.Image = _abstractMap.CreateMap(pictureBoxMachine.Width, pictureBoxMachine.Height,
+ new DrawningObject(machine));
+ }
+ ///
+ /// Обработка нажатия кнопки "Создать"
+ ///
+ ///
+ ///
+ private void ButtonCreate_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var machine = new DrawningMachine(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ SetData(machine);
+ }
+ ///
+ /// Изменение размеров формы
+ ///
+ ///
+ ///
+ 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;
+ }
+ pictureBoxMachine.Image = _abstractMap?.MoveObject(dir);
+ }
+ ///
+ /// Обработка нажатия кнопки "Модификация"
+ ///
+ ///
+ ///
+ private void ButtonCreateModif_Click(object sender, EventArgs e)
+ {
+ Random rnd = new();
+ var machine = new DrawningTank(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)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
+ SetData(machine);
+ }
+ ///
+ /// Смена карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ _abstractMap = new SimpleMap();
+ break;
+ case "Город":
+ _abstractMap = new TownMap();
+ break;
+ }
+ }
+ }
+}
diff --git a/ProjectMachine/ProjectMachine/FormMap.resx b/ProjectMachine/ProjectMachine/FormMap.resx
new file mode 100644
index 0000000..ba3508b
--- /dev/null
+++ b/ProjectMachine/ProjectMachine/FormMap.resx
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+ 33
+
+
\ No newline at end of file
diff --git a/ProjectMachine/ProjectMachine/IDrawningObject.cs b/ProjectMachine/ProjectMachine/IDrawningObject.cs
new file mode 100644
index 0000000..7078235
--- /dev/null
+++ b/ProjectMachine/ProjectMachine/IDrawningObject.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectMachine
+{
+ ///
+ /// Интерфейс для работы с объектом, прорисовываемым на форме
+ ///
+ internal interface IDrawningObject
+ {
+ ///
+ /// Шаг перемещения объекта
+ ///
+ public float Step { get; }
+ ///
+ /// Установка позиции объекта
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина полотна
+ /// Высота полотна
+ void SetObject(int x, int y, int width, int height);
+ ///
+ /// Изменение направления пермещения объекта
+ ///
+ /// Направление
+ ///
+ void MoveObject(Direction direction);
+ ///
+ /// Отрисовка объекта
+ ///
+ ///
+ void DrawningObject(Graphics g);
+ ///
+ /// Получение текущей позиции объекта
+ ///
+ ///
+ (float Left, float Right, float Top, float Bottom) GetCurrentPosition();
+ }
+}
diff --git a/ProjectMachine/ProjectMachine/Program.cs b/ProjectMachine/ProjectMachine/Program.cs
index b8ffc19..4d6e0f6 100644
--- a/ProjectMachine/ProjectMachine/Program.cs
+++ b/ProjectMachine/ProjectMachine/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectMachine
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormMachine());
+ Application.Run(new FormMap());
}
}
}
\ No newline at end of file
diff --git a/ProjectMachine/ProjectMachine/SimpleMap.cs b/ProjectMachine/ProjectMachine/SimpleMap.cs
new file mode 100644
index 0000000..d07049e
--- /dev/null
+++ b/ProjectMachine/ProjectMachine/SimpleMap.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectMachine
+{
+ ///
+ /// Простая реализация абсрактного класса AbstractMap
+ ///
+ 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, _size_x, _size_y);
+ }
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ 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++;
+ }
+ }
+ }
+ }
+}
diff --git a/ProjectMachine/ProjectMachine/TownMap.cs b/ProjectMachine/ProjectMachine/TownMap.cs
new file mode 100644
index 0000000..f7aeae6
--- /dev/null
+++ b/ProjectMachine/ProjectMachine/TownMap.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectMachine
+{
+ internal class TownMap : AbstractMap
+ {
+ ///
+ /// Цвет участка закрытого
+ ///
+ private readonly Brush barrierTreeColor = new SolidBrush(Color.Plum);
+ ///
+ /// Цвет участка открытого
+ ///
+ private readonly Brush roadColor = new SolidBrush(Color.LightGoldenrodYellow);
+ protected override void DrawBarrierPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(barrierTreeColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ protected override void DrawRoadPart(Graphics g, int i, int j)
+ {
+ g.FillRectangle(roadColor, i * _size_x, j * _size_y, _size_x, _size_y);
+ }
+ protected override void GenerateMap()
+ {
+ _map = new int[15, 15];
+ _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, 15);
+ int y = _random.Next(0, 15);
+ if (_map[x, y] == _freeRoad)
+ {
+ _map[x, y] = _barrier;
+ counter++;
+ }
+ }
+ }
+ }
+}