diff --git a/Excavator/AbstractStrategy.cs b/Excavator/AbstractStrategy.cs
new file mode 100644
index 0000000..fd0695c
--- /dev/null
+++ b/Excavator/AbstractStrategy.cs
@@ -0,0 +1,75 @@
+using Excavator.MovementStrategy;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement;
+
+using Excavator.DrawingObjects;
+
+namespace Excavator.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/Excavator/DirectionType.cs b/Excavator/DirectionType.cs
new file mode 100644
index 0000000..5e752c6
--- /dev/null
+++ b/Excavator/DirectionType.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Excavator
+{
+ public enum DirectionType
+ {
+ Up = 1,
+ Down = 2,
+ Left = 3,
+ Right = 4
+ }
+}
\ No newline at end of file
diff --git a/Excavator/DrawingExcavator.cs b/Excavator/DrawingExcavator.cs
new file mode 100644
index 0000000..2d6a998
--- /dev/null
+++ b/Excavator/DrawingExcavator.cs
@@ -0,0 +1,49 @@
+using Excavator.DrawingObjects;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using Excavator.Entities;
+
+namespace Excavator
+{
+ public class DrawingExcavator : DrawingMash
+ {
+ public DrawingExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool Bucket, bool Supports, int width, int height) : base(speed, weight, bodyColor, width, height, 215, 95)
+ {
+ if (EntityMash != null)
+ {
+ EntityMash = new EntityExcavator(speed, weight, bodyColor, additionalColor, Bucket, Supports);
+ }
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityMash is not EntityExcavator Excavator)
+ {
+ return;
+ }
+ Pen pen = new(Color.Black);
+ Pen additionalPen = new(Excavator.AdditionalColor);
+ Brush additionalBrush = new SolidBrush(Excavator.AdditionalColor);
+ base.DrawTransport(g);
+
+ if (Excavator.Bucket)
+ {
+ Brush additionalBrush2 = new
+ SolidBrush(EntityMash.BodyColor);
+
+ g.FillRectangle(additionalBrush, _startPosX + 10, _startPosY + 42, 20, 5);
+ g.FillRectangle(additionalBrush, _startPosX, _startPosY + 37, 15, 50);
+ }
+
+ if (Excavator.Supports)
+ {
+ g.FillRectangle(additionalBrush, _startPosX + 170, _startPosY + 47, 35, 5);
+ g.FillRectangle(additionalBrush, _startPosX + 190, _startPosY + 27, 15, 45);
+ g.FillRectangle(additionalBrush, _startPosX + 185, _startPosY + 72, 30, 5);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Excavator/DrawingMahs.cs b/Excavator/DrawingMahs.cs
new file mode 100644
index 0000000..5a1c6b2
--- /dev/null
+++ b/Excavator/DrawingMahs.cs
@@ -0,0 +1,138 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using Excavator.Entities;
+
+namespace Excavator.DrawingObjects
+{
+ public class DrawingMash
+ {
+ public EntityMash? EntityMash { get; protected set; }
+ public int _pictureWidth;
+ public int _pictureHeight;
+ protected int _startPosX;
+ protected int _startPosY;
+ protected readonly int _mashWidth = 150;
+ protected readonly int _mashHeight = 95;
+ public int GetPosX => _startPosX;
+ public int GetPosY => _startPosY;
+ public int GetWidth => _mashWidth;
+ public int GetHeight => _mashHeight;
+ public DrawingMash(int speed, double weight, Color bodyColor, int width, int height)
+ {
+ if (width < _mashWidth || height < _mashHeight)
+ {
+ return;
+ }
+ _pictureWidth = width;
+ _pictureHeight = height;
+ EntityMash = new EntityMash(speed, weight, bodyColor);
+ }
+ protected DrawingMash(int speed, double weight, Color bodyColor, int width, int height, int mashWidth, int mashHeight)
+ {
+ if (width < _mashWidth || height < _mashHeight)
+ {
+ return;
+ }
+ _pictureWidth = width;
+ _pictureHeight = height;
+ _mashWidth = mashWidth;
+ _mashHeight = mashHeight;
+ EntityMash = new EntityMash(speed, weight, bodyColor);
+ }
+ public void SetPosition(int x, int y)
+ {
+ if (x > _pictureWidth || y > _pictureHeight)
+ {
+ return;
+ }
+ _startPosX = x;
+ _startPosY = y;
+ }
+ public void MoveTransport(DirectionType direction)
+ {
+ if (!CanMove(direction) || EntityMash == null)
+ {
+ return;
+ }
+ switch (direction)
+ {
+ case DirectionType.Left:
+ if (_startPosX - EntityMash.Step > -50)
+ {
+ _startPosX -= (int)EntityMash.Step;
+ }
+ break;
+ case DirectionType.Up:
+ if (_startPosY - EntityMash.Step > -35)
+ {
+ _startPosY -= (int)EntityMash.Step;
+ }
+ break;
+ case DirectionType.Right:
+ if (_startPosX + _mashWidth + EntityMash.Step < _pictureWidth + 14)
+ {
+ _startPosX += (int)EntityMash.Step;
+ }
+ break;
+ case DirectionType.Down:
+ if (_startPosY + _mashHeight + EntityMash.Step < _pictureHeight)
+ {
+ _startPosY += (int)EntityMash.Step;
+ }
+ break;
+ }
+ }
+ public virtual void DrawTransport(Graphics g)
+ {
+ Pen pen = new(Color.Black);
+ Brush additionalBrush = new
+ SolidBrush(EntityMash.BodyColor);
+
+ g.FillRectangle(additionalBrush, _startPosX + 30, _startPosY + 31, 140, 35);
+ g.FillRectangle(additionalBrush, _startPosX + 60, _startPosY + 2, 15, 35);
+ g.FillRectangle(additionalBrush, _startPosX + 125, _startPosY + 2, 40, 40);
+
+ Brush additionalBrush1 = new
+ SolidBrush(EntityMash.BodyColor);
+
+ Brush gr = new SolidBrush(Color.Gray);
+
+ g.FillEllipse(additionalBrush1, _startPosX + 20, _startPosY + 72, 25, 25);
+ g.FillEllipse(additionalBrush1, _startPosX + 145, _startPosY + 72, 25, 25);
+
+ g.FillEllipse(gr, _startPosX + 55, _startPosY + 81, 17, 17);
+ g.FillEllipse(gr, _startPosX + 85, _startPosY + 81, 17, 17);
+ g.FillEllipse(gr, _startPosX + 110, _startPosY + 81, 17, 17);
+
+ g.FillEllipse(gr, _startPosX + 68, _startPosY + 72, 8, 8);
+ g.FillEllipse(gr, _startPosX + 95, _startPosY + 72, 8, 8);
+
+ Pen blackPen = new Pen(Color.Black, 3);
+ Rectangle rect1 = new Rectangle(_startPosX + 15, _startPosY + 69, 30, 30);
+ g.DrawArc(blackPen, rect1, 90, 180);
+ Rectangle rect2 = new Rectangle(_startPosX + 145, _startPosY + 69, 30, 30);
+ g.DrawArc(blackPen, rect2, -90, 180);
+ g.DrawLine(blackPen, _startPosX + 27, _startPosY + 69, _startPosX + 165, _startPosY + 69);
+ g.DrawLine(blackPen, _startPosX + 27, _startPosY + 99, _startPosX + 165, _startPosY + 99);
+ }
+ public bool CanMove(DirectionType direction)
+ {
+ if (EntityMash == null)
+ {
+ return false;
+ }
+ return direction switch
+ {
+ DirectionType.Left => _startPosX - EntityMash.Step > 0,
+ DirectionType.Up => _startPosY - EntityMash.Step > 0,
+ DirectionType.Right => _startPosX + _mashWidth + EntityMash.Step < _pictureWidth,
+ DirectionType.Down => _startPosY + _mashHeight + EntityMash.Step < _pictureHeight,
+ _ => false,
+ };
+ }
+ }
+}
\ No newline at end of file
diff --git a/Excavator/DrawingObjectMash.cs b/Excavator/DrawingObjectMash.cs
new file mode 100644
index 0000000..215d3be
--- /dev/null
+++ b/Excavator/DrawingObjectMash.cs
@@ -0,0 +1,36 @@
+using Excavator.MovementStrategy;
+using Excavator;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.NetworkInformation;
+using System.Text;
+using System.Threading.Tasks;
+
+using Excavator.DrawingObjects;
+namespace Excavator.MovementStrategy
+{
+ public class DrawingObjectMash : IMoveableObject
+ {
+
+ private readonly DrawingMash? _DrawingMash = null;
+ public DrawingObjectMash(DrawingMash DrawingMash)
+ {
+ _DrawingMash = DrawingMash;
+ }
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_DrawingMash == null || _DrawingMash.EntityMash == null)
+ {
+ return null;
+ }
+ return new ObjectParameters(_DrawingMash.GetPosX,_DrawingMash.GetPosY, _DrawingMash.GetWidth, _DrawingMash.GetHeight);
+ }
+ }
+ public int GetStep => (int)(_DrawingMash?.EntityMash?.Step ?? 0);
+ public bool CheckCanMove(DirectionType direction) => _DrawingMash?.CanMove(direction) ?? false;
+ public void MoveObject(DirectionType direction) => _DrawingMash?.MoveTransport(direction);
+ }
+}
\ No newline at end of file
diff --git a/Excavator/EntityExcavator.cs b/Excavator/EntityExcavator.cs
new file mode 100644
index 0000000..e106218
--- /dev/null
+++ b/Excavator/EntityExcavator.cs
@@ -0,0 +1,22 @@
+using Excavator.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Excavator.Entities
+{
+ public class EntityExcavator : EntityMash
+ {
+ public Color AdditionalColor { get; private set; }
+ public bool Bucket { get; private set; }
+ public bool Supports { get; private set; }
+ public EntityExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool bucket, bool supports) : base(speed, weight, bodyColor)
+ {
+ AdditionalColor = additionalColor;
+ Bucket = bucket;
+ Supports = supports;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Excavator/EntityMash.cs b/Excavator/EntityMash.cs
new file mode 100644
index 0000000..ff750f1
--- /dev/null
+++ b/Excavator/EntityMash.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Excavator.Entities
+{
+ public class EntityMash
+ {
+ public int Speed { get; private set; }
+ public double Weight { get; private set; }
+ public Color BodyColor { get; private set; }
+ public double Step => (double)Speed * 100 / Weight;
+ public EntityMash(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Excavator/FormExcavator.Designer.cs b/Excavator/FormExcavator.Designer.cs
index fffcd21..31f19c4 100644
--- a/Excavator/FormExcavator.Designer.cs
+++ b/Excavator/FormExcavator.Designer.cs
@@ -2,15 +2,7 @@
{
partial class FormExcavator
{
- ///
- /// 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))
@@ -28,111 +20,153 @@
///
private void InitializeComponent()
{
- System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormExcavator));
- this.pictureBoxExc = new System.Windows.Forms.PictureBox();
- this.buttonCreate = new System.Windows.Forms.Button();
+ this.pictureBoxExcavator = new System.Windows.Forms.PictureBox();
+ this.buttonCreateExcavator = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
- this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxExc)).BeginInit();
+ this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
+ this.buttonStep = new System.Windows.Forms.Button();
+ this.buttonCreateMash = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxExcavator)).BeginInit();
this.SuspendLayout();
//
- // pictureBoxBus
+ // pictureBoxExcavator
//
- this.pictureBoxExc.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBoxExc.Location = new System.Drawing.Point(0, 0);
- this.pictureBoxExc.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
- this.pictureBoxExc.Name = "pictureBoxBus";
- this.pictureBoxExc.Size = new System.Drawing.Size(1010, 615);
- this.pictureBoxExc.TabIndex = 1;
- this.pictureBoxExc.TabStop = false;
+ this.pictureBoxExcavator.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxExcavator.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxExcavator.Name = "pictureBoxExcavator";
+ this.pictureBoxExcavator.Size = new System.Drawing.Size(882, 453);
+ this.pictureBoxExcavator.TabIndex = 5;
+ this.pictureBoxExcavator.TabStop = false;
//
- // buttonCreate
+ // buttonCreateExcavator
//
- this.buttonCreate.Location = new System.Drawing.Point(14, 541);
- this.buttonCreate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
- this.buttonCreate.Name = "buttonCreate";
- this.buttonCreate.Size = new System.Drawing.Size(95, 57);
- this.buttonCreate.TabIndex = 2;
- this.buttonCreate.Text = "Создать";
- this.buttonCreate.UseVisualStyleBackColor = true;
- this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
+ this.buttonCreateExcavator.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreateExcavator.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);
+ this.buttonCreateExcavator.Location = new System.Drawing.Point(11, 365);
+ this.buttonCreateExcavator.Name = "buttonCreateExcavator";
+ this.buttonCreateExcavator.Size = new System.Drawing.Size(120, 73);
+ this.buttonCreateExcavator.TabIndex = 6;
+ this.buttonCreateExcavator.Text = "Создать Экскаватор";
+ this.buttonCreateExcavator.UseVisualStyleBackColor = true;
+ this.buttonCreateExcavator.Click += new System.EventHandler(this.buttonCreateExcavator_Click);
//
// buttonUp
//
- this.buttonUp.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonUp.BackgroundImage")));
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImage = global::Excavator.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonUp.Location = new System.Drawing.Point(896, 487);
- this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonUp.Location = new System.Drawing.Point(811, 377);
this.buttonUp.Name = "buttonUp";
- this.buttonUp.Size = new System.Drawing.Size(46, 53);
- this.buttonUp.TabIndex = 3;
+ this.buttonUp.Size = new System.Drawing.Size(30, 29);
+ this.buttonUp.TabIndex = 7;
this.buttonUp.UseVisualStyleBackColor = true;
- this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
- //
- // buttonDown
- //
- this.buttonDown.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonDown.BackgroundImage")));
- this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonDown.Location = new System.Drawing.Point(896, 548);
- this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
- this.buttonDown.Name = "buttonDown";
- this.buttonDown.Size = new System.Drawing.Size(46, 53);
- this.buttonDown.TabIndex = 4;
- this.buttonDown.UseVisualStyleBackColor = true;
- this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
+ this.buttonUp.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonLeft
//
- this.buttonLeft.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonLeft.BackgroundImage")));
+ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonLeft.BackgroundImage = global::Excavator.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonLeft.Location = new System.Drawing.Point(843, 547);
- this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonLeft.Location = new System.Drawing.Point(776, 413);
this.buttonLeft.Name = "buttonLeft";
- this.buttonLeft.Size = new System.Drawing.Size(46, 53);
- this.buttonLeft.TabIndex = 5;
+ this.buttonLeft.Size = new System.Drawing.Size(30, 29);
+ this.buttonLeft.TabIndex = 8;
this.buttonLeft.UseVisualStyleBackColor = true;
- this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ this.buttonLeft.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::Excavator.Properties.Resources.ArrowDown;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
+ this.buttonDown.Location = new System.Drawing.Point(811, 413);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 29);
+ this.buttonDown.TabIndex = 9;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
//
// buttonRight
//
- this.buttonRight.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("buttonRight.BackgroundImage")));
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::Excavator.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonRight.Location = new System.Drawing.Point(949, 547);
- this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonRight.Location = new System.Drawing.Point(848, 413);
this.buttonRight.Name = "buttonRight";
- this.buttonRight.Size = new System.Drawing.Size(46, 53);
- this.buttonRight.TabIndex = 6;
+ this.buttonRight.Size = new System.Drawing.Size(30, 29);
+ this.buttonRight.TabIndex = 10;
this.buttonRight.UseVisualStyleBackColor = true;
- this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ this.buttonRight.Click += new System.EventHandler(this.buttonMove_Click);
+ //
+ // comboBoxStrategy
+ //
+ this.comboBoxStrategy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.comboBoxStrategy.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxStrategy.FormattingEnabled = true;
+ this.comboBoxStrategy.Items.AddRange(new object[] {
+ "В центр",
+ "В правый нижний угол"});
+ this.comboBoxStrategy.Location = new System.Drawing.Point(719, 12);
+ this.comboBoxStrategy.Name = "comboBoxStrategy";
+ this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28);
+ this.comboBoxStrategy.TabIndex = 11;
+ //
+ // buttonStep
+ //
+ this.buttonStep.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonStep.Location = new System.Drawing.Point(747, 45);
+ this.buttonStep.Name = "buttonStep";
+ this.buttonStep.Size = new System.Drawing.Size(94, 29);
+ this.buttonStep.TabIndex = 12;
+ this.buttonStep.Text = "Шаг";
+ this.buttonStep.UseVisualStyleBackColor = true;
+ this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
+ //
+ // buttonCreateMash
+ //
+ this.buttonCreateMash.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreateMash.Location = new System.Drawing.Point(138, 365);
+ this.buttonCreateMash.Name = "buttonCreateMash";
+ this.buttonCreateMash.Size = new System.Drawing.Size(120, 74);
+ this.buttonCreateMash.TabIndex = 13;
+ this.buttonCreateMash.Text = "Создать Гусеничную машину";
+ this.buttonCreateMash.UseVisualStyleBackColor = true;
+ this.buttonCreateMash.Click += new System.EventHandler(this.buttonCreateMash_Click);
//
// FormExcavator
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1010, 615);
+ this.ClientSize = new System.Drawing.Size(882, 453);
+ this.Controls.Add(this.buttonCreateMash);
+ this.Controls.Add(this.buttonStep);
+ this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.buttonRight);
- this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
+ this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonUp);
- this.Controls.Add(this.buttonCreate);
- this.Controls.Add(this.pictureBoxExc);
- this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.Controls.Add(this.buttonCreateExcavator);
+ this.Controls.Add(this.pictureBoxExcavator);
this.Name = "FormExcavator";
- this.Text = "Bus";
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxExc)).EndInit();
+ this.Text = "Excavator";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxExcavator)).EndInit();
this.ResumeLayout(false);
}
#endregion
- private PictureBox pictureBoxExc;
- private Button buttonCreate;
+ private PictureBox pictureBoxExcavator;
+ private Button buttonCreateExcavator;
private Button buttonUp;
- private Button buttonDown;
private Button buttonLeft;
+ private Button buttonDown;
private Button buttonRight;
+ private ComboBox comboBoxStrategy;
+ private Button buttonStep;
+ private Button buttonCreateMash;
}
}
\ No newline at end of file
diff --git a/Excavator/FormExcavator.cs b/Excavator/FormExcavator.cs
index abe0b98..d71bc68 100644
--- a/Excavator/FormExcavator.cs
+++ b/Excavator/FormExcavator.cs
@@ -1,43 +1,56 @@
+using Excavator.DrawingObjects;
+using Excavator.MovementStrategy;
+
namespace Excavator
{
public partial class FormExcavator : Form
{
- private DrawingExc? _drawingExc;
+ private DrawingMash? _DrawingMash;
+ private AbstractStrategy? _abstractStrategy;
public FormExcavator()
{
InitializeComponent();
}
private void Draw()
{
- if (_drawingExc == null)
+ if (_DrawingMash == null)
{
return;
}
- Bitmap bmp = new(pictureBoxExc.Width, pictureBoxExc.Height);
+ Bitmap bmp = new(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawingExc.DrawTransport(gr);
- pictureBoxExc.Image = bmp;
+ _DrawingMash.DrawTransport(gr);
+ pictureBoxExcavator.Image = bmp;
}
- private void buttonCreate_Click(object sender, EventArgs e)
+ private void buttonCreateExcavator_Click(object sender, EventArgs e)
{
Random random = new();
- _drawingExc = new DrawingExc();
- EntityExcavator bus = new EntityExcavator();
- bus.Init(random.Next(100, 300),
+ _DrawingMash = new DrawingExcavator(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)));
- _drawingExc.Init(bus, pictureBoxExc.Width, pictureBoxExc.Height);
- _drawingExc.SetPosition(random.Next(10, 100),
- random.Next(10, 100));
+ true,
+ Convert.ToBoolean(random.Next(0, 2)),
+ pictureBoxExcavator.Width, pictureBoxExcavator.Height);
+ _DrawingMash.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
- private void ButtonMove_Click(object sender, EventArgs e)
+ private void buttonCreateMash_Click(object sender, EventArgs e)
{
- if (_drawingExc == null)
+ Random random = new();
+ _DrawingMash = new DrawingMash(random.Next(100, 300),
+ random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
+ random.Next(0, 256)),
+ pictureBoxExcavator.Width, pictureBoxExcavator.Height);
+ _DrawingMash.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ Draw();
+ }
+ private void buttonMove_Click(object sender, EventArgs e)
+ {
+ if (_DrawingMash == null)
{
return;
}
@@ -45,19 +58,53 @@ namespace Excavator
switch (name)
{
case "buttonUp":
- _drawingExc.MoveTransport(Direction.Up);
+ _DrawingMash.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
- _drawingExc.MoveTransport(Direction.Down);
+ _DrawingMash.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
- _drawingExc.MoveTransport(Direction.Left);
+ _DrawingMash.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
- _drawingExc.MoveTransport(Direction.Right);
+ _DrawingMash.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
+ private void buttonStep_Click(object sender, EventArgs e)
+ {
+ if (_DrawingMash == null)
+ {
+ return;
+ }
+ if (comboBoxStrategy.Enabled)
+ {
+ _abstractStrategy = comboBoxStrategy.SelectedIndex
+ switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_abstractStrategy == null)
+ {
+ return;
+ }
+ _abstractStrategy.SetData(new DrawingObjectMash(_DrawingMash), pictureBoxExcavator.Width, pictureBoxExcavator.Height);
+ comboBoxStrategy.Enabled = false;
+ }
+ if (_abstractStrategy == null)
+ {
+ return;
+ }
+ _abstractStrategy.MakeStep();
+ Draw();
+ if (_abstractStrategy.GetStatus() == Status.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _abstractStrategy = null;
+ }
+ }
}
-}
+}
\ No newline at end of file
diff --git a/Excavator/IMoveableObject.cs b/Excavator/IMoveableObject.cs
new file mode 100644
index 0000000..48cc023
--- /dev/null
+++ b/Excavator/IMoveableObject.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using Excavator.DrawingObjects;
+
+namespace Excavator.MovementStrategy
+{
+ public interface IMoveableObject
+ {
+ ObjectParameters? GetObjectPosition { get; }
+ int GetStep { get; }
+ bool CheckCanMove(DirectionType direction);
+ void MoveObject(DirectionType direction);
+ }
+
+}
\ No newline at end of file
diff --git a/Excavator/MoveToBorder.cs b/Excavator/MoveToBorder.cs
new file mode 100644
index 0000000..af69cf6
--- /dev/null
+++ b/Excavator/MoveToBorder.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Excavator.MovementStrategy
+{
+ internal class MoveToBorder : AbstractStrategy
+ {
+ protected override bool IsTargetDestinaion()
+ {
+ var objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.RightBorder <= FieldWidth &&
+ objParams.RightBorder + GetStep() >= FieldWidth &&
+ objParams.DownBorder <= FieldHeight &&
+ objParams.DownBorder + GetStep() >= FieldHeight;
+ }
+ protected override void MoveToTarget()
+ {
+ var objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ var diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+ var diffY = objParams.ObjectMiddleVertical - FieldHeight;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Excavator/MoveToCenter.cs b/Excavator/MoveToCenter.cs
new file mode 100644
index 0000000..38444c0
--- /dev/null
+++ b/Excavator/MoveToCenter.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Excavator.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();
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Excavator/ObjectParameters.cs b/Excavator/ObjectParameters.cs
new file mode 100644
index 0000000..e0cbdde
--- /dev/null
+++ b/Excavator/ObjectParameters.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Excavator.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;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Excavator/Status.cs b/Excavator/Status.cs
new file mode 100644
index 0000000..7515059
--- /dev/null
+++ b/Excavator/Status.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Excavator.MovementStrategy
+{
+ public enum Status
+ {
+ NotInit,
+ InProgress,
+ Finish
+ }
+}