diff --git a/Excavator/AbstractStrategy.cs b/Excavator/AbstractStrategy.cs
index fd0695c..5df72e0 100644
--- a/Excavator/AbstractStrategy.cs
+++ b/Excavator/AbstractStrategy.cs
@@ -71,5 +71,4 @@ namespace Excavator.MovementStrategy
return false;
}
}
-}
-
+}
\ No newline at end of file
diff --git a/Excavator/DirectionType.cs b/Excavator/DirectionType.cs
index 5e752c6..71675bc 100644
--- a/Excavator/DirectionType.cs
+++ b/Excavator/DirectionType.cs
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Excavator
{
public enum DirectionType
- {
+ {
Up = 1,
Down = 2,
Left = 3,
diff --git a/Excavator/DrawingExcavator.cs b/Excavator/DrawingExcavator.cs
index 2d6a998..58ce673 100644
--- a/Excavator/DrawingExcavator.cs
+++ b/Excavator/DrawingExcavator.cs
@@ -11,12 +11,13 @@ 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)
+ public DrawingExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool bucket, bool supports, int width, int height) : base(speed, weight, bodyColor, width, height, 180, 110)
{
if (EntityMash != null)
{
- EntityMash = new EntityExcavator(speed, weight, bodyColor, additionalColor, Bucket, Supports);
+ EntityMash = new EntityExcavator(speed, weight, bodyColor, additionalColor, bucket, supports);
}
+
}
public override void DrawTransport(Graphics g)
{
@@ -25,24 +26,23 @@ namespace Excavator
return;
}
Pen pen = new(Color.Black);
- Pen additionalPen = new(Excavator.AdditionalColor);
- Brush additionalBrush = new SolidBrush(Excavator.AdditionalColor);
+ Pen additionalPen = new(Excavator.Body);
+ Brush additionalBrush = new SolidBrush(Excavator.Body);
base.DrawTransport(g);
-
- if (Excavator.Bucket)
+ 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);
+ g.FillRectangle(additionalBrush, _startPosX + 5, _startPosY + 37, 10, 50);
}
-
- if (Excavator.Supports)
+
+ 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);
+ g.FillRectangle(additionalBrush, _startPosX + 170, _startPosY + 47, 25, 5);
+ g.FillRectangle(additionalBrush, _startPosX + 180, _startPosY + 27, 15, 45);
+ g.FillRectangle(additionalBrush, _startPosX + 175, _startPosY + 72, 25, 5);
}
}
}
diff --git a/Excavator/DrawingMash.cs b/Excavator/DrawingMash.cs
new file mode 100644
index 0000000..85314a9
--- /dev/null
+++ b/Excavator/DrawingMash.cs
@@ -0,0 +1,140 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using Excavator.Entities;
+using Excavator.MovementStrategy;
+
+namespace Excavator.DrawingObjects
+{
+ public class DrawingMash
+ {
+ public IMoveableObject GetMoveableObject => new DrawingObjectMash(this);
+ public EntityMash? EntityMash { get; protected set; }
+ public int _pictureWidth;
+ public int _pictureHeight;
+ protected int _startPosX;
+ protected int _startPosY;
+ protected readonly int _mashWidth = 175;
+ protected readonly int _mashHeight = 115;
+ 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 > 0)
+ {
+ _startPosX -= (int)EntityMash.Step;
+ }
+ break;
+ case DirectionType.Up:
+ if (_startPosY - EntityMash.Step > 0)
+ {
+ _startPosY -= (int)EntityMash.Step;
+ }
+ break;
+ case DirectionType.Right:
+ if (_startPosX + _mashWidth + EntityMash.Step < _pictureWidth)
+ {
+ _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
index 215d3be..7dc09f4 100644
--- a/Excavator/DrawingObjectMash.cs
+++ b/Excavator/DrawingObjectMash.cs
@@ -12,25 +12,24 @@ namespace Excavator.MovementStrategy
{
public class DrawingObjectMash : IMoveableObject
{
-
- private readonly DrawingMash? _DrawingMash = null;
- public DrawingObjectMash(DrawingMash DrawingMash)
+ private readonly DrawingMash? _drawingMash = null;
+ public DrawingObjectMash(DrawingMash drawingMash)
{
- _DrawingMash = DrawingMash;
+ _drawingMash = drawingMash;
}
public ObjectParameters? GetObjectPosition
{
get
{
- if (_DrawingMash == null || _DrawingMash.EntityMash == null)
+ if (_drawingMash == null || _drawingMash.EntityMash == null)
{
return null;
}
- return new ObjectParameters(_DrawingMash.GetPosX,_DrawingMash.GetPosY, _DrawingMash.GetWidth, _DrawingMash.GetHeight);
+ 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);
+ 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
index e106218..9859c47 100644
--- a/Excavator/EntityExcavator.cs
+++ b/Excavator/EntityExcavator.cs
@@ -9,14 +9,14 @@ 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)
+ public Color Body { 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;
+ Body = additionalColor;
+ bucket = Bucket;
+ supports = Supports;
}
}
}
\ No newline at end of file
diff --git a/Excavator/FormExcavator.Designer.cs b/Excavator/FormExcavator.Designer.cs
index 31f19c4..b89cd92 100644
--- a/Excavator/FormExcavator.Designer.cs
+++ b/Excavator/FormExcavator.Designer.cs
@@ -29,6 +29,7 @@
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
this.buttonStep = new System.Windows.Forms.Button();
this.buttonCreateMash = new System.Windows.Forms.Button();
+ this.buttonSelect = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxExcavator)).BeginInit();
this.SuspendLayout();
//
@@ -56,50 +57,46 @@
// buttonUp
//
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.BackgroundImage = global::Excavator.Properties.Resources.ArrowUp;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonUp.Location = new System.Drawing.Point(811, 377);
this.buttonUp.Name = "buttonUp";
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);
//
// buttonLeft
//
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.BackgroundImage = global::Excavator.Properties.Resources.ArrowLeft;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonLeft.Location = new System.Drawing.Point(776, 413);
+ this.buttonLeft.Location = new System.Drawing.Point(775, 413);
this.buttonLeft.Name = "buttonLeft";
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);
//
// 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.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.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.BackgroundImage = global::Excavator.Properties.Resources.ArrowRight;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
this.buttonRight.Location = new System.Drawing.Point(848, 413);
this.buttonRight.Name = "buttonRight";
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);
//
// comboBoxStrategy
//
@@ -123,7 +120,6 @@
this.buttonStep.TabIndex = 12;
this.buttonStep.Text = "Шаг";
this.buttonStep.UseVisualStyleBackColor = true;
- this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
//
// buttonCreateMash
//
@@ -136,11 +132,23 @@
this.buttonCreateMash.UseVisualStyleBackColor = true;
this.buttonCreateMash.Click += new System.EventHandler(this.buttonCreateMash_Click);
//
+ // buttonSelect
+ //
+ this.buttonSelect.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonSelect.Location = new System.Drawing.Point(273, 365);
+ this.buttonSelect.Name = "buttonSelect";
+ this.buttonSelect.Size = new System.Drawing.Size(120, 73);
+ this.buttonSelect.TabIndex = 14;
+ this.buttonSelect.Text = "Выбрать объект";
+ this.buttonSelect.UseVisualStyleBackColor = true;
+ this.buttonSelect.Click += new System.EventHandler(this.buttonSelect_Click);
+ //
// FormExcavator
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(882, 453);
+ this.Controls.Add(this.buttonSelect);
this.Controls.Add(this.buttonCreateMash);
this.Controls.Add(this.buttonStep);
this.Controls.Add(this.comboBoxStrategy);
@@ -151,7 +159,7 @@
this.Controls.Add(this.buttonCreateExcavator);
this.Controls.Add(this.pictureBoxExcavator);
this.Name = "FormExcavator";
- this.Text = "Excavator";
+ this.Text = "Экскаватор";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxExcavator)).EndInit();
this.ResumeLayout(false);
@@ -168,5 +176,6 @@
private ComboBox comboBoxStrategy;
private Button buttonStep;
private Button buttonCreateMash;
+ private Button buttonSelect;
}
}
\ No newline at end of file
diff --git a/Excavator/FormExcavator.cs b/Excavator/FormExcavator.cs
index d71bc68..92bc37f 100644
--- a/Excavator/FormExcavator.cs
+++ b/Excavator/FormExcavator.cs
@@ -5,52 +5,66 @@ namespace Excavator
{
public partial class FormExcavator : Form
{
- private DrawingMash? _DrawingMash;
+ private DrawingMash? _drawingMash;
private AbstractStrategy? _abstractStrategy;
+ public DrawingMash? SelectedMash { get; private set; }
public FormExcavator()
{
InitializeComponent();
+ _abstractStrategy = null;
+ SelectedMash = null;
}
private void Draw()
{
- if (_DrawingMash == null)
+ if (_drawingMash == null)
{
return;
}
Bitmap bmp = new(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
Graphics gr = Graphics.FromImage(bmp);
- _DrawingMash.DrawTransport(gr);
+ _drawingMash.DrawTransport(gr);
pictureBoxExcavator.Image = bmp;
}
private void buttonCreateExcavator_Click(object sender, EventArgs e)
{
Random random = new();
- _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)),
- true,
- Convert.ToBoolean(random.Next(0, 2)),
+ Color color = Color.FromArgb(random.Next(0, 256),
+ random.Next(0, 256), random.Next(0, 256));
+ Color color1 = Color.FromArgb(random.Next(0, 256),
+ random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ ColorDialog dialog1 = new();
+ if (dialog.ShowDialog() == DialogResult.OK && dialog1.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ color1 = dialog1.Color;
+ }
+ _drawingMash = new DrawingExcavator(random.Next(100, 300),
+ random.Next(1000, 3000), color, color1, true, true,
pictureBoxExcavator.Width, pictureBoxExcavator.Height);
- _DrawingMash.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ _drawingMash.SetPosition(random.Next(10, 100), random.Next(10,
+ 100));
Draw();
}
private void buttonCreateMash_Click(object sender, EventArgs e)
{
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)),
+ Color color = Color.FromArgb(random.Next(0, 256),
+ random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ _drawingMash = new DrawingMash(random.Next(100, 300),
+ random.Next(1000, 3000), color,
pictureBoxExcavator.Width, pictureBoxExcavator.Height);
- _DrawingMash.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ _drawingMash.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
private void buttonMove_Click(object sender, EventArgs e)
{
- if (_DrawingMash == null)
+ if (_drawingMash == null)
{
return;
}
@@ -58,23 +72,23 @@ namespace Excavator
switch (name)
{
case "buttonUp":
- _DrawingMash.MoveTransport(DirectionType.Up);
+ _drawingMash.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
- _DrawingMash.MoveTransport(DirectionType.Down);
+ _drawingMash.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
- _DrawingMash.MoveTransport(DirectionType.Left);
+ _drawingMash.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
- _DrawingMash.MoveTransport(DirectionType.Right);
+ _drawingMash.MoveTransport(DirectionType.Right);
break;
}
Draw();
}
private void buttonStep_Click(object sender, EventArgs e)
{
- if (_DrawingMash == null)
+ if (_drawingMash == null)
{
return;
}
@@ -91,7 +105,7 @@ namespace Excavator
{
return;
}
- _abstractStrategy.SetData(new DrawingObjectMash(_DrawingMash), pictureBoxExcavator.Width, pictureBoxExcavator.Height);
+ _abstractStrategy.SetData(new DrawingObjectMash(_drawingMash), pictureBoxExcavator.Width, pictureBoxExcavator.Height);
comboBoxStrategy.Enabled = false;
}
if (_abstractStrategy == null)
@@ -106,5 +120,10 @@ namespace Excavator
_abstractStrategy = null;
}
}
+ private void buttonSelect_Click(object sender, EventArgs e)
+ {
+ SelectedMash = _drawingMash;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/Excavator/FormMashCollection.Designer.cs b/Excavator/FormMashCollection.Designer.cs
new file mode 100644
index 0000000..7468e0e
--- /dev/null
+++ b/Excavator/FormMashCollection.Designer.cs
@@ -0,0 +1,114 @@
+namespace Excavator
+{
+ partial class FormMashCollection
+ {
+ private System.ComponentModel.IContainer components = null;
+ 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.pictureBoxCollection = new System.Windows.Forms.PictureBox();
+ this.labelInstruments = new System.Windows.Forms.Label();
+ this.buttonAdd = new System.Windows.Forms.Button();
+ this.maskedTextBoxNumber = new System.Windows.Forms.TextBox();
+ this.buttonDelete = new System.Windows.Forms.Button();
+ this.buttonUpdate = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
+ this.SuspendLayout();
+ //
+ // pictureBoxCollection
+ //
+ this.pictureBoxCollection.Location = new System.Drawing.Point(1, -3);
+ this.pictureBoxCollection.Name = "pictureBoxCollection";
+ this.pictureBoxCollection.Size = new System.Drawing.Size(918, 1232);
+ this.pictureBoxCollection.TabIndex = 0;
+ this.pictureBoxCollection.TabStop = false;
+ //
+ // labelInstruments
+ //
+ this.labelInstruments.AutoSize = true;
+ this.labelInstruments.Location = new System.Drawing.Point(974, 29);
+ this.labelInstruments.Name = "labelInstruments";
+ this.labelInstruments.Size = new System.Drawing.Size(103, 20);
+ this.labelInstruments.TabIndex = 1;
+ this.labelInstruments.Text = "Инструменты";
+ //
+ // buttonAdd
+ //
+ this.buttonAdd.Location = new System.Drawing.Point(960, 84);
+ this.buttonAdd.Name = "buttonAdd";
+ this.buttonAdd.Size = new System.Drawing.Size(184, 59);
+ this.buttonAdd.TabIndex = 2;
+ this.buttonAdd.Text = "Добавить объект";
+ this.buttonAdd.UseVisualStyleBackColor = true;
+ this.buttonAdd.Click += new System.EventHandler(this.ButtonAddMash_Click);
+ //
+ // maskedTextBoxNumber
+ //
+ this.maskedTextBoxNumber.Location = new System.Drawing.Point(999, 187);
+ this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ this.maskedTextBoxNumber.Size = new System.Drawing.Size(125, 27);
+ this.maskedTextBoxNumber.TabIndex = 3;
+ //
+ // buttonDelete
+ //
+ this.buttonDelete.Location = new System.Drawing.Point(960, 223);
+ this.buttonDelete.Name = "buttonDelete";
+ this.buttonDelete.Size = new System.Drawing.Size(189, 60);
+ this.buttonDelete.TabIndex = 4;
+ this.buttonDelete.Text = "Удалить объект";
+ this.buttonDelete.UseVisualStyleBackColor = true;
+ this.buttonDelete.Click += new System.EventHandler(this.ButtonRemoveMash_Click);
+ //
+ // buttonUpdate
+ //
+ this.buttonUpdate.Location = new System.Drawing.Point(960, 347);
+ this.buttonUpdate.Name = "buttonUpdate";
+ this.buttonUpdate.Size = new System.Drawing.Size(189, 60);
+ this.buttonUpdate.TabIndex = 5;
+ this.buttonUpdate.Text = "Обновить";
+ this.buttonUpdate.UseVisualStyleBackColor = true;
+ this.buttonUpdate.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
+ //
+ // FormMashCollection
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1317, 1055);
+ this.Controls.Add(this.buttonUpdate);
+ this.Controls.Add(this.buttonDelete);
+ this.Controls.Add(this.maskedTextBoxNumber);
+ this.Controls.Add(this.buttonAdd);
+ this.Controls.Add(this.labelInstruments);
+ this.Controls.Add(this.pictureBoxCollection);
+ this.Name = "FormMashCollection";
+ this.Text = "Экскаватор";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxCollection;
+ private Label labelInstruments;
+ private Button buttonAdd;
+ private TextBox maskedTextBoxNumber;
+ private Button buttonDelete;
+ private Button buttonUpdate;
+ }
+}
\ No newline at end of file
diff --git a/Excavator/FormMashCollection.cs b/Excavator/FormMashCollection.cs
new file mode 100644
index 0000000..b194662
--- /dev/null
+++ b/Excavator/FormMashCollection.cs
@@ -0,0 +1,74 @@
+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;
+using Excavator.DrawingObjects;
+using Excavator;
+using Excavator.MovementStrategy;
+
+namespace Excavator
+{
+ public partial class FormMashCollection : Form
+ {
+ private readonly MashGenericCollection _Mash;
+ public FormMashCollection()
+ {
+ InitializeComponent();
+ _Mash = new MashGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+
+ }
+ private void ButtonAddMash_Click(object sender, EventArgs e)
+ {
+ FormExcavator form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (_Mash + form.SelectedMash != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollection.Image = _Mash.ShowMash();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ private void ButtonRemoveMash_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = 0;
+ try
+ {
+ pos = Convert.ToInt32(maskedTextBoxNumber.Text) ;
+
+ }
+ catch
+ {
+ MessageBox.Show("Ошибка ввода данных");
+ return;
+ }
+ if (_Mash - (_Mash.ReturnLength() - pos))
+ {
+ MessageBox.Show("Объект удален");
+ pictureBoxCollection.Image = _Mash.ShowMash();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ private void ButtonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image = _Mash.ShowMash();
+ }
+ }
+}
diff --git a/Excavator/FormMashCollection.resx b/Excavator/FormMashCollection.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/Excavator/FormMashCollection.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
\ No newline at end of file
diff --git a/Excavator/IMoveableObject.cs b/Excavator/IMoveableObject.cs
index 48cc023..9fae518 100644
--- a/Excavator/IMoveableObject.cs
+++ b/Excavator/IMoveableObject.cs
@@ -15,5 +15,4 @@ namespace Excavator.MovementStrategy
bool CheckCanMove(DirectionType direction);
void MoveObject(DirectionType direction);
}
-
}
\ No newline at end of file
diff --git a/Excavator/MashGenericCollection.cs b/Excavator/MashGenericCollection.cs
new file mode 100644
index 0000000..d41a75c
--- /dev/null
+++ b/Excavator/MashGenericCollection.cs
@@ -0,0 +1,105 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Excavator.DrawingObjects;
+using Excavator.MovementStrategy;
+
+namespace Excavator
+{
+ internal class MashGenericCollection
+ where T : DrawingMash
+ where U : IMoveableObject
+ {
+ private readonly int _pictureWidth;
+ private readonly int _pictureHeight;
+ private readonly int _placeSizeWidth = 200;
+ private readonly int _placeSizeHeight = 120;
+ private readonly SetGeneric _collection;
+
+ public MashGenericCollection(int picWidth, int picHeight)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+
+ _collection = new SetGeneric(width * height);
+ }
+ public static int operator +(MashGenericCollection collect, T? obj)
+ {
+ if (obj != null)
+ {
+ return collect._collection.Insert(obj);
+ }
+ return -1;
+ }
+ public static bool operator -(MashGenericCollection collect, int pos)
+ {
+ if (collect._collection.Get(pos) == null)
+ {
+ return false;
+ }
+ return collect?._collection.Remove(pos) ?? false;
+ }
+
+ public int ReturnLength()
+ {
+ return _collection.Count;
+ }
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObject;
+ }
+ public Bitmap ShowMash()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawObjects(gr);
+ return bmp;
+ }
+ private void DrawBackground(Graphics gr)
+ {
+ Pen pen = new(Color.Black, 3);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; ++i)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
+ {
+ gr.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j * _placeSizeHeight);
+ gr.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ }
+ }
+ }
+ private void DrawObjects(Graphics g)
+ {
+ int x = 0;
+ int y = 0;
+ int index = -1;
+ for (int i = 0; i <= _collection.Count; ++i)
+ {
+ DrawingMash _Mash = _collection.Get(i);
+ x = 0;
+ y = 0;
+ if (_Mash != null)
+ {
+ index = _collection.Count - i;
+ while ((index - _pictureWidth / _placeSizeWidth) >= 0)
+ {
+ y++;
+ index -= _pictureWidth / _placeSizeWidth;
+ }
+ if (index > 0)
+ {
+ x += index;
+ }
+ x = _pictureWidth / _placeSizeWidth - 1 - x;
+ _Mash.SetPosition(_placeSizeWidth * x, _placeSizeHeight * y);
+
+ _Mash.DrawTransport(g);
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/Excavator/MoveToBorder.cs b/Excavator/MoveToBorder.cs
index af69cf6..aa9754e 100644
--- a/Excavator/MoveToBorder.cs
+++ b/Excavator/MoveToBorder.cs
@@ -38,6 +38,7 @@ namespace Excavator.MovementStrategy
{
MoveRight();
}
+
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight;
if (Math.Abs(diffY) > GetStep())
diff --git a/Excavator/MoveToCenter.cs b/Excavator/MoveToCenter.cs
index 38444c0..f79d833 100644
--- a/Excavator/MoveToCenter.cs
+++ b/Excavator/MoveToCenter.cs
@@ -38,6 +38,7 @@ namespace Excavator.MovementStrategy
{
MoveRight();
}
+
}
var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
if (Math.Abs(diffY) > GetStep())
diff --git a/Excavator/Program.cs b/Excavator/Program.cs
index 8249c53..476326d 100644
--- a/Excavator/Program.cs
+++ b/Excavator/Program.cs
@@ -1,5 +1,3 @@
-using System.Drawing;
-
namespace Excavator
{
internal static class Program
@@ -8,7 +6,7 @@ namespace Excavator
static void Main()
{
ApplicationConfiguration.Initialize();
- Application.Run(new FormExcavator());
+ Application.Run(new FormMashCollection());
}
}
}
\ No newline at end of file
diff --git a/Excavator/SetGeneric.cs b/Excavator/SetGeneric.cs
new file mode 100644
index 0000000..d5020d6
--- /dev/null
+++ b/Excavator/SetGeneric.cs
@@ -0,0 +1,85 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Excavator
+{
+ internal class SetGeneric
+ where T : class
+
+ {
+ private readonly T?[] _places;
+ public int Count => _places.Length - 1;
+ public SetGeneric(int count)
+ {
+ _places = new T?[count];
+ }
+ public int Insert(T Mash)
+ {
+ int pos = Count - 1;
+ if (_places[Count] != null)
+ {
+ for (int i = pos; i > 0; --i)
+ {
+ if (_places[i] == null)
+ {
+ pos = i;
+ break;
+ }
+ }
+ for (int i = pos + 1; i <= Count; ++i)
+ {
+ _places[i - 1] = _places[i];
+ }
+ }
+ _places[Count] = Mash;
+ return pos;
+ }
+ public bool Insert(T Mash, int position)
+ {
+ if (position < 0 || position > Count)
+ {
+ return false;
+ }
+ if (_places[Count] != null)
+ {
+ int pos = Count;
+ for (int i = Count; i > 0; --i)
+ {
+
+ if (_places[i] == null)
+ {
+ pos = i;
+ break;
+ }
+ }
+ for (int i = Count; i >= pos; --i)
+ {
+ _places[i - 1] = _places[i];
+ }
+ }
+ _places[Count] = Mash;
+ return true;
+ }
+ public bool Remove(int position)
+ {
+ if (position < 0 || position > Count)
+ {
+ return false;
+ }
+ _places[position] = null;
+
+ return true;
+ }
+ public T? Get(int position)
+ {
+ if (position < 0 || position > Count)
+ {
+ return null;
+ }
+ return _places[position];
+ }
+ }
+}