diff --git a/ProjectBulldozer/Direction.cs b/ProjectBulldozer/Direction.cs
deleted file mode 100644
index 2f756d8..0000000
--- a/ProjectBulldozer/Direction.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ProjectBulldozer
-{
- internal enum Direction
- {
-
- Up = 1,
-
- Down = 2,
-
- Left = 3,
-
- Right = 4
-
- }
-}
diff --git a/ProjectBulldozer/DirectionType.cs b/ProjectBulldozer/DirectionType.cs
new file mode 100644
index 0000000..e37c505
--- /dev/null
+++ b/ProjectBulldozer/DirectionType.cs
@@ -0,0 +1,12 @@
+
+
+namespace ProjectBulldozer
+{
+ public enum DirectionType
+ {
+ Up = 1,
+ Down = 2,
+ Left = 3,
+ Right = 4,
+ }
+}
diff --git a/ProjectBulldozer/Drawings/DrawingTractor.cs b/ProjectBulldozer/Drawings/DrawingTractor.cs
new file mode 100644
index 0000000..4c7366d
--- /dev/null
+++ b/ProjectBulldozer/Drawings/DrawingTractor.cs
@@ -0,0 +1,169 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Bulldozer;
+using ProjectBulldozer.Entities;
+using ProjectBulldozer.Properties;
+
+namespace ProjectBulldozer.Drawings
+{
+ public class DrawingTractor
+ {
+ public EntityTractor? EntityTractor { get; protected set; }
+
+ protected int _pictureWidth;
+
+ protected int _pictureHeight;
+
+ protected int _startPosX;
+
+ protected int _startPosY;
+
+ private int tractWidth;
+ protected readonly int _tractWidth = 140;
+
+ protected readonly int _tractHeight = 123;
+ public int GetPosX => _startPosX;
+ public int GetPosY => _startPosY;
+ public int GetWidth => _tractWidth;
+ public int GetHeight => _tractHeight;
+
+ public DrawingTractor(int speed, double weight, Color bodyColor, int width, int heigth)
+ {
+ if (width < _tractWidth || heigth < _tractHeight)
+ {
+ return;
+ }
+ _pictureWidth = width;
+ _pictureHeight = heigth;
+ EntityTractor = new EntityTractor(speed, weight, bodyColor);
+ }
+
+ protected DrawingTractor(int speed, double weight, Color bodyColor, int width,
+ int height, int tractWidth, int tractHeight)
+ {
+ if (width < _tractWidth || height < _tractHeight)
+ {
+ return;
+ }
+ _pictureWidth = width;
+ _pictureHeight = height;
+ _tractWidth = tractWidth;
+ _tractHeight = tractHeight;
+ EntityTractor = new EntityTractor(speed, weight, bodyColor);
+ }
+
+ //Установка позиции
+ public void SetPosition(int x, int y)
+ {
+ if (x < 0 || x + _tractWidth > _pictureWidth)
+ {
+ x = _pictureWidth - tractWidth;
+ }
+ if (y < 0 || y + _tractHeight > _pictureHeight)
+ {
+ y = _pictureHeight - _tractHeight;
+ }
+ _startPosX = x;
+ _startPosY = y;
+ }
+
+ public void MoveTransport(DirectionType direction)
+ {
+ if (EntityTractor == null)
+ {
+ return;
+ }
+ switch (direction)
+ {
+ case DirectionType.Left:
+ if (_startPosX - EntityTractor.Step > 0)
+ {
+ _startPosX -= (int)EntityTractor.Step;
+ }
+ break;
+ case DirectionType.Up:
+ if (_startPosY - EntityTractor.Step > 0)
+ {
+ _startPosY -= (int)EntityTractor.Step;
+ }
+ break;
+ case DirectionType.Right:
+ if (_startPosX + EntityTractor.Step + _tractWidth < _pictureWidth)
+ {
+ _startPosX += (int)EntityTractor.Step;
+ }
+ break;
+ case DirectionType.Down:
+ if (_startPosY + EntityTractor.Step + _tractHeight < _pictureHeight)
+ {
+ _startPosY += (int)EntityTractor.Step;
+ }
+ break;
+ }
+ }
+
+ public virtual void DrawTransport(Graphics g)
+ {
+ {
+ if (EntityTractor == null) return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush brownBrush = new SolidBrush(Color.Brown);
+ Brush windows = new SolidBrush(Color.LightYellow);
+ Brush bodyColor = new SolidBrush(EntityTractor.BodyColor);
+
+ Brush grayBrush = new SolidBrush(Color.Gray);
+
+ //основное тело
+ g.FillRectangle(bodyColor, _startPosX + 20, _startPosY + 40, 100, 60);
+ g.DrawRectangle(pen, _startPosX + 20, _startPosY + 40, 100, 60);
+
+
+
+ //кабина водителя
+ g.FillRectangle(windows, _startPosX + 20, _startPosY, 40, 40);
+ g.DrawRectangle(pen, _startPosX + 20, _startPosY, 40, 40);
+
+
+
+ //колеса
+
+ g.FillEllipse(grayBrush, _startPosX + 20, _startPosY + 74, 47, 47);
+ g.DrawEllipse(pen, _startPosX + 20, _startPosY + 74, 47, 47);
+
+
+ g.FillEllipse(grayBrush, _startPosX + 80, _startPosY + 85, 35, 35);
+ g.DrawEllipse(pen, _startPosX + 80, _startPosY + 85, 35, 35);
+
+
+ //выхлопная труба
+ g.FillRectangle(brownBrush, _startPosX + 90, _startPosY, 15, 40);
+ g.DrawRectangle(pen, _startPosX + 90, _startPosY, 15, 40);
+
+
+ }
+
+ public bool CanMove(DirectionType direction)
+ {
+ if (EntityTractor == null)
+ {
+ return false;
+ }
+ return direction switch
+ {
+ //влево
+ DirectionType.Left => _startPosX - EntityTractor.Step > 0,
+ //вверх
+ DirectionType.Up => _startPosY - EntityTractor.Step > 0,
+ // вправо
+ DirectionType.Right => _startPosX + EntityTractor.Step < _pictureWidth,
+ //вниз
+ DirectionType.Down => _startPosY + EntityTractor.Step < _pictureHeight,
+ };
+ }
+ }
+}
diff --git a/ProjectBulldozer/Drawings/DrawningBulldozer.cs b/ProjectBulldozer/Drawings/DrawningBulldozer.cs
new file mode 100644
index 0000000..6edc944
--- /dev/null
+++ b/ProjectBulldozer/Drawings/DrawningBulldozer.cs
@@ -0,0 +1,75 @@
+using ProjectBulldozer.Entities;
+
+namespace ProjectBulldozer.Drawings
+{
+ public class DrawingBulldozer : DrawingTractor
+ {
+ public DrawingBulldozer(int speed, double weight, Color bodyColor, Color additionalColor,
+ bool otval, bool seifBatteries, int width, int height) : base(speed, weight, bodyColor, width, height, 129, 120)
+ {
+ if (EntityTractor != null)
+ {
+ EntityTractor = new EntityBulldozer(speed, width, bodyColor, additionalColor, otval, seifBatteries);
+ }
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityTractor is not EntityBulldozer Bulldozer)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush blackBrush = new SolidBrush(Color.Black);
+ Brush windows = new SolidBrush(Color.LightBlue);
+ Brush bodyColor = new SolidBrush(Bulldozer.BodyColor);
+ Brush additionalBrush = new SolidBrush(Bulldozer.AdditionalColor);
+ Brush grayBrush = new SolidBrush(Color.Gray);
+ if (Bulldozer.Otval)
+ {
+ //otval
+ Point[] Otval =
+ {
+ new Point(_startPosX + 122, _startPosY + 55),
+ new Point(_startPosX + 142, _startPosY + 115),
+ new Point(_startPosX+ 122, _startPosY + 115),
+
+
+ };
+
+ g.FillPolygon(blackBrush, Otval);
+ g.DrawPolygon(pen, Otval);
+ }
+
+
+ //гусеницы
+ Brush gg = new SolidBrush(Color.LightGray);
+ g.FillEllipse(gg, _startPosX + 19, _startPosY + 62, 100, 65);
+ g.DrawEllipse(pen, _startPosX + 19, _startPosY + 62, 100, 65);
+
+
+
+ g.FillEllipse(grayBrush, _startPosX + 65, _startPosY + 100, 15, 15);
+ g.DrawEllipse(pen, _startPosX + 65, _startPosY + 100, 15, 15);
+
+
+
+
+ Point[] Ttt =
+ {
+ new Point(_startPosX + 18 , _startPosY + 80),
+ new Point(_startPosX + 18, _startPosY + 110),
+ new Point(_startPosX, _startPosY + 50),
+
+ };
+ g.FillPolygon(blackBrush, Ttt);
+ g.DrawPolygon(pen, Ttt);
+
+ if (Bulldozer.SeifBatteries)
+ {
+ g.FillRectangle(blackBrush, _startPosX + 78, _startPosY + 30, 10, 10);
+ }
+ base.DrawTransport(g);
+ }
+ }
+}
diff --git a/ProjectBulldozer/DrawningBulldozer.cs b/ProjectBulldozer/DrawningBulldozer.cs
deleted file mode 100644
index 7bb92b0..0000000
--- a/ProjectBulldozer/DrawningBulldozer.cs
+++ /dev/null
@@ -1,209 +0,0 @@
-
-
-using ProjectBulldozer.Entities;
-
-namespace ProjectBulldozer
-{
- internal class DrawningBulldozer
- {
-
- public EntityBulldozer? EntityBulldozer { get; private set; }
-
- private int _pictureWidth;
-
- private int _pictureHeight;
-
- private int _startPosX;
-
- private int _startPosY;
-
- private readonly int _BulldozerWidth = 180;
-
- private readonly int _BulldozerHeight = 140;
-
- public bool Init(int speed, double weight, Color bodyColor, Color
- additionalColor, bool additionalEngine, bool additionalCompartment, int width, int height)
- {
- if (_pictureWidth < _BulldozerWidth | _pictureHeight < _BulldozerHeight)
- {
- _pictureWidth = width;
- _pictureHeight = height;
- EntityBulldozer = new EntityBulldozer();
- EntityBulldozer.Init(speed, weight, bodyColor, additionalColor,
- additionalEngine, additionalCompartment);
- return true;
- }
- else return false;
- }
-
- public void SetPosition(int x, int y)
- {
- if (_startPosY + _BulldozerHeight < _pictureHeight)
- _startPosY = y;
- else
- _startPosY = _pictureHeight - _BulldozerHeight;
- if (_startPosX + _BulldozerWidth < _pictureWidth)
- _startPosX = x;
- else
- _startPosX = _pictureWidth - _BulldozerWidth;
- }
-
- public void MoveTransport(Direction direction)
- {
- if (EntityBulldozer == null)
- {
- return;
- }
- switch (direction)
- {
- //влево
- case Direction.Left:
- if (_startPosX - EntityBulldozer.Step > 0)
- {
- _startPosX -= (int)EntityBulldozer.Step;
- }
- else _startPosX = 0;
- break;
- //вверх
- case Direction.Up:
- if (_startPosY - EntityBulldozer.Step > 0)
- {
- _startPosY -= (int)EntityBulldozer.Step;
- }
- else _startPosY = 0;
- break;
- // вправо
- case Direction.Right:
- if (_startPosX + _BulldozerWidth + EntityBulldozer.Step < _pictureWidth)
- {
- _startPosX += (int)EntityBulldozer.Step;
- }
- else _startPosX = _pictureWidth - _BulldozerWidth;
- break;
- //вниз
- case Direction.Down:
- if (_startPosY + _BulldozerHeight + EntityBulldozer.Step < _pictureHeight)
- {
- _startPosY += (int)EntityBulldozer.Step;
- }
- else _startPosY = _pictureHeight - _BulldozerHeight;
- break;
- }
- }
-
- public void DrawTransport(Graphics g)
- {
- if (EntityBulldozer == null)
- {
- return;
- }
- Pen pen = new(Color.Black);
- Brush brush = new SolidBrush(Color.Black);
- Brush bl = new SolidBrush(EntityBulldozer.AdditionalColor);
- Brush bodyBrush = new SolidBrush(EntityBulldozer.BodyColor);
- Brush bodyBrush2 = new SolidBrush(EntityBulldozer.AdditionalColor);
-
-
-
-
- //основное тело
- g.FillRectangle(bodyBrush, _startPosX + 20, _startPosY + 40, 120, 60);
-
- g.DrawRectangle(pen, _startPosX + 20, _startPosY + 40, 120, 60);
-
-
-
- //Гусеницы
- Brush gg = new SolidBrush(Color.LightGray);
- g.FillEllipse(gg, _startPosX + 23, _startPosY + 101, 118, 35);
- g.DrawEllipse(pen, _startPosX + 23, _startPosY + 101, 118, 35);
-
-
-
-
- g.DrawEllipse(pen, _startPosX + 26, _startPosY + 103, 110, 30);
-
- //катки в гусеницах
- Brush gr = new SolidBrush(Color.Gray);
- g.FillEllipse(gr, _startPosX + 40, _startPosY + 108, 20, 20);
- g.DrawEllipse(pen, _startPosX + 40, _startPosY + 108, 20, 20);
-
-
- g.FillEllipse(gr, _startPosX + 65, _startPosY + 110, 20, 20);
- g.DrawEllipse(pen, _startPosX + 65, _startPosY + 110, 20, 20);
-
- g.FillEllipse(gr, _startPosX + 115, _startPosY + 110, 15, 15);
- g.DrawEllipse(pen, _startPosX + 115, _startPosY + 110, 15, 15);
-
- g.FillEllipse(gr, _startPosX + 90, _startPosY + 110, 20, 20);
- g.DrawEllipse(pen, _startPosX + 90, _startPosY + 110, 20, 20);
-
-
-
-
- //кабина водителя
- g.FillRectangle(bodyBrush2, _startPosX + 20, _startPosY, 40, 40);
- g.DrawRectangle(pen, _startPosX + 20, _startPosY, 40, 40);
-
-
- //выхлопная труба
- Brush brBr = new SolidBrush(Color.Brown);
-
- g.FillRectangle(brBr, _startPosX + 110, _startPosY, 15, 40);
- g.DrawRectangle(pen, _startPosX + 110, _startPosY, 15, 40);
-
-
-
- //Brush bl = new SolidBrush(Color.LightYellow);
- /////////отвал
- ///
- Point[] Otval =
- {
- new Point(_startPosX + 142, _startPosY + 70),
- new Point(_startPosX + 172, _startPosY + 130),
- new Point(_startPosX+ 142, _startPosY + 130),
-
-
- };
-
- g.FillPolygon(bl, Otval);
- g.DrawPolygon(pen, Otval);
-
-
-
- Brush black = new SolidBrush(Color.Black);
- Point[] Rihl =
- {
- new Point(_startPosX + 18 , _startPosY + 60),
- new Point(_startPosX + 18, _startPosY + 80),
- new Point(_startPosX, _startPosY + 120),
-
- };
-
- g.FillPolygon(black, Rihl);
- g.DrawPolygon(pen, Rihl);
-
-
-
- Point[] Ttt =
- {
- new Point(_startPosX + 18 , _startPosY + 80),
- new Point(_startPosX + 18, _startPosY + 120),
- new Point(_startPosX, _startPosY + 50),
-
- };
- g.FillPolygon(black, Ttt);
- g.DrawPolygon(pen, Ttt);
-
-
-
-
-
-
-
-
-
-
- }
- }
-}
diff --git a/ProjectBulldozer/FormBulldozer.Designer.cs b/ProjectBulldozer/FormBulldozer.Designer.cs
index 8f9dbab..d69ea4c 100644
--- a/ProjectBulldozer/FormBulldozer.Designer.cs
+++ b/ProjectBulldozer/FormBulldozer.Designer.cs
@@ -1,6 +1,6 @@
-namespace ProjectBulldozer
+namespace Bulldozer
{
- partial class FormBulldozer
+ partial class Bulldozer
{
///
/// Required designer variable.
@@ -28,13 +28,15 @@
///
private void InitializeComponent()
{
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormBulldozer));
pictureBoxBulldozer = new PictureBox();
- buttonCreate = new Button();
+ buttonCreateBulldozer = new Button();
buttonLeft = new Button();
buttonUp = new Button();
buttonRight = new Button();
buttonDown = new Button();
+ comboBoxStrategy = new ComboBox();
+ buttonCreateTractor = new Button();
+ buttonStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit();
SuspendLayout();
//
@@ -42,31 +44,35 @@
//
pictureBoxBulldozer.Dock = DockStyle.Fill;
pictureBoxBulldozer.Location = new Point(0, 0);
+ pictureBoxBulldozer.Margin = new Padding(2);
pictureBoxBulldozer.Name = "pictureBoxBulldozer";
- pictureBoxBulldozer.Size = new Size(884, 461);
+ pictureBoxBulldozer.Size = new Size(869, 307);
pictureBoxBulldozer.SizeMode = PictureBoxSizeMode.AutoSize;
pictureBoxBulldozer.TabIndex = 0;
pictureBoxBulldozer.TabStop = false;
//
- // buttonCreate
+ // buttonCreateBulldozer
//
- buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(12, 426);
- buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(75, 23);
- buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать";
- buttonCreate.UseVisualStyleBackColor = true;
- buttonCreate.Click += buttonCreate_Click;
+ buttonCreateBulldozer.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateBulldozer.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
+ buttonCreateBulldozer.Location = new Point(131, 249);
+ buttonCreateBulldozer.Margin = new Padding(2);
+ buttonCreateBulldozer.Name = "buttonCreateBulldozer";
+ buttonCreateBulldozer.Size = new Size(100, 47);
+ buttonCreateBulldozer.TabIndex = 1;
+ buttonCreateBulldozer.Text = "Создать булльдозер";
+ buttonCreateBulldozer.UseVisualStyleBackColor = true;
+ buttonCreateBulldozer.Click += buttonCreateBulldozer_Click;
//
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
+ buttonLeft.BackgroundImage = ProjectBulldozer.Properties.Resources.left1;
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
- buttonLeft.Location = new Point(769, 419);
+ buttonLeft.Location = new Point(764, 271);
+ buttonLeft.Margin = new Padding(2);
buttonLeft.Name = "buttonLeft";
- buttonLeft.Size = new Size(30, 30);
+ buttonLeft.Size = new Size(26, 25);
buttonLeft.TabIndex = 2;
buttonLeft.UseVisualStyleBackColor = true;
buttonLeft.Click += buttonMove_Click;
@@ -74,24 +80,25 @@
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
+ buttonUp.BackgroundImage = ProjectBulldozer.Properties.Resources.up1;
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
- buttonUp.Location = new Point(805, 383);
+ buttonUp.Location = new Point(792, 240);
+ buttonUp.Margin = new Padding(2);
buttonUp.Name = "buttonUp";
- buttonUp.Size = new Size(30, 30);
+ buttonUp.Size = new Size(30, 27);
buttonUp.TabIndex = 3;
- buttonUp.TextAlign = ContentAlignment.BottomRight;
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += buttonMove_Click;
//
// buttonRight
//
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
+ buttonRight.BackgroundImage = ProjectBulldozer.Properties.Resources.right1;
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
- buttonRight.Location = new Point(841, 419);
+ buttonRight.Location = new Point(826, 271);
+ buttonRight.Margin = new Padding(2);
buttonRight.Name = "buttonRight";
- buttonRight.Size = new Size(30, 30);
+ buttonRight.Size = new Size(27, 25);
buttonRight.TabIndex = 4;
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click;
@@ -99,28 +106,74 @@
// buttonDown
//
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
+ buttonDown.BackgroundImage = ProjectBulldozer.Properties.Resources.down1;
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
- buttonDown.Location = new Point(805, 419);
+ buttonDown.Location = new Point(794, 271);
+ buttonDown.Margin = new Padding(2);
buttonDown.Name = "buttonDown";
- buttonDown.Size = new Size(30, 30);
+ buttonDown.Size = new Size(30, 25);
buttonDown.TabIndex = 5;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += buttonMove_Click;
//
- // FormBulldozer
+ // comboBoxStrategy
+ //
+ comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxStrategy.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
+ comboBoxStrategy.FormattingEnabled = true;
+ comboBoxStrategy.Items.AddRange(new object[] { "К центру", "В угол" });
+ comboBoxStrategy.Location = new Point(693, 10);
+ comboBoxStrategy.Margin = new Padding(2);
+ comboBoxStrategy.Name = "comboBoxStrategy";
+ comboBoxStrategy.Size = new Size(150, 25);
+ comboBoxStrategy.TabIndex = 6;
+ comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged;
+ //
+ // buttonCreateTractor
+ //
+ buttonCreateTractor.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateTractor.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
+ buttonCreateTractor.Location = new Point(11, 249);
+ buttonCreateTractor.Margin = new Padding(2);
+ buttonCreateTractor.Name = "buttonCreateTractor";
+ buttonCreateTractor.Size = new Size(106, 47);
+ buttonCreateTractor.TabIndex = 7;
+ buttonCreateTractor.Text = "Создать трактор";
+ buttonCreateTractor.UseVisualStyleBackColor = true;
+ buttonCreateTractor.Click += buttonCreateTractor_Click;
+ //
+ // buttonStep
+ //
+ buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonStep.Font = new Font("Times New Roman", 11.25F, FontStyle.Regular, GraphicsUnit.Point);
+ buttonStep.Location = new Point(755, 39);
+ buttonStep.Margin = new Padding(2);
+ buttonStep.Name = "buttonStep";
+ buttonStep.Size = new Size(88, 34);
+ buttonStep.TabIndex = 8;
+ buttonStep.Text = "Шаг";
+ buttonStep.UseVisualStyleBackColor = true;
+ buttonStep.Click += buttonStep_Click;
+ //
+ // Bulldozer
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(884, 461);
+ ClientSize = new Size(869, 307);
+ Controls.Add(buttonStep);
+ Controls.Add(buttonCreateTractor);
+ Controls.Add(comboBoxStrategy);
Controls.Add(buttonDown);
Controls.Add(buttonRight);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreate);
+ Controls.Add(buttonCreateBulldozer);
Controls.Add(pictureBoxBulldozer);
- Name = "FormBulldozer";
- Text = "FormBulldozer";
+ Margin = new Padding(2);
+ Name = "Bulldozer";
+ StartPosition = FormStartPosition.CenterScreen;
+ Text = "Bulldozer";
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).EndInit();
ResumeLayout(false);
PerformLayout();
@@ -129,10 +182,13 @@
#endregion
private PictureBox pictureBoxBulldozer;
- private Button buttonCreate;
+ private Button buttonCreateBulldozer;
private Button buttonLeft;
private Button buttonUp;
private Button buttonRight;
private Button buttonDown;
+ private ComboBox comboBoxStrategy;
+ private Button buttonCreateTractor;
+ private Button buttonStep;
}
-}
+}
\ No newline at end of file
diff --git a/ProjectBulldozer/FormBulldozer.cs b/ProjectBulldozer/FormBulldozer.cs
index 398b38a..ff082ce 100644
--- a/ProjectBulldozer/FormBulldozer.cs
+++ b/ProjectBulldozer/FormBulldozer.cs
@@ -1,51 +1,59 @@
-namespace ProjectBulldozer
+using ProjectBulldozer;
+using ProjectBulldozer.Drawings;
+using ProjectBulldozer.MovementStrategy;
+using System;
+
+namespace Bulldozer
{
- public partial class FormBulldozer : Form
+ public partial class Bulldozer : Form
{
- private DrawningBulldozer? _drawningBulldozer;
+ private DrawingTractor? _drawingTractor;
- public FormBulldozer()
+ private AbstractStrategy? _abstractStrategy;
+
+ public Bulldozer()
{
InitializeComponent();
}
private void Draw()
{
- if (_drawningBulldozer == null)
+ if (_drawingTractor == null)
{
return;
}
- Bitmap bmp = new(pictureBoxBulldozer.Width,
- pictureBoxBulldozer.Height);
+ Bitmap bmp = new(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawningBulldozer.DrawTransport(gr);
+ _drawingTractor.DrawTransport(gr);
pictureBoxBulldozer.Image = bmp;
}
-
-
- private void buttonCreate_Click(object sender, EventArgs e)
+ private void buttonCreateBulldozer_Click(object sender, EventArgs e)
{
- Random random = new();
- _drawningBulldozer = new DrawningBulldozer();
- _drawningBulldozer.Init(random.Next(100, 300),
- random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
- random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
- random.Next(0, 256)),
- Convert.ToBoolean(random.Next(0, 2)),
- Convert.ToBoolean(random.Next(0, 2)),
+ Random random = new Random();
+ _drawingTractor = new DrawingBulldozer(random.Next(100, 300), random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
- _drawningBulldozer.SetPosition(random.Next(10, 100),
- random.Next(10, 100));
+ _drawingTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ Draw();
+ }
+
+ private void buttonCreateTractor_Click(object sender, EventArgs e)
+ {
+ Random rnd = new Random();
+ _drawingTractor = new DrawingTractor(rnd.Next(100, 300), rnd.Next(1000, 3000),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
+ _drawingTractor.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
- if (_drawningBulldozer == null)
+ if (_drawingTractor == null)
{
return;
}
@@ -53,20 +61,60 @@ namespace ProjectBulldozer
switch (name)
{
case "buttonUp":
- _drawningBulldozer.MoveTransport(Direction.Up);
+ _drawingTractor.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
- _drawningBulldozer.MoveTransport(Direction.Down);
+ _drawingTractor.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
- _drawningBulldozer.MoveTransport(Direction.Left);
+ _drawingTractor.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
- _drawningBulldozer.MoveTransport(Direction.Right);
+ _drawingTractor.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
- }
-}
+ private void buttonStep_Click(object sender, EventArgs e)
+ {
+ if (_drawingTractor == null)
+ {
+ return;
+ }
+ if (comboBoxStrategy.Enabled)
+ {
+ _abstractStrategy = comboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToRightCorner(),
+ _ => null,
+ };
+ if (_abstractStrategy == null)
+ {
+ return;
+ }
+ _abstractStrategy.SetData(new
+ DrawingObjectTractor(_drawingTractor), pictureBoxBulldozer.Width,
+ pictureBoxBulldozer.Height);
+ comboBoxStrategy.Enabled = false;
+ }
+ if (_abstractStrategy == null)
+ {
+ return;
+ }
+ _abstractStrategy.MakeStep();
+ Draw();
+ if (_abstractStrategy.GetStatus() == Status.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _abstractStrategy = null;
+ }
+ }
+
+ private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
+ {
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs b/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs
new file mode 100644
index 0000000..6d0644d
--- /dev/null
+++ b/ProjectBulldozer/MovementStrategy/AbstractStrategy.cs
@@ -0,0 +1,79 @@
+namespace ProjectBulldozer.MovementStrategy
+{
+ ///
+ /// Абстрактный класс стратегии
+ ///
+ public abstract class AbstractStrategy
+ {
+ private IMoveableObject? _moveableObject;
+
+ private Status _state = Status.NotInit;
+ protected int FieldWidth { get; private set; }
+ protected int FieldHeight { get; private set; }
+ public Status GetStatus() { return _state; }
+
+ public void SetData(IMoveableObject moveableObject, int width, int height)
+ {
+ if (moveableObject == null)
+ {
+ _state = Status.NotInit;
+ return;
+ }
+ _state = Status.InProgress;
+ _moveableObject = moveableObject;
+ FieldWidth = width;
+ FieldHeight = height;
+ }
+
+ public void MakeStep()
+ {
+ if (_state != Status.InProgress)
+ {
+ return;
+ }
+ if (IsTargetDestinaion())
+ {
+ _state = Status.Finish;
+ return;
+ }
+ MoveToTarget();
+ }
+
+ protected bool MoveLeft() => MoveTo(DirectionType.Left);
+
+ protected bool MoveRight() => MoveTo(DirectionType.Right);
+
+ protected bool MoveUp() => MoveTo(DirectionType.Up);
+
+ protected bool MoveDown() => MoveTo(DirectionType.Down);
+
+ /// Параметры объекта
+ protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition;
+
+ protected int? GetStep()
+ {
+ if (_state != Status.InProgress)
+ {
+ return null;
+ }
+ return _moveableObject?.GetStep;
+ }
+ protected abstract void MoveToTarget();
+
+ protected abstract bool IsTargetDestinaion();
+
+ private bool MoveTo(DirectionType directionType)
+ {
+ if (_state != Status.InProgress)
+ {
+ return false;
+ }
+ if (_moveableObject?.CheckCanMove(directionType) ?? false)
+ {
+ _moveableObject.MoveObject(directionType);
+ return true;
+ }
+ return false;
+ }
+ }
+}
diff --git a/ProjectBulldozer/MovementStrategy/DrawingObjectTractor.cs b/ProjectBulldozer/MovementStrategy/DrawingObjectTractor.cs
new file mode 100644
index 0000000..8df4ffe
--- /dev/null
+++ b/ProjectBulldozer/MovementStrategy/DrawingObjectTractor.cs
@@ -0,0 +1,30 @@
+
+using ProjectBulldozer.Drawings;
+
+namespace ProjectBulldozer.MovementStrategy
+{
+ public class DrawingObjectTractor : IMoveableObject
+ {
+ private readonly DrawingTractor? _drawningTractor = null;
+
+ public DrawingObjectTractor(DrawingTractor drawningTractor)
+ {
+ _drawningTractor = drawningTractor;
+ }
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_drawningTractor == null || _drawningTractor.EntityTractor == null)
+ {
+ return null;
+ }
+ return new ObjectParameters(_drawningTractor.GetPosX,
+ _drawningTractor.GetPosY, _drawningTractor.GetWidth, _drawningTractor.GetHeight);
+ }
+ }
+ public int GetStep => (int)(_drawningTractor?.EntityTractor?.Step ?? 0);
+ public bool CheckCanMove(DirectionType direction) => _drawningTractor?.CanMove(direction) ?? false;
+ public void MoveObject(DirectionType direction) => _drawningTractor?.MoveTransport(direction);
+ }
+}
diff --git a/ProjectBulldozer/MovementStrategy/IMoveableObject.cs b/ProjectBulldozer/MovementStrategy/IMoveableObject.cs
new file mode 100644
index 0000000..4a1315e
--- /dev/null
+++ b/ProjectBulldozer/MovementStrategy/IMoveableObject.cs
@@ -0,0 +1,13 @@
+
+namespace ProjectBulldozer.MovementStrategy
+{
+ public interface IMoveableObject
+ {
+ ObjectParameters? GetObjectPosition { get; }
+
+ int GetStep { get; }
+
+ bool CheckCanMove(DirectionType direction);
+ void MoveObject(DirectionType direction);
+ }
+}
diff --git a/ProjectBulldozer/MovementStrategy/MoveToCenter.cs b/ProjectBulldozer/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..d16d4a7
--- /dev/null
+++ b/ProjectBulldozer/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,47 @@
+
+
+namespace ProjectBulldozer.MovementStrategy
+{
+ public class MoveToCenter : AbstractStrategy
+ {
+ protected override bool IsTargetDestinaion()
+ {
+ var objParams = GetObjectParameters;
+ if (objParams == null) return false;
+
+ return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 && objParams.ObjectMiddleHorizontal
+ + GetStep() >= FieldWidth / 2 && objParams.ObjectMiddleVertical <= FieldHeight / 2 &&
+ objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
+ }
+
+ protected override void MoveToTarget()
+ {
+ var objParams = GetObjectParameters;
+ if (objParams == null) return;
+ var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+ var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+ }
+}
diff --git a/ProjectBulldozer/MovementStrategy/MoveToRightCorner.cs b/ProjectBulldozer/MovementStrategy/MoveToRightCorner.cs
new file mode 100644
index 0000000..37ac745
--- /dev/null
+++ b/ProjectBulldozer/MovementStrategy/MoveToRightCorner.cs
@@ -0,0 +1,25 @@
+
+
+namespace ProjectBulldozer.MovementStrategy
+{
+ public class MoveToRightCorner : AbstractStrategy
+ {
+ protected override bool IsTargetDestinaion()
+ {
+ var objParams = GetObjectParameters;
+ if (objParams == null) return false;
+
+ return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep();
+ }
+
+ protected override void MoveToTarget()
+ {
+ var objParams = GetObjectParameters;
+ if (objParams == null) return;
+
+ if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight();
+ if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown();
+
+ }
+ }
+}
diff --git a/ProjectBulldozer/MovementStrategy/ObjectsParameters.cs b/ProjectBulldozer/MovementStrategy/ObjectsParameters.cs
new file mode 100644
index 0000000..d0ce8f9
--- /dev/null
+++ b/ProjectBulldozer/MovementStrategy/ObjectsParameters.cs
@@ -0,0 +1,38 @@
+
+
+namespace ProjectBulldozer.MovementStrategy
+{
+ public class ObjectParameters
+ {
+ private readonly int _x;
+ private readonly int _y;
+ private readonly int _width;
+ private readonly int _height;
+
+ /// Левая граница
+ public int LeftBorder => _x;
+
+ /// Верхняя граница
+ public int TopBorder => _y;
+
+ /// Правая граница
+ public int RightBorder => _x + _width;
+
+ /// Нижняя граница
+ public int DownBorder => _y + _height;
+
+ /// Середина объекта по горизонтали
+ public int ObjectMiddleHorizontal => _x + _width / 2;
+
+ /// Середина объекта по вертикали
+ public int ObjectMiddleVertical => _y + _height / 2;
+
+ public ObjectParameters(int x, int y, int width, int height)
+ {
+ _x = x;
+ _y = y;
+ _width = width;
+ _height = height;
+ }
+ }
+}
diff --git a/ProjectBulldozer/Program.cs b/ProjectBulldozer/Program.cs
index ce4d1f0..b800f23 100644
--- a/ProjectBulldozer/Program.cs
+++ b/ProjectBulldozer/Program.cs
@@ -1,4 +1,4 @@
-namespace ProjectBulldozer
+namespace Bulldozer
{
internal static class Program
{
@@ -11,7 +11,7 @@ namespace ProjectBulldozer
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormBulldozer());
+ Application.Run(new Bulldozer());
}
}
}
\ No newline at end of file
diff --git a/ProjectBulldozer/Properties/Resources.Designer.cs b/ProjectBulldozer/Properties/Resources.Designer.cs
index 273f98f..32374d8 100644
--- a/ProjectBulldozer/Properties/Resources.Designer.cs
+++ b/ProjectBulldozer/Properties/Resources.Designer.cs
@@ -59,5 +59,45 @@ namespace ProjectBulldozer.Properties {
resourceCulture = value;
}
}
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap down1 {
+ get {
+ object obj = ResourceManager.GetObject("down1", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap left1 {
+ get {
+ object obj = ResourceManager.GetObject("left1", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap right1 {
+ get {
+ object obj = ResourceManager.GetObject("right1", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap up1 {
+ get {
+ object obj = ResourceManager.GetObject("up1", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
}
}
diff --git a/ProjectBulldozer/Properties/Resources.resx b/ProjectBulldozer/Properties/Resources.resx
index 1af7de1..bf99cff 100644
--- a/ProjectBulldozer/Properties/Resources.resx
+++ b/ProjectBulldozer/Properties/Resources.resx
@@ -117,4 +117,17 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ ..\Resources\down1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\left1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\right1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\up1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
\ No newline at end of file
diff --git a/ProjectBulldozer/Resources/Down.png b/ProjectBulldozer/Resources/Down.png
deleted file mode 100644
index ff3555a..0000000
Binary files a/ProjectBulldozer/Resources/Down.png and /dev/null differ
diff --git a/ProjectBulldozer/Resources/Left.png b/ProjectBulldozer/Resources/Left.png
deleted file mode 100644
index ad0b209..0000000
Binary files a/ProjectBulldozer/Resources/Left.png and /dev/null differ
diff --git a/ProjectBulldozer/Resources/Right.png b/ProjectBulldozer/Resources/Right.png
deleted file mode 100644
index 0078897..0000000
Binary files a/ProjectBulldozer/Resources/Right.png and /dev/null differ
diff --git a/ProjectBulldozer/Resources/Up.png b/ProjectBulldozer/Resources/Up.png
deleted file mode 100644
index 0223b64..0000000
Binary files a/ProjectBulldozer/Resources/Up.png and /dev/null differ
diff --git a/ProjectBulldozer/Resources/down1.png b/ProjectBulldozer/Resources/down1.png
new file mode 100644
index 0000000..d48db8d
Binary files /dev/null and b/ProjectBulldozer/Resources/down1.png differ
diff --git a/ProjectBulldozer/Resources/left1.png b/ProjectBulldozer/Resources/left1.png
new file mode 100644
index 0000000..cdbe6c7
Binary files /dev/null and b/ProjectBulldozer/Resources/left1.png differ
diff --git a/ProjectBulldozer/Resources/right1.png b/ProjectBulldozer/Resources/right1.png
new file mode 100644
index 0000000..b3aed57
Binary files /dev/null and b/ProjectBulldozer/Resources/right1.png differ
diff --git a/ProjectBulldozer/Resources/up1.png b/ProjectBulldozer/Resources/up1.png
new file mode 100644
index 0000000..d29315d
Binary files /dev/null and b/ProjectBulldozer/Resources/up1.png differ
diff --git a/ProjectBulldozer/Status.cs b/ProjectBulldozer/Status.cs
new file mode 100644
index 0000000..419da5e
--- /dev/null
+++ b/ProjectBulldozer/Status.cs
@@ -0,0 +1,10 @@
+
+namespace ProjectBulldozer.MovementStrategy
+{
+ public enum Status
+ {
+ NotInit,
+ InProgress,
+ Finish
+ }
+}