diff --git a/DumpTruck/DumpTruck/AbstractStrategy.cs b/DumpTruck/DumpTruck/AbstractStrategy.cs
new file mode 100644
index 0000000..9d92804
--- /dev/null
+++ b/DumpTruck/DumpTruck/AbstractStrategy.cs
@@ -0,0 +1,131 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck.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();
+ }
+ ///
+ /// Перемещение влево
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveLeft() => MoveTo(DirectionType.Left);
+ ///
+ /// Перемещение вправо
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveRight() => MoveTo(DirectionType.Right);
+ ///
+ /// Перемещение вверх
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveUp() => MoveTo(DirectionType.Up);
+ ///
+ /// Перемещение вниз
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ 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();
+ ///
+ /// Попытка перемещения в требуемом направлении
+ ///
+ /// Направление
+ /// Результат попытки (true - удалось переместиться, false - неудача)
+ 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/DumpTruck/DumpTruck/DirectionType.cs b/DumpTruck/DumpTruck/DirectionType.cs
new file mode 100644
index 0000000..2ae426b
--- /dev/null
+++ b/DumpTruck/DumpTruck/DirectionType.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck
+{
+ public enum DirectionType
+ {
+ Up = 1,
+ Down = 2,
+ Left = 3,
+ Right = 4
+ }
+}
diff --git a/DumpTruck/DumpTruck/DrawningDumpTruck.cs b/DumpTruck/DumpTruck/DrawningDumpTruck.cs
new file mode 100644
index 0000000..64e5158
--- /dev/null
+++ b/DumpTruck/DumpTruck/DrawningDumpTruck.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using DumpTruck.DrawningObjects;
+using DumpTruck.Entities;
+
+namespace DumpTruck.DrawningObjects
+{
+ public class DrawningDumpTruck: DrawningTruck
+ {
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Ширина картинки
+ /// Высота картинки
+ /// Признак наличия груза
+ /// Признак наличия тента
+ public DrawningDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool tent, int width, int height) :
+ base(speed, weight, bodyColor, width, height, 110, 60)
+ {
+ if (EntityTruck != null)
+ {
+ EntityTruck = new EntityDumpTruck(speed, weight, bodyColor, additionalColor, bodyKit, tent);
+ }
+ }
+
+ ///
+ /// Отрисовка автомобиля
+ ///
+ ///
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityTruck is not EntityDumpTruck dumpTruck)
+ {
+ return;
+ }
+
+ Brush brushAdditionalColor = new SolidBrush(dumpTruck.AdditionalColor);
+ Brush brushWhite = new SolidBrush(Color.White);
+ Pen penBlack = new Pen(Color.Black);
+
+ base.DrawTransport(g);
+
+ if (dumpTruck.BodyKit)
+ {
+ g.FillRectangle(brushAdditionalColor, _startPosX, _startPosY + 30, 100, 5);
+ g.FillRectangle(brushAdditionalColor, _startPosX, _startPosY + 10, 70, 20);
+ g.DrawRectangle(penBlack, _startPosX, _startPosY + 30, 100, 5);
+ g.DrawRectangle(penBlack, _startPosX, _startPosY + 10, 70, 20);
+
+ if (dumpTruck.Tent)
+ {
+ g.FillRectangle(brushWhite, _startPosX, _startPosY + 10, 70, 5);
+ g.DrawRectangle(penBlack, _startPosX, _startPosY + 10, 70, 5);
+ }
+ }
+ }
+ }
+}
diff --git a/DumpTruck/DumpTruck/DrawningObjectTruck.cs b/DumpTruck/DumpTruck/DrawningObjectTruck.cs
new file mode 100644
index 0000000..70d7303
--- /dev/null
+++ b/DumpTruck/DumpTruck/DrawningObjectTruck.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using DumpTruck.DrawningObjects;
+
+namespace DumpTruck.MovementStrategy
+{
+ public class DrawningObjectTruck : IMoveableObject
+ {
+ private readonly DrawningTruck? _drawningTruck = null;
+ public DrawningObjectTruck(DrawningTruck drawningTruck)
+ {
+ _drawningTruck = drawningTruck;
+ }
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_drawningTruck == null || _drawningTruck.EntityTruck == null)
+ {
+ return null;
+ }
+ return new ObjectParameters(_drawningTruck.GetPosX, _drawningTruck.GetPosY, _drawningTruck.GetWidth, _drawningTruck.GetHeight);
+ }
+ }
+ public int GetStep => (int)(_drawningTruck?.EntityTruck?.Step ?? 0);
+
+ public bool CheckCanMove(DirectionType direction) => _drawningTruck?.CanMove(direction) ?? false;
+ public void MoveObject(DirectionType direction) => _drawningTruck?.MoveTransport(direction);
+ }
+}
diff --git a/DumpTruck/DumpTruck/DrawningTruck.cs b/DumpTruck/DumpTruck/DrawningTruck.cs
new file mode 100644
index 0000000..985b916
--- /dev/null
+++ b/DumpTruck/DumpTruck/DrawningTruck.cs
@@ -0,0 +1,228 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using DumpTruck.Entities;
+using DumpTruck.MovementStrategy;
+
+namespace DumpTruck.DrawningObjects
+{
+ public class DrawningTruck
+ {
+ ///
+ /// Класс-сущность
+ ///
+ public EntityTruck? EntityTruck { get; protected set; }
+ ///
+ /// Получение объекта IMoveableObject из объекта DrawningCar
+ ///
+ public IMoveableObject GetMoveableObject => new DrawningObjectTruck(this);
+ ///
+ /// Ширина окна
+ ///
+ private int _pictureWidth;
+ ///
+ /// Высота окна
+ ///
+ private int _pictureHeight;
+ ///
+ /// Левая координата прорисовки автомобиля
+ ///
+ protected int _startPosX;
+ ///
+ /// Верхняя кооридната прорисовки автомобиля
+ ///
+ protected int _startPosY;
+ ///
+ /// Ширина прорисовки автомобиля
+ ///
+ protected readonly int _truckWidth = 110;
+ ///
+ /// Высота прорисовки автомобиля
+ ///
+ protected readonly int _truckHeight = 60;
+ ///
+ ///
+ /// Координата X объекта
+ ///
+ public int GetPosX => _startPosX;
+ ///
+ /// Координата Y объекта
+ ///
+ public int GetPosY => _startPosY;
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _truckWidth;
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _truckHeight;
+
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Ширина картинки
+ /// Высота картинки
+ public DrawningTruck(int speed, double weight, Color bodyColor, int width, int height)
+ {
+ if (width < _truckWidth || height < _truckHeight)
+ {
+ return;
+ }
+ _pictureWidth = width;
+ _pictureHeight = height;
+ EntityTruck = new EntityTruck(speed, weight, bodyColor);
+ }
+
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Ширина картинки
+ /// Высота картинки
+ /// Ширина прорисовки автомобиля
+ /// Высота прорисовки автомобиля
+ protected DrawningTruck(int speed, double weight, Color bodyColor, int width, int height, int truckWidth, int truckHeight)
+ {
+ if (width <= _truckWidth || height <= _truckHeight)
+ {
+ return;
+ }
+ _pictureWidth = width;
+ _pictureHeight = height;
+ _truckWidth = truckWidth;
+ _truckHeight = truckHeight;
+ EntityTruck = new EntityTruck(speed, weight, bodyColor);
+ }
+
+ ///
+ /// Проверка, что объект может переместится по указанному направлению
+ ///
+ /// Направление
+ /// true - можно переместится по указанному направлению
+ public bool CanMove(DirectionType direction)
+ {
+ if (EntityTruck == null)
+ {
+ return false;
+ }
+ return direction switch
+ {
+ //влево
+ DirectionType.Left => _startPosX - EntityTruck.Step > 0,
+ //вверх
+ DirectionType.Up => _startPosY - EntityTruck.Step > 0,
+ // вправо
+ DirectionType.Right => _startPosX + _truckWidth + EntityTruck.Step < _pictureWidth,
+ //вниз
+ DirectionType.Down => _startPosY + _truckHeight + EntityTruck.Step < _pictureHeight,
+ _ => false,
+ };
+ }
+
+ ///
+ /// Установка позиции
+ ///
+ /// Координата X
+ /// Координата Y
+ public void SetPosition(int x, int y)
+ {
+ if (x < 0 || x + _truckWidth > _pictureWidth)
+ {
+ x = Math.Max(0, _pictureWidth - _truckWidth);
+ }
+ if (y < 0 || y + _truckHeight > _pictureHeight)
+ {
+ y = Math.Max(0, _pictureHeight - _truckHeight);
+ }
+ _startPosX = x;
+ _startPosY = y;
+ }
+
+ ///
+ /// Изменение направления перемещения
+ ///
+ /// Направление
+ public void MoveTransport(DirectionType direction)
+ {
+ if (!CanMove(direction) || EntityTruck == null)
+ {
+ return;
+ }
+ switch (direction)
+ {
+ //влево
+ case DirectionType.Left:
+ if (_startPosX - EntityTruck.Step > 0)
+ {
+ _startPosX -= (int)EntityTruck.Step;
+ }
+ break;
+ //вверх
+ case DirectionType.Up:
+ if (_startPosY - EntityTruck.Step > 0)
+ {
+ _startPosY -= (int)EntityTruck.Step;
+ }
+ break;
+ // вправо
+ case DirectionType.Right:
+ if (_startPosX + _truckWidth + EntityTruck.Step < _pictureWidth)
+ {
+ _startPosX += (int)EntityTruck.Step;
+ }
+ break;
+ //вниз
+ case DirectionType.Down:
+ if (_startPosY + _truckHeight + EntityTruck.Step < _pictureHeight)
+ {
+ _startPosY += (int)EntityTruck.Step;
+ }
+ break;
+ }
+ }
+
+ ///
+ /// Прорисовка объекта
+ ///
+ ///
+ public virtual void DrawTransport(Graphics g)
+ {
+ if (EntityTruck == null)
+ {
+ return;
+ }
+ Pen penBlack = new Pen(Color.Black);
+ Brush brushBodyColor = new SolidBrush(EntityTruck.BodyColor);
+ Brush brushBlack = new SolidBrush(Color.Black);
+ Brush brushWhite = new SolidBrush(Color.White);
+
+ //Кабина
+ g.FillRectangle(brushBodyColor, _startPosX + 80, _startPosY, 20, 30);
+ g.DrawRectangle(penBlack, _startPosX + 80, _startPosY, 20, 30);
+
+ //Рама
+ g.FillRectangle(brushBodyColor, _startPosX, _startPosY + 30, 100, 5);
+ g.DrawRectangle(penBlack, _startPosX, _startPosY + 30, 100, 5);
+
+ //Колёса
+ g.FillEllipse(brushBlack, _startPosX, _startPosY + 35, 20, 20);
+ g.FillEllipse(brushBlack, _startPosX + 22, _startPosY + 35, 20, 20);
+ g.FillEllipse(brushBlack, _startPosX + 80, _startPosY + 35, 20, 20);
+
+ g.FillEllipse(brushWhite, _startPosX + 5, _startPosY + 40, 10, 10);
+ g.FillEllipse(brushWhite, _startPosX + 27, _startPosY + 40, 10, 10);
+ g.FillEllipse(brushWhite, _startPosX + 85, _startPosY + 40, 10, 10);
+
+ g.DrawEllipse(penBlack, _startPosX, _startPosY + 35, 20, 20);
+ g.DrawEllipse(penBlack, _startPosX + 22, _startPosY + 35, 20, 20);
+ g.DrawEllipse(penBlack, _startPosX + 80, _startPosY + 35, 20, 20);
+ }
+ }
+}
diff --git a/DumpTruck/DumpTruck/DumpTruck.csproj b/DumpTruck/DumpTruck/DumpTruck.csproj
index b57c89e..13ee123 100644
--- a/DumpTruck/DumpTruck/DumpTruck.csproj
+++ b/DumpTruck/DumpTruck/DumpTruck.csproj
@@ -8,4 +8,19 @@
enable
+
+
+ True
+ True
+ Resources.resx
+
+
+
+
+
+ ResXFileCodeGenerator
+ Resources.Designer.cs
+
+
+
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/EntityDumpTruck.cs b/DumpTruck/DumpTruck/EntityDumpTruck.cs
new file mode 100644
index 0000000..b326478
--- /dev/null
+++ b/DumpTruck/DumpTruck/EntityDumpTruck.cs
@@ -0,0 +1,43 @@
+using DumpTruck.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck.Entities
+{
+ internal class EntityDumpTruck: EntityTruck
+ {
+ ///
+ /// Дополнительный цвет (для опциональных элементов)
+ ///
+ public Color AdditionalColor { get; private set; }
+
+ ///
+ /// Признак (опция) наличия кузова
+ ///
+ public bool BodyKit { get; private set; }
+
+ ///
+ /// Признак (опция) наличия тента
+ ///
+ public bool Tent { get; private set; }
+
+ ///
+ /// Инициализация полей объекта-класса автомобиля
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public EntityDumpTruck(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool tent) :
+ base(speed, weight, bodyColor)
+ {
+ AdditionalColor = additionalColor;
+ BodyKit = bodyKit;
+ Tent = tent;
+ }
+ }
+}
diff --git a/DumpTruck/DumpTruck/EntityTruck.cs b/DumpTruck/DumpTruck/EntityTruck.cs
new file mode 100644
index 0000000..c2b757f
--- /dev/null
+++ b/DumpTruck/DumpTruck/EntityTruck.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck.Entities
+{
+ public class EntityTruck
+ {
+ ///
+ /// Скорость
+ ///
+ 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 EntityTruck(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+ }
+}
diff --git a/DumpTruck/DumpTruck/Form1.Designer.cs b/DumpTruck/DumpTruck/Form1.Designer.cs
deleted file mode 100644
index 073cfce..0000000
--- a/DumpTruck/DumpTruck/Form1.Designer.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-namespace DumpTruck
-{
- partial class Form1
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "Form1";
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/Form1.cs b/DumpTruck/DumpTruck/Form1.cs
deleted file mode 100644
index 2326120..0000000
--- a/DumpTruck/DumpTruck/Form1.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace DumpTruck
-{
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- }
-}
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/FormDumpTruck.Designer.cs b/DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
new file mode 100644
index 0000000..95ed775
--- /dev/null
+++ b/DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
@@ -0,0 +1,192 @@
+namespace DumpTruck
+{
+ partial class FormDumpTruck
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ pictureBoxDumpTruck = new PictureBox();
+ buttonCreateTruck = new Button();
+ buttonLeft = new Button();
+ buttonUp = new Button();
+ buttonDown = new Button();
+ buttonRight = new Button();
+ buttonCreateDumpTruck = new Button();
+ comboBoxStrategy = new ComboBox();
+ buttonStep = new Button();
+ buttonSelectTruck = new Button();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).BeginInit();
+ SuspendLayout();
+ //
+ // pictureBoxDumpTruck
+ //
+ pictureBoxDumpTruck.Dock = DockStyle.Fill;
+ pictureBoxDumpTruck.Location = new Point(0, 0);
+ pictureBoxDumpTruck.Name = "pictureBoxDumpTruck";
+ pictureBoxDumpTruck.Size = new Size(884, 461);
+ pictureBoxDumpTruck.SizeMode = PictureBoxSizeMode.AutoSize;
+ pictureBoxDumpTruck.TabIndex = 0;
+ pictureBoxDumpTruck.TabStop = false;
+ //
+ // buttonCreateTruck
+ //
+ buttonCreateTruck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateTruck.Location = new Point(12, 406);
+ buttonCreateTruck.Name = "buttonCreateTruck";
+ buttonCreateTruck.Size = new Size(107, 43);
+ buttonCreateTruck.TabIndex = 1;
+ buttonCreateTruck.Text = "Создать грузовик";
+ buttonCreateTruck.UseVisualStyleBackColor = true;
+ buttonCreateTruck.Click += buttonCreateTruck_Click;
+ //
+ // buttonLeft
+ //
+ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
+ buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
+ buttonLeft.Location = new Point(770, 426);
+ buttonLeft.Name = "buttonLeft";
+ buttonLeft.Size = new Size(30, 30);
+ buttonLeft.TabIndex = 2;
+ buttonLeft.UseVisualStyleBackColor = true;
+ buttonLeft.Click += buttonMove_Click;
+ //
+ // buttonUp
+ //
+ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonUp.BackgroundImage = Properties.Resources.arrowUp;
+ buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
+ buttonUp.Location = new Point(806, 390);
+ buttonUp.Name = "buttonUp";
+ buttonUp.Size = new Size(30, 30);
+ buttonUp.TabIndex = 3;
+ buttonUp.UseVisualStyleBackColor = true;
+ buttonUp.Click += buttonMove_Click;
+ //
+ // buttonDown
+ //
+ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonDown.BackgroundImage = Properties.Resources.arrowDown;
+ buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
+ buttonDown.Location = new Point(806, 426);
+ buttonDown.Name = "buttonDown";
+ buttonDown.Size = new Size(30, 30);
+ buttonDown.TabIndex = 4;
+ buttonDown.UseVisualStyleBackColor = true;
+ buttonDown.Click += buttonMove_Click;
+ //
+ // buttonRight
+ //
+ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonRight.BackgroundImage = Properties.Resources.arrowRight;
+ buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
+ buttonRight.Location = new Point(842, 426);
+ buttonRight.Name = "buttonRight";
+ buttonRight.Size = new Size(30, 30);
+ buttonRight.TabIndex = 5;
+ buttonRight.UseVisualStyleBackColor = true;
+ buttonRight.Click += buttonMove_Click;
+ //
+ // buttonCreateDumpTruck
+ //
+ buttonCreateDumpTruck.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateDumpTruck.Location = new Point(125, 406);
+ buttonCreateDumpTruck.Name = "buttonCreateDumpTruck";
+ buttonCreateDumpTruck.Size = new Size(118, 43);
+ buttonCreateDumpTruck.TabIndex = 6;
+ buttonCreateDumpTruck.Text = "Создать грузовик с кузовом";
+ buttonCreateDumpTruck.UseVisualStyleBackColor = true;
+ buttonCreateDumpTruck.Click += buttonCreateDumpTruck_Click;
+ //
+ // comboBoxStrategy
+ //
+ comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxStrategy.FormattingEnabled = true;
+ comboBoxStrategy.Items.AddRange(new object[] { "Путь к центру", "Путь к правому нижнему углу" });
+ comboBoxStrategy.Location = new Point(751, 12);
+ comboBoxStrategy.Name = "comboBoxStrategy";
+ comboBoxStrategy.Size = new Size(121, 23);
+ comboBoxStrategy.TabIndex = 7;
+ //
+ // buttonStep
+ //
+ buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right;
+ buttonStep.Location = new Point(797, 41);
+ buttonStep.Name = "buttonStep";
+ buttonStep.Size = new Size(75, 23);
+ buttonStep.TabIndex = 8;
+ buttonStep.Text = "Шаг";
+ buttonStep.UseVisualStyleBackColor = true;
+ buttonStep.Click += buttonStep_Click;
+ //
+ // buttonSelectTruck
+ //
+ buttonSelectTruck.Location = new Point(12, 357);
+ buttonSelectTruck.Name = "buttonSelectTruck";
+ buttonSelectTruck.Size = new Size(231, 43);
+ buttonSelectTruck.TabIndex = 9;
+ buttonSelectTruck.Text = "Выбрать";
+ buttonSelectTruck.UseVisualStyleBackColor = true;
+ buttonSelectTruck.Click += buttonSelectTruck_Click;
+ //
+ // FormDumpTruck
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(884, 461);
+ Controls.Add(buttonSelectTruck);
+ Controls.Add(buttonStep);
+ Controls.Add(comboBoxStrategy);
+ Controls.Add(buttonCreateDumpTruck);
+ Controls.Add(buttonRight);
+ Controls.Add(buttonDown);
+ Controls.Add(buttonUp);
+ Controls.Add(buttonLeft);
+ Controls.Add(buttonCreateTruck);
+ Controls.Add(pictureBoxDumpTruck);
+ Name = "FormDumpTruck";
+ StartPosition = FormStartPosition.CenterScreen;
+ Text = "Проект";
+ ((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxDumpTruck;
+ private Button buttonCreateTruck;
+ private Button buttonLeft;
+ private Button buttonUp;
+ private Button buttonDown;
+ private Button buttonRight;
+ private Button buttonCreateDumpTruck;
+ private ComboBox comboBoxStrategy;
+ private Button buttonStep;
+ private Button buttonSelectTruck;
+ }
+}
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/FormDumpTruck.cs b/DumpTruck/DumpTruck/FormDumpTruck.cs
new file mode 100644
index 0000000..6cb0b9e
--- /dev/null
+++ b/DumpTruck/DumpTruck/FormDumpTruck.cs
@@ -0,0 +1,161 @@
+using DumpTruck.DrawningObjects;
+using DumpTruck.MovementStrategy;
+
+namespace DumpTruck
+{
+ public partial class FormDumpTruck : Form
+ {
+ ///
+ /// Поле-объект для прорисовки объекта
+ ///
+ private DrawningTruck? _drawningTruck;
+
+ private AbstractStrategy? _abstractStrategy;
+
+ ///
+ /// Выбранный автомобиль
+ ///
+ public DrawningTruck? selectedTruck { get; private set; }
+
+
+ ///
+ /// Инициализация формы
+ ///
+ public FormDumpTruck()
+ {
+ InitializeComponent();
+ _abstractStrategy = null;
+ selectedTruck = null;
+ }
+
+ ///
+ /// Метод прорисовки машины
+ ///
+ private void Draw()
+ {
+ if (_drawningTruck == null)
+ return;
+ Bitmap bmp = new(pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _drawningTruck.DrawTransport(gr);
+ pictureBoxDumpTruck.Image = bmp;
+ }
+
+ ///
+ /// Обработка нажатия кнопки "Создать truck"
+ ///
+ ///
+ ///
+ private void buttonCreateTruck_Click(object sender, EventArgs e)
+ {
+ Random random = new();
+ 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;
+ }
+ _drawningTruck = new DrawningTruck(random.Next(100, 300), random.Next(1000, 3000), color,
+ pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
+ _drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
+
+ Draw();
+ }
+
+ ///
+ /// Изменение размеров формы
+ ///
+ ///
+ ///
+ private void buttonMove_Click(object sender, EventArgs e)
+ {
+ if (_drawningTruck == null)
+ {
+ return;
+ }
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ switch (name)
+ {
+ case "buttonUp":
+ _drawningTruck.MoveTransport(DirectionType.Up);
+ break;
+ case "buttonDown":
+ _drawningTruck.MoveTransport(DirectionType.Down);
+ break;
+ case "buttonLeft":
+ _drawningTruck.MoveTransport(DirectionType.Left);
+ break;
+ case "buttonRight":
+ _drawningTruck.MoveTransport(DirectionType.Right);
+ break;
+ }
+ Draw();
+ }
+
+ private void buttonCreateDumpTruck_Click(object sender, EventArgs e)
+ {
+ Random random = new();
+ 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;
+ }
+ Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = dialog.Color;
+ }
+ _drawningTruck = new DrawningDumpTruck(random.Next(100, 300), random.Next(1000, 3000),
+ color, dopColor,
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
+ pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
+ _drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ Draw();
+ }
+
+ private void buttonStep_Click(object sender, EventArgs e)
+ {
+ if (_drawningTruck == null)
+ {
+ return;
+ }
+ if (comboBoxStrategy.Enabled)
+ {
+ _abstractStrategy = comboBoxStrategy.SelectedIndex
+ switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_abstractStrategy == null)
+ {
+ return;
+ }
+ _abstractStrategy.SetData(new
+ DrawningObjectTruck(_drawningTruck), pictureBoxDumpTruck.Width,
+ pictureBoxDumpTruck.Height);
+ comboBoxStrategy.Enabled = false;
+ }
+ if (_abstractStrategy == null)
+ {
+ return;
+ }
+ _abstractStrategy.MakeStep();
+ Draw();
+ if (_abstractStrategy.GetStatus() == Status.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _abstractStrategy = null;
+ }
+ }
+
+ private void buttonSelectTruck_Click(object sender, EventArgs e)
+ {
+ selectedTruck = _drawningTruck;
+ DialogResult = DialogResult.OK;
+ }
+ }
+}
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/Form1.resx b/DumpTruck/DumpTruck/FormDumpTruck.resx
similarity index 93%
rename from DumpTruck/DumpTruck/Form1.resx
rename to DumpTruck/DumpTruck/FormDumpTruck.resx
index 1af7de1..af32865 100644
--- a/DumpTruck/DumpTruck/Form1.resx
+++ b/DumpTruck/DumpTruck/FormDumpTruck.resx
@@ -1,17 +1,17 @@
-
diff --git a/DumpTruck/DumpTruck/FormTruckCollection.Designer.cs b/DumpTruck/DumpTruck/FormTruckCollection.Designer.cs
new file mode 100644
index 0000000..a41becd
--- /dev/null
+++ b/DumpTruck/DumpTruck/FormTruckCollection.Designer.cs
@@ -0,0 +1,124 @@
+namespace DumpTruck
+{
+ partial class FormTruckCollection
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ groupBox1 = new GroupBox();
+ maskedTextBoxNumber = new MaskedTextBox();
+ buttonRefreshCollection = new Button();
+ buttonRemoveTruck = new Button();
+ buttonAddTruck = new Button();
+ pictureBoxCollection = new PictureBox();
+ groupBox1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
+ SuspendLayout();
+ //
+ // groupBox1
+ //
+ groupBox1.Controls.Add(maskedTextBoxNumber);
+ groupBox1.Controls.Add(buttonRefreshCollection);
+ groupBox1.Controls.Add(buttonRemoveTruck);
+ groupBox1.Controls.Add(buttonAddTruck);
+ groupBox1.Location = new Point(588, 12);
+ groupBox1.Name = "groupBox1";
+ groupBox1.Size = new Size(200, 426);
+ groupBox1.TabIndex = 0;
+ groupBox1.TabStop = false;
+ groupBox1.Text = "Инструменты";
+ groupBox1.Enter += groupBox1_Enter;
+ //
+ // maskedTextBoxNumber
+ //
+ maskedTextBoxNumber.Location = new Point(52, 166);
+ maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ maskedTextBoxNumber.Size = new Size(100, 23);
+ maskedTextBoxNumber.TabIndex = 4;
+ //
+ // buttonRefreshCollection
+ //
+ buttonRefreshCollection.Location = new Point(6, 382);
+ buttonRefreshCollection.Name = "buttonRefreshCollection";
+ buttonRefreshCollection.Size = new Size(188, 33);
+ buttonRefreshCollection.TabIndex = 3;
+ buttonRefreshCollection.Text = "Обновить коллекцию";
+ buttonRefreshCollection.UseVisualStyleBackColor = true;
+ buttonRefreshCollection.Click += buttonRefreshCollection_Click;
+ //
+ // buttonRemoveTruck
+ //
+ buttonRemoveTruck.Location = new Point(6, 195);
+ buttonRemoveTruck.Name = "buttonRemoveTruck";
+ buttonRemoveTruck.Size = new Size(188, 34);
+ buttonRemoveTruck.TabIndex = 2;
+ buttonRemoveTruck.Text = "Удалить грузовик";
+ buttonRemoveTruck.UseVisualStyleBackColor = true;
+ buttonRemoveTruck.Click += buttonRemoveTruck_Click;
+ //
+ // buttonAddTruck
+ //
+ buttonAddTruck.Location = new Point(6, 22);
+ buttonAddTruck.Name = "buttonAddTruck";
+ buttonAddTruck.Size = new Size(188, 31);
+ buttonAddTruck.TabIndex = 1;
+ buttonAddTruck.Text = "Добавить грузовик";
+ buttonAddTruck.UseVisualStyleBackColor = true;
+ buttonAddTruck.Click += buttonAddTruck_Click;
+ //
+ // pictureBoxCollection
+ //
+ pictureBoxCollection.Location = new Point(12, 12);
+ pictureBoxCollection.Name = "pictureBoxCollection";
+ pictureBoxCollection.Size = new Size(570, 426);
+ pictureBoxCollection.TabIndex = 1;
+ pictureBoxCollection.TabStop = false;
+ //
+ // FormTruckCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(pictureBoxCollection);
+ Controls.Add(groupBox1);
+ Name = "FormTruckCollection";
+ Text = "Набор грузовиков";
+ groupBox1.ResumeLayout(false);
+ groupBox1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBox1;
+ private Button buttonAddTruck;
+ private Button buttonRemoveTruck;
+ private Button buttonRefreshCollection;
+ private PictureBox pictureBoxCollection;
+ private MaskedTextBox maskedTextBoxNumber;
+ }
+}
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/FormTruckCollection.cs b/DumpTruck/DumpTruck/FormTruckCollection.cs
new file mode 100644
index 0000000..918e530
--- /dev/null
+++ b/DumpTruck/DumpTruck/FormTruckCollection.cs
@@ -0,0 +1,77 @@
+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 DumpTruck.DrawningObjects;
+using DumpTruck.Generics;
+using DumpTruck.MovementStrategy;
+
+
+namespace DumpTruck
+{
+ public partial class FormTruckCollection : Form
+ {
+ ///
+ /// Набор объектов
+ ///
+ private readonly TrucksGenericCollection _trucks;
+
+ public FormTruckCollection()
+ {
+ InitializeComponent();
+ _trucks = new TrucksGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+
+ private void buttonAddTruck_Click(object sender, EventArgs e)
+ {
+ FormDumpTruck form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (_trucks + form.selectedTruck != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollection.Image = _trucks.ShowTrucks();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+
+ }
+
+ private void buttonRemoveTruck_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ if (_trucks - pos)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBoxCollection.Image = _trucks.ShowTrucks();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+
+ }
+
+ private void buttonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image = _trucks.ShowTrucks();
+ }
+
+ private void groupBox1_Enter(object sender, EventArgs e)
+ {
+
+ }
+ }
+}
diff --git a/DumpTruck/DumpTruck/FormTruckCollection.resx b/DumpTruck/DumpTruck/FormTruckCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/DumpTruck/DumpTruck/FormTruckCollection.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/DumpTruck/DumpTruck/IMoveableObject.cs b/DumpTruck/DumpTruck/IMoveableObject.cs
new file mode 100644
index 0000000..6792e74
--- /dev/null
+++ b/DumpTruck/DumpTruck/IMoveableObject.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck.MovementStrategy
+{
+ public interface IMoveableObject
+ {
+ ///
+ /// Получение координаты X объекта
+ ///
+ ObjectParameters? GetObjectPosition { get; }
+ ///
+ /// Шаг объекта
+ ///
+ int GetStep { get; }
+ ///
+ /// Проверка, можно ли переместиться по нужному направлению
+ ///
+ ///
+ ///
+ bool CheckCanMove(DirectionType direction);
+ ///
+ /// Изменение направления пермещения объекта
+ ///
+ /// Направление
+ void MoveObject(DirectionType direction);
+ }
+}
diff --git a/DumpTruck/DumpTruck/MoveToBorder.cs b/DumpTruck/DumpTruck/MoveToBorder.cs
new file mode 100644
index 0000000..2a4a825
--- /dev/null
+++ b/DumpTruck/DumpTruck/MoveToBorder.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using DumpTruck.MovementStrategy;
+
+namespace DumpTruck
+{
+ 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.RightBorder - FieldWidth;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+ var diffY = objParams.DownBorder - FieldHeight;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+ }
+}
diff --git a/DumpTruck/DumpTruck/MoveToCenter.cs b/DumpTruck/DumpTruck/MoveToCenter.cs
new file mode 100644
index 0000000..fe0c9c4
--- /dev/null
+++ b/DumpTruck/DumpTruck/MoveToCenter.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck.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/DumpTruck/DumpTruck/ObjectParameters.cs b/DumpTruck/DumpTruck/ObjectParameters.cs
new file mode 100644
index 0000000..2af38ef
--- /dev/null
+++ b/DumpTruck/DumpTruck/ObjectParameters.cs
@@ -0,0 +1,55 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck.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;
+ ///
+ /// Конструктор
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина
+ /// Высота
+ public ObjectParameters(int x, int y, int width, int height)
+ {
+ _x = x;
+ _y = y;
+ _width = width;
+ _height = height;
+ }
+ }
+}
diff --git a/DumpTruck/DumpTruck/Program.cs b/DumpTruck/DumpTruck/Program.cs
index a716913..b645567 100644
--- a/DumpTruck/DumpTruck/Program.cs
+++ b/DumpTruck/DumpTruck/Program.cs
@@ -11,7 +11,7 @@ namespace DumpTruck
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new Form1());
+ Application.Run(new FormTruckCollection());
}
}
}
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/Properties/Resources.Designer.cs b/DumpTruck/DumpTruck/Properties/Resources.Designer.cs
new file mode 100644
index 0000000..eb02a09
--- /dev/null
+++ b/DumpTruck/DumpTruck/Properties/Resources.Designer.cs
@@ -0,0 +1,103 @@
+//------------------------------------------------------------------------------
+//
+// Этот код создан программой.
+// Исполняемая версия:4.0.30319.42000
+//
+// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
+// повторной генерации кода.
+//
+//------------------------------------------------------------------------------
+
+namespace DumpTruck.Properties {
+ using System;
+
+
+ ///
+ /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
+ ///
+ // Этот класс создан автоматически классом StronglyTypedResourceBuilder
+ // с помощью такого средства, как ResGen или Visual Studio.
+ // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
+ // с параметром /str или перестройте свой проект VS.
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
+ [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
+ [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
+ internal class Resources {
+
+ private static global::System.Resources.ResourceManager resourceMan;
+
+ private static global::System.Globalization.CultureInfo resourceCulture;
+
+ [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
+ internal Resources() {
+ }
+
+ ///
+ /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Resources.ResourceManager ResourceManager {
+ get {
+ if (object.ReferenceEquals(resourceMan, null)) {
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DumpTruck.Properties.Resources", typeof(Resources).Assembly);
+ resourceMan = temp;
+ }
+ return resourceMan;
+ }
+ }
+
+ ///
+ /// Перезаписывает свойство CurrentUICulture текущего потока для всех
+ /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
+ ///
+ [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
+ internal static global::System.Globalization.CultureInfo Culture {
+ get {
+ return resourceCulture;
+ }
+ set {
+ resourceCulture = value;
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowDown {
+ get {
+ object obj = ResourceManager.GetObject("arrowDown", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowLeft {
+ get {
+ object obj = ResourceManager.GetObject("arrowLeft", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowRight {
+ get {
+ object obj = ResourceManager.GetObject("arrowRight", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap arrowUp {
+ get {
+ object obj = ResourceManager.GetObject("arrowUp", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+ }
+}
diff --git a/DumpTruck/DumpTruck/Properties/Resources.resx b/DumpTruck/DumpTruck/Properties/Resources.resx
new file mode 100644
index 0000000..dc6b4c5
--- /dev/null
+++ b/DumpTruck/DumpTruck/Properties/Resources.resx
@@ -0,0 +1,133 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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
+
+
+
+ ..\Resources\arrowDown.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\arrowLeft.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\arrowRight.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\arrowUp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/Resources/arrowDown.png b/DumpTruck/DumpTruck/Resources/arrowDown.png
new file mode 100644
index 0000000..c8222f8
Binary files /dev/null and b/DumpTruck/DumpTruck/Resources/arrowDown.png differ
diff --git a/DumpTruck/DumpTruck/Resources/arrowLeft.png b/DumpTruck/DumpTruck/Resources/arrowLeft.png
new file mode 100644
index 0000000..ff74fb3
Binary files /dev/null and b/DumpTruck/DumpTruck/Resources/arrowLeft.png differ
diff --git a/DumpTruck/DumpTruck/Resources/arrowRight.png b/DumpTruck/DumpTruck/Resources/arrowRight.png
new file mode 100644
index 0000000..ee722eb
Binary files /dev/null and b/DumpTruck/DumpTruck/Resources/arrowRight.png differ
diff --git a/DumpTruck/DumpTruck/Resources/arrowUp.png b/DumpTruck/DumpTruck/Resources/arrowUp.png
new file mode 100644
index 0000000..0c80a4f
Binary files /dev/null and b/DumpTruck/DumpTruck/Resources/arrowUp.png differ
diff --git a/DumpTruck/DumpTruck/SetGeneric.cs b/DumpTruck/DumpTruck/SetGeneric.cs
new file mode 100644
index 0000000..cdfe2c4
--- /dev/null
+++ b/DumpTruck/DumpTruck/SetGeneric.cs
@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Numerics;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck.Generics
+{
+ ///
+ /// Параметризованный набор объектов
+ ///
+ ///
+ internal class SetGeneric
+ where T : class
+ {
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private readonly T?[] _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Length;
+ ///
+ /// Конструктор
+ ///
+ ///
+ public SetGeneric(int count)
+ {
+ _places = new T?[count];
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ /// Добавляемый автомобиль
+ ///
+ public int Insert(T truck)
+ {
+ return Insert(truck, 0);
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый автомобиль
+ /// Позиция
+ ///
+ public int Insert(T truck, int position)
+ {
+ // TODO проверка позиции
+ if (position < 0 || position > Count)
+ {
+ return -1;
+ }
+ // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
+ if (_places[position] != null)
+ {
+ // проверка, что после вставляемого элемента в массиве есть пустой элемент
+ int nullIndex = -1;
+ for (int i = position + 1; i < Count; i++)
+ {
+ if (_places[i] == null)
+ {
+ nullIndex = i;
+ break;
+ }
+ }
+ // Если пустого элемента нет, то выходим
+ if (nullIndex < 0)
+ {
+ return -1;
+ }
+ // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
+ int j = nullIndex - 1;
+ while (j >= position)
+ {
+ _places[j + 1] = _places[j];
+ j--;
+ }
+ }
+ // TODO вставка по позиции
+ _places[position] = truck;
+ return position;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public bool Remove(int position)
+ {
+ // TODO проверка позиции
+ if ((position < 0) || (position > Count)) return false;
+ // TODO удаление объекта из массива, присвоив элементу массива значение null
+ _places[position] = null;
+ return true;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T? Get(int position)
+ {
+ // TODO проверка позиции
+ if ((position < 0) || (position > Count)) return null;
+ return _places[position];
+ }
+ }
+}
diff --git a/DumpTruck/DumpTruck/Status.cs b/DumpTruck/DumpTruck/Status.cs
new file mode 100644
index 0000000..fafc078
--- /dev/null
+++ b/DumpTruck/DumpTruck/Status.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck.MovementStrategy
+{
+ public enum Status
+ {
+ NotInit,
+
+ InProgress,
+
+ Finish
+ }
+}
diff --git a/DumpTruck/DumpTruck/TrucksGenericCollection.cs b/DumpTruck/DumpTruck/TrucksGenericCollection.cs
new file mode 100644
index 0000000..5ed60fe
--- /dev/null
+++ b/DumpTruck/DumpTruck/TrucksGenericCollection.cs
@@ -0,0 +1,140 @@
+using DumpTruck.DrawningObjects;
+using DumpTruck.MovementStrategy;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck.Generics
+{
+ internal class TrucksGenericCollection
+ where T : DrawningTruck
+ where U : IMoveableObject
+ {
+ ///
+ /// Ширина окна прорисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна прорисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 110;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 70;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetGeneric _collection;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public TrucksGenericCollection(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 +(TrucksGenericCollection collect, T?
+ obj)
+ {
+ if (obj == null)
+ {
+ return -1;
+ }
+ return collect._collection.Insert(obj);
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static bool operator -(TrucksGenericCollection collect, int pos)
+ {
+ T? obj = collect._collection.Get(pos);
+ if (obj != null)
+ {
+ return collect._collection.Remove(pos);
+ }
+ return false;
+ }
+ ///
+ /// Получение объекта IMoveableObject
+ ///
+ ///
+ ///
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObject;
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowTrucks()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawObjects(gr);
+ return bmp;
+ }
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 3);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight +
+ 1; ++j)
+ {//линия рамзетки места
+ g.DrawLine(pen, i * _placeSizeWidth, j *
+ _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
+ _placeSizeHeight);
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i *
+ _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ }
+ }
+ ///
+ /// Метод прорисовки объектов
+ ///
+ ///
+ private void DrawObjects(Graphics g)
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+
+ for (int i = 0; i < _collection.Count; i++)
+ {
+ // TODO получение объекта
+ // TODO установка позиции
+ // TODO прорисовка объекта
+ DrawningTruck? truck = _collection.Get(i);
+ if (truck == null)
+ continue;
+ truck.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight);
+ truck.DrawTransport(g);
+ }
+ }
+ }
+}