From 3e9bd950234e82a19ab08e77d71df3572948020f Mon Sep 17 00:00:00 2001
From: "Pyatkin I.A" <4234.sunrise.234@gmail.com>
Date: Fri, 8 Dec 2023 18:32:29 +0400
Subject: [PATCH] =?UTF-8?q?=D0=92=D1=82=D0=BE=D1=80=D0=B0=D1=8F=20=D1=83?=
=?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B5=D0=BD=D0=BD=D0=B0=D1=8F=20?=
=?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD?=
=?UTF-8?q?=D0=B0=D1=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ProjectExcavator/AbstractStrategy.cs | 135 ++++++++
.../ProjectExcavator/DrawKatkiSquare.cs | 89 ++++++
.../ProjectExcavator/DrawKatkiTriangle.cs | 148 +++++++++
.../ProjectExcavator/DrawingExcavator.cs | 297 ++++++++----------
.../ProjectExcavator/DrawingExcavatorKovsh.cs | 136 ++++++++
.../ProjectExcavator/DrawingKatkiCircle.cs | 90 ++++++
.../DrawingObjectExcavator.cs | 39 +++
.../ProjectExcavator/EntityExcavator.cs | 18 +-
.../ProjectExcavator/EntityExcavatorKovsh.cs | 43 +++
.../FormExcavator.Designer.cs | 82 +++--
.../ProjectExcavator/FormExcavator.cs | 79 ++++-
.../ProjectExcavator/IDrawingKatki.cs | 14 +
.../ProjectExcavator/IMoveableObject.cs | 34 ++
.../ProjectExcavator/MoveToBorder.cs | 60 ++++
.../ProjectExcavator/MoveToCenter.cs | 59 ++++
.../ProjectExcavator/ObjectParameters.cs | 56 ++++
ProjectExcavator/ProjectExcavator/Status.cs | 13 +
17 files changed, 1171 insertions(+), 221 deletions(-)
create mode 100644 ProjectExcavator/ProjectExcavator/AbstractStrategy.cs
create mode 100644 ProjectExcavator/ProjectExcavator/DrawKatkiSquare.cs
create mode 100644 ProjectExcavator/ProjectExcavator/DrawKatkiTriangle.cs
create mode 100644 ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs
create mode 100644 ProjectExcavator/ProjectExcavator/DrawingKatkiCircle.cs
create mode 100644 ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs
create mode 100644 ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs
create mode 100644 ProjectExcavator/ProjectExcavator/IDrawingKatki.cs
create mode 100644 ProjectExcavator/ProjectExcavator/IMoveableObject.cs
create mode 100644 ProjectExcavator/ProjectExcavator/MoveToBorder.cs
create mode 100644 ProjectExcavator/ProjectExcavator/MoveToCenter.cs
create mode 100644 ProjectExcavator/ProjectExcavator/ObjectParameters.cs
create mode 100644 ProjectExcavator/ProjectExcavator/Status.cs
diff --git a/ProjectExcavator/ProjectExcavator/AbstractStrategy.cs b/ProjectExcavator/ProjectExcavator/AbstractStrategy.cs
new file mode 100644
index 0000000..4a5e951
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/AbstractStrategy.cs
@@ -0,0 +1,135 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement;
+
+namespace ProjectExcavator.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/ProjectExcavator/ProjectExcavator/DrawKatkiSquare.cs b/ProjectExcavator/ProjectExcavator/DrawKatkiSquare.cs
new file mode 100644
index 0000000..8ca3199
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/DrawKatkiSquare.cs
@@ -0,0 +1,89 @@
+using ProjectWarmlyShip;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectExcavator
+{
+ public class DrawKatkiSquare : IDrawingKatki
+ {
+ private KatkiNumber KatNum;
+ public int Properties
+ {
+ get
+ {
+ return Properties;
+ }
+ set
+ {
+ switch (value)
+ {
+ case 1:
+ KatNum = KatkiNumber.Four;
+ break;
+ case 2:
+ KatNum = KatkiNumber.Five;
+ break;
+ case 3:
+ KatNum = KatkiNumber.Six;
+ break;
+ default:
+ KatNum = KatkiNumber.Four;
+ MessageBox.Show("Было введено некорректное количество катков, поэтому было отрисовано стандартное количество катков");
+ break;
+ }
+ }
+ }
+ public void Draw(int _startPosX, int _startPosY, Color katkiColor, Graphics g)
+ {
+ Pen pen = new Pen(Color.Black);
+ Brush KatkiColor = new SolidBrush(katkiColor);
+ Brush brBlack = new SolidBrush(Color.Black);
+ if (KatNum == KatkiNumber.Four)
+ {
+ g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 30, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 60, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
+ g.FillRectangle(KatkiColor, _startPosX + 9, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 34, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 64, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 89, _startPosY + 62, 7, 7);
+
+
+ }
+ if (KatNum == KatkiNumber.Five)
+ {
+ g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
+ g.FillRectangle(KatkiColor, _startPosX + 9, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 29, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 49, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 69, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 89, _startPosY + 62, 7, 7);
+
+ }
+ if (KatNum == KatkiNumber.Six)
+ {
+ g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 50, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 58, 15, 15);
+ g.FillRectangle(KatkiColor, _startPosX + 9, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 24, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 39, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 54, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 69, _startPosY + 62, 7, 7);
+ g.FillRectangle(KatkiColor, _startPosX + 84, _startPosY + 62, 7, 7);
+
+ }
+ }
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/DrawKatkiTriangle.cs b/ProjectExcavator/ProjectExcavator/DrawKatkiTriangle.cs
new file mode 100644
index 0000000..e6ea95e
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/DrawKatkiTriangle.cs
@@ -0,0 +1,148 @@
+using ProjectWarmlyShip;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectExcavator
+{
+ public class DrawKatkiTriangle : IDrawingKatki
+ {
+ private KatkiNumber KatNum;
+ public int Properties
+ {
+ get
+ {
+ return Properties;
+ }
+ set
+ {
+ switch (value)
+ {
+ case 1:
+ KatNum = KatkiNumber.Four;
+ break;
+ case 2:
+ KatNum = KatkiNumber.Five;
+ break;
+ case 3:
+ KatNum = KatkiNumber.Six;
+ break;
+ default:
+ KatNum = KatkiNumber.Four;
+ MessageBox.Show("Было введено некорректное количество катков, поэтому было отрисовано стандартное количество катков");
+ break;
+ }
+ }
+ }
+ public void Draw(int _startPosX, int _startPosY, Color katkiColor, Graphics g)
+ {
+ Pen pen = new Pen(Color.Black);
+ Brush KatkiColor = new SolidBrush(katkiColor);
+ Brush brBlack = new SolidBrush(Color.Black);
+ if (KatNum == KatkiNumber.Four)
+ {
+ g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 30, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 60, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
+
+ Point point1 = new Point(_startPosX + 12, _startPosY + 60);
+ Point point2 = new Point(_startPosX + 17, _startPosY + 70);
+ Point point3 = new Point(_startPosX + 7, _startPosY + 70);
+ Point[] trianglePoints1 = { point1, point2, point3 };
+ g.FillPolygon(KatkiColor, trianglePoints1);
+ Point point4 = new Point(_startPosX + 37, _startPosY + 60);
+ Point point5 = new Point(_startPosX + 42, _startPosY + 70);
+ Point point6 = new Point(_startPosX + 32, _startPosY + 70);
+ Point[] trianglePoints2 = { point4, point5, point6 };
+ g.FillPolygon(KatkiColor, trianglePoints2);
+ Point point7 = new Point(_startPosX + 67, _startPosY + 60);
+ Point point8 = new Point(_startPosX + 72, _startPosY + 70);
+ Point point9 = new Point(_startPosX + 62, _startPosY + 70);
+ Point[] trianglePoints3 = { point7, point8, point9 };
+ g.FillPolygon(KatkiColor, trianglePoints3);
+ Point point10 = new Point(_startPosX + 92, _startPosY + 60);
+ Point point11 = new Point(_startPosX + 97, _startPosY + 70);
+ Point point12 = new Point(_startPosX + 87, _startPosY + 70);
+ Point[] trianglePoints4 = { point10, point11, point12 };
+ g.FillPolygon(KatkiColor, trianglePoints4);
+ }
+ if (KatNum == KatkiNumber.Five)
+ {
+ g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
+
+ Point point1 = new Point(_startPosX + 12, _startPosY + 60);
+ Point point2 = new Point(_startPosX + 17, _startPosY + 70);
+ Point point3 = new Point(_startPosX + 7, _startPosY + 70);
+ Point[] trianglePoints1 = { point1, point2, point3 };
+ g.FillPolygon(KatkiColor, trianglePoints1);
+ Point point4 = new Point(_startPosX + 32, _startPosY + 60);
+ Point point5 = new Point(_startPosX + 37, _startPosY + 70);
+ Point point6 = new Point(_startPosX + 27, _startPosY + 70);
+ Point[] trianglePoints2 = { point4, point5, point6 };
+ g.FillPolygon(KatkiColor, trianglePoints2);
+ Point point7 = new Point(_startPosX + 52, _startPosY + 60);
+ Point point8 = new Point(_startPosX + 57, _startPosY + 70);
+ Point point9 = new Point(_startPosX + 47, _startPosY + 70);
+ Point[] trianglePoints3 = { point7, point8, point9 };
+ g.FillPolygon(KatkiColor, trianglePoints3);
+ Point point10 = new Point(_startPosX + 72, _startPosY + 60);
+ Point point11 = new Point(_startPosX + 77, _startPosY + 70);
+ Point point12 = new Point(_startPosX + 67, _startPosY + 70);
+ Point[] trianglePoints4 = { point10, point11, point12 };
+ g.FillPolygon(KatkiColor, trianglePoints4);
+ Point point13 = new Point(_startPosX + 92, _startPosY + 60);
+ Point point14 = new Point(_startPosX + 97, _startPosY + 70);
+ Point point15 = new Point(_startPosX + 87, _startPosY + 70);
+ Point[] trianglePoints5 = { point13, point14, point15 };
+ g.FillPolygon(KatkiColor, trianglePoints5);
+ }
+ if (KatNum == KatkiNumber.Six)
+ {
+ g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 50, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 58, 15, 15);
+
+ Point point1 = new Point(_startPosX + 12, _startPosY + 60);
+ Point point2 = new Point(_startPosX + 17, _startPosY + 70);
+ Point point3 = new Point(_startPosX + 7, _startPosY + 70);
+ Point[] trianglePoints1 = { point1, point2, point3 };
+ g.FillPolygon(KatkiColor, trianglePoints1);
+ Point point4 = new Point(_startPosX + 27, _startPosY + 60);
+ Point point5 = new Point(_startPosX + 32, _startPosY + 70);
+ Point point6 = new Point(_startPosX + 22, _startPosY + 70);
+ Point[] trianglePoints2 = { point4, point5, point6 };
+ g.FillPolygon(KatkiColor, trianglePoints2);
+ Point point7 = new Point(_startPosX + 42, _startPosY + 60);
+ Point point8 = new Point(_startPosX + 47, _startPosY + 70);
+ Point point9 = new Point(_startPosX + 37, _startPosY + 70);
+ Point[] trianglePoints3 = { point7, point8, point9 };
+ g.FillPolygon(KatkiColor, trianglePoints3);
+ Point point10 = new Point(_startPosX + 57, _startPosY + 60);
+ Point point11 = new Point(_startPosX + 62, _startPosY + 70);
+ Point point12 = new Point(_startPosX + 52, _startPosY + 70);
+ Point[] trianglePoints4 = { point10, point11, point12 };
+ g.FillPolygon(KatkiColor, trianglePoints4);
+ Point point13 = new Point(_startPosX + 72, _startPosY + 60);
+ Point point14 = new Point(_startPosX + 77, _startPosY + 70);
+ Point point15 = new Point(_startPosX + 67, _startPosY + 70);
+ Point[] trianglePoints5 = { point13, point14, point15 };
+ g.FillPolygon(KatkiColor, trianglePoints5);
+ Point point16 = new Point(_startPosX + 87, _startPosY + 60);
+ Point point17 = new Point(_startPosX + 92, _startPosY + 70);
+ Point point18 = new Point(_startPosX + 82, _startPosY + 70);
+ Point[] trianglePoints6 = { point16, point17, point18 };
+ g.FillPolygon(KatkiColor, trianglePoints6);
+ }
+ }
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs b/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs
index 975e66a..f063a12 100644
--- a/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs
+++ b/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs
@@ -3,16 +3,18 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using ProjectExcavator.Entities;
+using ProjectWarmlyShip;
-namespace ProjectExcavator
+namespace ProjectExcavator.DrawingObjects
{
public class DrawingExcavator
{
+ private IDrawingKatki? DrawingKatki;
///
/// Класс-сущность
///
- public EntityExcavator? EntityExcavator { get; private set; }
- public DrawingKatki Katki;
+ public EntityExcavator? EntityExcavator { get; protected set; }
///
/// Ширина окна
///
@@ -24,54 +26,77 @@ namespace ProjectExcavator
///
/// /// Левая координата прорисовки автомобиля
///
- private int _startPosX;
+ protected int _startPosX;
///
/// Верхняя кооридната прорисовки автомобиля
///
- private int _startPosY;
+ protected int _startPosY;
///
/// Ширина прорисовки автомобиля
///
- private int _exWidth;
+ protected readonly int _exWidth = 138;
///
/// Высота прорисовки автомобиля
///
- private int _exHeight;
+ protected readonly int _exHeight = 80;
///
/// Инициализация свойств
///
/// Скорость
/// Вес
/// Цвет кузова
- /// Дополнительный цвет
/// Ширина картинки
/// Высота картинки
- /// Ковш
/// true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах
- public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool kovsh, int width, int height)
+ public DrawingExcavator(int speed, double weight, Color bodyColor, int width, int height, int numKatki, int numchoose)
{
- if (width < _pictureWidth || height < _pictureHeight)
+ // TODO: Продумать проверки
+ if (width > _exWidth || height > _exHeight)
{
- return false;
+ _pictureWidth = width;
+ _pictureHeight = height;
+ EntityExcavator = new EntityExcavator(speed, weight, bodyColor);
+ int choose = numchoose % 3;
+ switch (choose)
+ {
+ case 0:
+ DrawingKatki = new DrawKatkiSquare();
+ break;
+ case 1:
+ DrawingKatki = new DrawKatkiTriangle();
+ break;
+ case 2:
+ DrawingKatki = new DrawKatkiCircle();
+ break;
+ }
+ DrawingKatki.Properties = numKatki;
}
-
- if (!kovsh)
- {
- _exWidth = 105;
- _exHeight = 75;
- }
- else
- {
- _exWidth = 140;
- _exHeight = 87;
- }
- _pictureWidth = width;
- _pictureHeight = height;
- EntityExcavator = new EntityExcavator();
- EntityExcavator.Init(speed, weight, bodyColor, additionalColor, kovsh);
- Katki = new DrawingKatki();
- return true;
}
+
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Ширина картинки
+ /// Высота картинки
+ /// Ширина прорисовки автомобиля
+ /// Высота прорисовки автомобиля
+ protected DrawingExcavator(int speed, double weight, Color bodyColor, int
+ width, int height, int exWidth, int exHeight, int numKatki)
+ {
+ // TODO: Продумать проверки
+ if (width > _exWidth || height > _exHeight)
+ {
+ _pictureWidth = width;
+ _pictureHeight = height;
+ _exWidth = exWidth;
+ _exHeight = exHeight;
+ EntityExcavator = new EntityExcavator(speed, weight, bodyColor);
+ }
+ }
+
///
/// Установка позиции
///
@@ -101,12 +126,52 @@ namespace ProjectExcavator
_startPosY = y;
}
///
+ /// Координата X объекта
+ ///
+ public int GetPosX => _startPosX;
+ ///
+ /// Координата Y объекта
+ ///
+ public int GetPosY => _startPosY;
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _exWidth;
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _exHeight;
+
+ ///
+ /// Проверка, что объект может переместится по указанному направлению
+ ///
+ /// Направление
+ /// true - можно переместится по указанному направлению
+ public bool CanMove(DirectionType direction)
+ {
+ if (EntityExcavator == null)
+ {
+ return false;
+ }
+ return direction switch
+ {
+ //влево
+ DirectionType.Left => _startPosX - EntityExcavator.Step > 0,
+ //вверх
+ DirectionType.Up => _startPosY - EntityExcavator.Step > 0,
+ // вправо
+ DirectionType.Right => _startPosX + _exWidth + EntityExcavator.Step <= _pictureWidth,
+ //влево
+ DirectionType.Down => _startPosY + _exHeight + EntityExcavator.Step <= _pictureHeight,
+ };
+ }
+ ///
/// Изменение направления перемещения
///
/// Направление
public void MoveTransport(DirectionType direction)
{
- if (EntityExcavator == null)
+ if (!CanMove(direction) || EntityExcavator == null)
{
return;
}
@@ -114,47 +179,19 @@ namespace ProjectExcavator
{
//влево
case DirectionType.Left:
- if (_startPosX - EntityExcavator.Step > 0)
- {
- _startPosX -= (int)EntityExcavator.Step;
- }
- else
- {
- _startPosX = 0;
- }
+ _startPosX -= (int)EntityExcavator.Step;
break;
//вверх
case DirectionType.Up:
- if (_startPosY - EntityExcavator.Step > 0)
- {
- _startPosY -= (int)EntityExcavator.Step;
- }
- else
- {
- _startPosY = 0;
- }
+ _startPosY -= (int)EntityExcavator.Step;
break;
- //вправо
+ // вправо
case DirectionType.Right:
- if (_startPosX + _exWidth + EntityExcavator.Step <= _pictureWidth)
- {
- _startPosX += (int)EntityExcavator.Step;
- }
- else
- {
- _startPosX = _pictureWidth - _exWidth;
- }
+ _startPosX += (int)EntityExcavator.Step;
break;
//вниз
case DirectionType.Down:
- if (_startPosY + _exHeight + EntityExcavator.Step <= _pictureHeight)
- {
- _startPosY += (int)EntityExcavator.Step;
- }
- else
- {
- _startPosY = _pictureHeight - _exHeight;
- }
+ _startPosY += (int)EntityExcavator.Step;
break;
}
}
@@ -162,120 +199,46 @@ namespace ProjectExcavator
/// Прорисовка объекта
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
if (EntityExcavator == null)
{
return;
}
- Pen pen = new(Color.Black);
- Brush additionalBrush = new
- SolidBrush(EntityExcavator.AdditionalColor);
+
//цвета
+ Pen pen = new(Color.Black);
Brush brBlue = new SolidBrush(Color.LightBlue);
Brush brYellow = new SolidBrush(Color.Yellow);
Brush brGray = new SolidBrush(Color.Gray);
- Brush brBlack = new SolidBrush(Color.Black);
+
+
//отрисовка экскаватора без ковша
- if (!EntityExcavator.Kovsh)
- {
- g.DrawRectangle(pen, _startPosX + 15, _startPosY + 25, 75, 25);
- g.DrawRectangle(pen, _startPosX + 60, _startPosY, 30, 25);
- g.DrawRectangle(pen, _startPosX + 30, _startPosY + 5, 10, 20);
- g.DrawRectangle(pen, _startPosX + 10, _startPosY + 55, 86, 20);
- g.DrawPie(pen, _startPosX, _startPosY + 55, 20, 20, 90, 180);
- g.DrawPie(pen, _startPosX + 85, _startPosY + 55, 20, 20, 270, 180);
- g.DrawEllipse(pen, _startPosX + 5, _startPosY + 58, 15, 15);
- g.DrawEllipse(pen, _startPosX + 85, _startPosY + 58, 15, 15);
- g.DrawEllipse(pen, _startPosX + 25, _startPosY + 65, 8, 8);
- g.DrawEllipse(pen, _startPosX + 45, _startPosY + 65, 8, 8);
- g.DrawEllipse(pen, _startPosX + 65, _startPosY + 65, 8, 8);
- g.DrawEllipse(pen, _startPosX + 37, _startPosY + 58, 6, 6);
- g.DrawEllipse(pen, _startPosX + 57, _startPosY + 58, 6, 6);
- //кабина водителя
- g.FillRectangle(brBlue, _startPosX + 61, _startPosY + 1, 29, 24);
- // кузов
- g.FillRectangle(brYellow, _startPosX + 16, _startPosY + 26, 74, 24);
- // труба
- g.FillRectangle(brYellow, _startPosX + 31, _startPosY + 6, 9, 19);
- //гусеница
- g.FillPie(brGray, _startPosX, _startPosY + 55, 20, 20, 90, 180);
- g.FillPie(brGray, _startPosX + 85, _startPosY + 55, 20, 20, 270, 180);
- g.FillRectangle(brGray, _startPosX + 10, _startPosY + 55, 86, 20);
- //катки(4,5,6)
- Katki.DrawKatki(g, _startPosX, _startPosY, Color.Black);
- }
- //отрисовка экскаватора с ковшом
- if (EntityExcavator.Kovsh)
- {
- //экскаватор
- g.DrawRectangle(pen, _startPosX + 50, _startPosY + 35, 75, 25);
- g.DrawRectangle(pen, _startPosX + 95, _startPosY + 10, 30, 25);
- g.DrawRectangle(pen, _startPosX + 60, _startPosY + 15, 10, 20);
- g.DrawRectangle(pen, _startPosX + 44, _startPosY + 65, 86, 20);
- g.DrawPie(pen, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180);
- g.DrawPie(pen, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180);
- g.DrawEllipse(pen, _startPosX + 40, _startPosY + 68, 15, 15);
- g.DrawEllipse(pen, _startPosX + 120, _startPosY + 68, 15, 15);
- g.DrawEllipse(pen, _startPosX + 60, _startPosY + 76, 8, 8);
- g.DrawEllipse(pen, _startPosX + 80, _startPosY + 76, 8, 8);
- g.DrawEllipse(pen, _startPosX + 100, _startPosY + 76, 8, 8);
- g.DrawEllipse(pen, _startPosX + 72, _startPosY + 68, 6, 6);
- g.DrawEllipse(pen, _startPosX + 92, _startPosY + 68, 6, 6);
- //кабина водителя
- g.FillRectangle(brBlue, _startPosX + 96, _startPosY + 11, 29, 24);
- // кузов
- g.FillRectangle(brYellow, _startPosX + 51, _startPosY + 36, 74, 24);
- // труба
- g.FillRectangle(brYellow, _startPosX + 61, _startPosY + 16, 9, 19);
- //гусеница
- g.FillPie(brGray, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180);
- g.FillPie(brGray, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180);
- g.FillRectangle(brGray, _startPosX + 44, _startPosY + 65, 86, 20);
- //ковш
- g.DrawLine(pen, _startPosX + 50, _startPosY + 35, _startPosX + 10, _startPosY + 10);
- g.DrawLine(pen, _startPosX + 58, _startPosY + 35, _startPosX + 12, _startPosY + 5);
- g.DrawEllipse(pen, _startPosX + 7, _startPosY + 4, 7, 7);
- g.DrawLine(pen, _startPosX + 10, _startPosY + 10, _startPosX + 10, _startPosY + 45);
- g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY + 45);
- g.DrawPie(pen, _startPosX, _startPosY + 44, 28, 30, 90, 180);
- g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY);
- g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 7, _startPosY + 10);
- g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 12);
- g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 16);
- g.DrawLine(pen, _startPosX + 50, _startPosY + 12, _startPosX + 50, _startPosY + 29);
- //катки (4,5,6)
- Katki.DrawKatki(g, _startPosX + 35, _startPosY + 10, EntityExcavator.AdditionalColor);
-
- g.FillEllipse(additionalBrush, _startPosX + 7, _startPosY + 4, 7, 7);
- g.FillPie(brBlack, _startPosX, _startPosY + 44, 28, 30, 90, 180);
- Point point1 = new Point(_startPosX + 50, _startPosY + 35);
- Point point2 = new Point(_startPosX + 10, _startPosY + 10);
- Point point3 = new Point(_startPosX + 12, _startPosY + 5);
- Point point4 = new Point(_startPosX + 58, _startPosY + 35);
- Point[] truba_1 = { point1, point2, point3, point4, point1 };
- g.FillPolygon(additionalBrush, truba_1);
-
- Point point5 = new Point(_startPosX + 10, _startPosY + 10);
- Point point6 = new Point(_startPosX + 10, _startPosY + 45);
- Point point7 = new Point(_startPosX + 14, _startPosY + 45);
- Point point8 = new Point(_startPosX + 14, _startPosY + 5);
- Point[] truba_2 = { point5, point6, point7, point8, point5 };
- g.FillPolygon(additionalBrush, truba_2);
-
- Point point9 = new Point(_startPosX + 14, _startPosY + 5);
- Point point10 = new Point(_startPosX + 14, _startPosY);
- Point point11 = new Point(_startPosX + 7, _startPosY + 10);
- Point[] triangle = { point9, point10, point11, point9 };
- g.FillPolygon(additionalBrush, triangle);
-
- Point point12 = new Point(_startPosX + 14, _startPosY);
- Point point13 = new Point(_startPosX + 50, _startPosY + 12);
- Point point14 = new Point(_startPosX + 50, _startPosY + 16);
- Point point15 = new Point(_startPosX + 14, _startPosY);
- Point[] krepl = { point12, point13, point14, point15, point12 };
- g.FillPolygon(additionalBrush, krepl);
- }
+ g.DrawRectangle(pen, _startPosX + 15, _startPosY + 25, 75, 25);
+ g.DrawRectangle(pen, _startPosX + 60, _startPosY, 30, 25);
+ g.DrawRectangle(pen, _startPosX + 30, _startPosY + 5, 10, 20);
+ g.DrawRectangle(pen, _startPosX + 10, _startPosY + 55, 86, 20);
+ g.DrawPie(pen, _startPosX, _startPosY + 55, 20, 20, 90, 180);
+ g.DrawPie(pen, _startPosX + 85, _startPosY + 55, 20, 20, 270, 180);
+ g.DrawEllipse(pen, _startPosX + 5, _startPosY + 58, 15, 15);
+ g.DrawEllipse(pen, _startPosX + 85, _startPosY + 58, 15, 15);
+ g.DrawEllipse(pen, _startPosX + 25, _startPosY + 65, 8, 8);
+ g.DrawEllipse(pen, _startPosX + 45, _startPosY + 65, 8, 8);
+ g.DrawEllipse(pen, _startPosX + 65, _startPosY + 65, 8, 8);
+ g.DrawEllipse(pen, _startPosX + 37, _startPosY + 58, 6, 6);
+ g.DrawEllipse(pen, _startPosX + 57, _startPosY + 58, 6, 6);
+ //кабина водителя
+ g.FillRectangle(brBlue, _startPosX + 61, _startPosY + 1, 29, 24);
+ // кузов
+ g.FillRectangle(brYellow, _startPosX + 16, _startPosY + 26, 74, 24);
+ // труба
+ g.FillRectangle(brYellow, _startPosX + 31, _startPosY + 6, 9, 19);
+ //гусеница
+ g.FillPie(brGray, _startPosX, _startPosY + 55, 20, 20, 90, 180);
+ g.FillPie(brGray, _startPosX + 85, _startPosY + 55, 20, 20, 270, 180);
+ g.FillRectangle(brGray, _startPosX + 10, _startPosY + 55, 86, 20);
+ //катки орнамент(4,5,6)
+ DrawingKatki.Draw(_startPosX, _startPosY, EntityExcavator.BodyColor, g);
}
}
}
diff --git a/ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs b/ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs
new file mode 100644
index 0000000..63f7762
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs
@@ -0,0 +1,136 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ProjectExcavator.Entities;
+using ProjectWarmlyShip;
+
+namespace ProjectExcavator.DrawingObjects
+{
+ ///
+ /// Класс, отвечающий за прорисовку и перемещение объекта-сущности
+ ///
+ public class DrawingExcavatorKovsh : DrawingExcavator
+ {
+ private IDrawingKatki? DrawingKatki;
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Признак наличия ковша
+ /// Признак наличия катков
+ /// Ширина картинки
+ /// Высота картинки
+ public DrawingExcavatorKovsh(int speed, double weight, Color bodyColor, Color
+ additionalColor, bool kovsh, bool katki, int width, int height, int numKatki, int numchoose) : base(speed, weight, bodyColor, width, height, numKatki, numchoose)
+ {
+ if (EntityExcavator != null)
+ {
+ EntityExcavator = new EntityExcavatorKovsh(speed, weight, bodyColor,
+ additionalColor, kovsh, katki);
+ }
+ int choose = numchoose % 3;
+ switch (choose)
+ {
+ case 0:
+ DrawingKatki = new DrawKatkiSquare();
+ break;
+ case 1:
+ DrawingKatki = new DrawKatkiTriangle();
+ break;
+ case 2:
+ DrawingKatki = new DrawKatkiCircle();
+ break;
+ }
+ DrawingKatki.Properties = numKatki;
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityExcavator is not EntityExcavatorKovsh excavatorKovsh)
+ {
+ return;
+ }
+ //цвета
+ Pen pen = new(Color.Black);
+ Brush additionalBrush = new
+ SolidBrush(excavatorKovsh.AdditionalColor);
+ Brush brBlack = new SolidBrush(Color.Black);
+ Brush brBlue = new SolidBrush(Color.LightBlue);
+ Brush brYellow = new SolidBrush(Color.Yellow);
+ Brush brGray = new SolidBrush(Color.Gray);
+
+
+ //экскаватор
+ g.DrawRectangle(pen, _startPosX + 50, _startPosY + 35, 75, 25);
+ g.DrawRectangle(pen, _startPosX + 95, _startPosY + 10, 30, 25);
+ g.DrawRectangle(pen, _startPosX + 60, _startPosY + 15, 10, 20);
+ g.DrawRectangle(pen, _startPosX + 44, _startPosY + 65, 86, 20);
+ g.DrawPie(pen, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180);
+ g.DrawPie(pen, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180);
+ g.DrawEllipse(pen, _startPosX + 40, _startPosY + 68, 15, 15);
+ g.DrawEllipse(pen, _startPosX + 120, _startPosY + 68, 15, 15);
+ g.DrawEllipse(pen, _startPosX + 60, _startPosY + 76, 8, 8);
+ g.DrawEllipse(pen, _startPosX + 80, _startPosY + 76, 8, 8);
+ g.DrawEllipse(pen, _startPosX + 100, _startPosY + 76, 8, 8);
+ g.DrawEllipse(pen, _startPosX + 72, _startPosY + 68, 6, 6);
+ g.DrawEllipse(pen, _startPosX + 92, _startPosY + 68, 6, 6);
+ //кабина водителя
+ g.FillRectangle(brBlue, _startPosX + 96, _startPosY + 11, 29, 24);
+ // кузов
+ g.FillRectangle(brYellow, _startPosX + 51, _startPosY + 36, 74, 24);
+ // труба
+ g.FillRectangle(brYellow, _startPosX + 61, _startPosY + 16, 9, 19);
+ //гусеница
+ g.FillPie(brGray, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180);
+ g.FillPie(brGray, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180);
+ g.FillRectangle(brGray, _startPosX + 44, _startPosY + 65, 86, 20);
+ //ковш
+ g.DrawLine(pen, _startPosX + 50, _startPosY + 35, _startPosX + 10, _startPosY + 10);
+ g.DrawLine(pen, _startPosX + 58, _startPosY + 35, _startPosX + 12, _startPosY + 5);
+ g.DrawEllipse(pen, _startPosX + 7, _startPosY + 4, 7, 7);
+ g.DrawLine(pen, _startPosX + 10, _startPosY + 10, _startPosX + 10, _startPosY + 45);
+ g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY + 45);
+ g.DrawPie(pen, _startPosX, _startPosY + 44, 28, 30, 90, 180);
+ g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY);
+ g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 7, _startPosY + 10);
+ g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 12);
+ g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 16);
+ g.DrawLine(pen, _startPosX + 50, _startPosY + 12, _startPosX + 50, _startPosY + 29);
+
+
+ g.FillEllipse(additionalBrush, _startPosX + 7, _startPosY + 4, 7, 7);
+ g.FillPie(brBlack, _startPosX, _startPosY + 44, 28, 30, 90, 180);
+ Point point1 = new Point(_startPosX + 50, _startPosY + 35);
+ Point point2 = new Point(_startPosX + 10, _startPosY + 10);
+ Point point3 = new Point(_startPosX + 12, _startPosY + 5);
+ Point point4 = new Point(_startPosX + 58, _startPosY + 35);
+ Point[] truba_1 = { point1, point2, point3, point4, point1 };
+ g.FillPolygon(additionalBrush, truba_1);
+
+ Point point5 = new Point(_startPosX + 10, _startPosY + 10);
+ Point point6 = new Point(_startPosX + 10, _startPosY + 45);
+ Point point7 = new Point(_startPosX + 14, _startPosY + 45);
+ Point point8 = new Point(_startPosX + 14, _startPosY + 5);
+ Point[] truba_2 = { point5, point6, point7, point8, point5 };
+ g.FillPolygon(additionalBrush, truba_2);
+
+ Point point9 = new Point(_startPosX + 14, _startPosY + 5);
+ Point point10 = new Point(_startPosX + 14, _startPosY);
+ Point point11 = new Point(_startPosX + 7, _startPosY + 10);
+ Point[] triangle = { point9, point10, point11, point9 };
+ g.FillPolygon(additionalBrush, triangle);
+
+ Point point12 = new Point(_startPosX + 14, _startPosY);
+ Point point13 = new Point(_startPosX + 50, _startPosY + 12);
+ Point point14 = new Point(_startPosX + 50, _startPosY + 16);
+ Point point15 = new Point(_startPosX + 14, _startPosY);
+ Point[] krepl = { point12, point13, point14, point15, point12 };
+ g.FillPolygon(additionalBrush, krepl);
+ DrawingKatki.Draw(_startPosX + 35, _startPosY + 10, EntityExcavator.BodyColor, g);
+ }
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/DrawingKatkiCircle.cs b/ProjectExcavator/ProjectExcavator/DrawingKatkiCircle.cs
new file mode 100644
index 0000000..428cc9d
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/DrawingKatkiCircle.cs
@@ -0,0 +1,90 @@
+using ProjectWarmlyShip;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectExcavator
+{
+ public class DrawKatkiCircle : IDrawingKatki
+ {
+ private KatkiNumber KatNum;
+ public int Properties
+ {
+ get
+ {
+ return Properties;
+ }
+ set
+ {
+ switch (value)
+ {
+ case 1:
+ KatNum = KatkiNumber.Four;
+ break;
+ case 2:
+ KatNum = KatkiNumber.Five;
+ break;
+ case 3:
+ KatNum = KatkiNumber.Six;
+ break;
+ default:
+ KatNum = KatkiNumber.Four;
+ MessageBox.Show("Было введено некорректное количество катков, поэтому было отрисовано стандартное количество катков");
+ break;
+ }
+ }
+ }
+ public void Draw(int _startPosX, int _startPosY, Color katkiColor, Graphics g)
+ {
+ Pen pen = new Pen(Color.Black);
+ Brush KatkiColor = new SolidBrush(katkiColor);
+ Brush brBlack = new SolidBrush(Color.Black);
+ if (KatNum == KatkiNumber.Four)
+ {
+ g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 30, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 60, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
+
+ g.FillEllipse(KatkiColor, _startPosX + 8, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 33, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 63, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 88, _startPosY + 61, 8, 8);
+
+ }
+ if (KatNum == KatkiNumber.Five)
+ {
+ g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 25, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 85, _startPosY + 58, 15, 15);
+
+ g.FillEllipse(KatkiColor, _startPosX + 8, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 28, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 48, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 68, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 88, _startPosY + 61, 8, 8);
+ }
+ if (KatNum == KatkiNumber.Six)
+ {
+ g.FillEllipse(brBlack, _startPosX + 5, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 50, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 65, _startPosY + 58, 15, 15);
+ g.FillEllipse(brBlack, _startPosX + 80, _startPosY + 58, 15, 15);
+
+ g.FillEllipse(KatkiColor, _startPosX + 8, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 23, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 38, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 53, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 68, _startPosY + 61, 8, 8);
+ g.FillEllipse(KatkiColor, _startPosX + 83, _startPosY + 61, 8, 8);
+
+ }
+ }
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs b/ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs
new file mode 100644
index 0000000..4fc56be
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ProjectExcavator.DrawingObjects;
+
+namespace ProjectExcavator.MovementStrategy
+{
+ ///
+ /// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
+ ///
+ public class DrawingObjectExcavator : IMoveableObject
+ {
+ private readonly DrawingExcavator? _drawingExcavator = null;
+ public DrawingObjectExcavator(DrawingExcavator drawingExcavator)
+ {
+ _drawingExcavator = drawingExcavator;
+ }
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_drawingExcavator == null || _drawingExcavator.EntityExcavator ==
+ null)
+ {
+ return null;
+ }
+ return new ObjectParameters(_drawingExcavator.GetPosX,
+ _drawingExcavator.GetPosY, _drawingExcavator.GetWidth, _drawingExcavator.GetHeight);
+ }
+ }
+ public int GetStep => (int)(_drawingExcavator?.EntityExcavator?.Step ?? 0);
+ public bool CheckCanMove(DirectionType direction) =>
+ _drawingExcavator?.CanMove(direction) ?? false;
+ public void MoveObject(DirectionType direction) =>
+ _drawingExcavator?.MoveTransport(direction);
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/EntityExcavator.cs b/ProjectExcavator/ProjectExcavator/EntityExcavator.cs
index 525709d..25fd29a 100644
--- a/ProjectExcavator/ProjectExcavator/EntityExcavator.cs
+++ b/ProjectExcavator/ProjectExcavator/EntityExcavator.cs
@@ -4,10 +4,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-namespace ProjectExcavator
+namespace ProjectExcavator.Entities
{
public class EntityExcavator
{
+ public int numKatki;
///
/// Скорость
///
@@ -21,14 +22,6 @@ namespace ProjectExcavator
///
public Color BodyColor { get; private set; }
///
- /// Ковш
- ///
- public bool Kovsh { get; private set; }
- ///
- /// Дополнительный цвет (для опциональных элементов)
- ///
- public Color AdditionalColor { get; private set; }
- ///
/// Шаг перемещения автомобиля
///
public double Step => (double)Speed * 100 / Weight;
@@ -38,16 +31,11 @@ namespace ProjectExcavator
/// Скорость
/// Вес автомобиля
/// Основной цвет
- /// Дополнительный цвет
- /// Ковш
- public void Init(int speed, double weight, Color bodyColor, Color
- additionalColor, bool kovsh)
+ public EntityExcavator(int speed, double weight, Color bodyColor)
{
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
- AdditionalColor = additionalColor;
- Kovsh = kovsh;
}
}
}
diff --git a/ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs b/ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs
new file mode 100644
index 0000000..4dbd852
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectExcavator.Entities
+{
+ ///
+ /// Класс-сущность "Экскаватор Ковш"
+ ///
+ public class EntityExcavatorKovsh : EntityExcavator
+ {
+ ///
+ /// Дополнительный цвет (для опциональных элементов)
+ ///
+ public Color AdditionalColor { get; private set; }
+ ///
+ /// Ковш
+ ///
+ public bool Kovsh { get; private set; }
+ ///
+ /// Катки гусеничные
+ ///
+ public bool Katki { get; private set; }
+
+ ///
+ /// Инициализация полей объекта-класса экскаватора с ковшом
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Признак наличия ковша
+ /// Признак наличия катков
+ public EntityExcavatorKovsh(int speed, double weight, Color bodyColor, Color additionalColor, bool kovsh, bool katki) : base(speed, weight, bodyColor)
+ {
+ AdditionalColor = additionalColor;
+ Kovsh = kovsh;
+ Katki = katki;
+ }
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/FormExcavator.Designer.cs b/ProjectExcavator/ProjectExcavator/FormExcavator.Designer.cs
index e03f788..61b36ca 100644
--- a/ProjectExcavator/ProjectExcavator/FormExcavator.Designer.cs
+++ b/ProjectExcavator/ProjectExcavator/FormExcavator.Designer.cs
@@ -29,14 +29,15 @@
private void InitializeComponent()
{
this.pictureBoxExcavator = new System.Windows.Forms.PictureBox();
- this.buttonCreate = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
- this.numericUpDownKatkiNumber = new System.Windows.Forms.NumericUpDown();
+ this.buttonCreateExKovsh = new System.Windows.Forms.Button();
+ this.buttonCreateEx = new System.Windows.Forms.Button();
+ this.buttonStep = new System.Windows.Forms.Button();
+ this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxExcavator)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDownKatkiNumber)).BeginInit();
this.SuspendLayout();
//
// pictureBoxExcavator
@@ -48,23 +49,12 @@
this.pictureBoxExcavator.TabIndex = 0;
this.pictureBoxExcavator.TabStop = false;
//
- // buttonCreate
- //
- this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonCreate.Location = new System.Drawing.Point(0, 438);
- this.buttonCreate.Name = "buttonCreate";
- this.buttonCreate.Size = new System.Drawing.Size(75, 23);
- this.buttonCreate.TabIndex = 1;
- this.buttonCreate.Text = "Создать";
- this.buttonCreate.UseVisualStyleBackColor = true;
- this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
- //
// buttonLeft
//
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::ProjectExcavator.Properties.Resources.влево;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonLeft.Location = new System.Drawing.Point(780, 427);
+ this.buttonLeft.Location = new System.Drawing.Point(762, 404);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 2;
@@ -76,7 +66,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ProjectExcavator.Properties.Resources.право;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonRight.Location = new System.Drawing.Point(852, 427);
+ this.buttonRight.Location = new System.Drawing.Point(842, 404);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 3;
@@ -88,7 +78,7 @@
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::ProjectExcavator.Properties.Resources.up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonUp.Location = new System.Drawing.Point(816, 391);
+ this.buttonUp.Location = new System.Drawing.Point(803, 368);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 4;
@@ -100,36 +90,70 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::ProjectExcavator.Properties.Resources.down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Zoom;
- this.buttonDown.Location = new System.Drawing.Point(816, 427);
+ this.buttonDown.Location = new System.Drawing.Point(803, 404);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 5;
this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.Click += new System.EventHandler(this.buttonMove_Click);
//
- // numericUpDownKatkiNumber
+ // buttonCreateExKovsh
//
- this.numericUpDownKatkiNumber.Location = new System.Drawing.Point(81, 438);
- this.numericUpDownKatkiNumber.Name = "numericUpDownKatkiNumber";
- this.numericUpDownKatkiNumber.Size = new System.Drawing.Size(120, 23);
- this.numericUpDownKatkiNumber.TabIndex = 6;
+ this.buttonCreateExKovsh.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreateExKovsh.Location = new System.Drawing.Point(12, 426);
+ this.buttonCreateExKovsh.Name = "buttonCreateExKovsh";
+ this.buttonCreateExKovsh.Size = new System.Drawing.Size(180, 23);
+ this.buttonCreateExKovsh.TabIndex = 6;
+ this.buttonCreateExKovsh.Text = "Создать экскаватор с ковшом";
+ this.buttonCreateExKovsh.UseVisualStyleBackColor = true;
+ this.buttonCreateExKovsh.Click += new System.EventHandler(this.buttonCreateExKovsh_Click);
+ //
+ // buttonCreateEx
+ //
+ this.buttonCreateEx.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonCreateEx.Location = new System.Drawing.Point(198, 426);
+ this.buttonCreateEx.Name = "buttonCreateEx";
+ this.buttonCreateEx.Size = new System.Drawing.Size(133, 23);
+ this.buttonCreateEx.TabIndex = 7;
+ this.buttonCreateEx.Text = "Создать";
+ this.buttonCreateEx.UseVisualStyleBackColor = true;
+ this.buttonCreateEx.Click += new System.EventHandler(this.buttonCreateEx_Click);
+ //
+ // buttonStep
+ //
+ this.buttonStep.Location = new System.Drawing.Point(797, 41);
+ this.buttonStep.Name = "buttonStep";
+ this.buttonStep.Size = new System.Drawing.Size(75, 23);
+ this.buttonStep.TabIndex = 8;
+ this.buttonStep.Text = "Шаг";
+ this.buttonStep.UseVisualStyleBackColor = true;
+ this.buttonStep.Click += new System.EventHandler(this.buttonStep_Click);
+ //
+ // comboBoxStrategy
+ //
+ this.comboBoxStrategy.FormattingEnabled = true;
+ this.comboBoxStrategy.Location = new System.Drawing.Point(751, 12);
+ this.comboBoxStrategy.Name = "comboBoxStrategy";
+ this.comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
+ this.comboBoxStrategy.TabIndex = 9;
//
// FormExcavator
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(884, 461);
- this.Controls.Add(this.numericUpDownKatkiNumber);
+ this.Controls.Add(this.comboBoxStrategy);
+ this.Controls.Add(this.buttonStep);
+ this.Controls.Add(this.buttonCreateEx);
+ this.Controls.Add(this.buttonCreateExKovsh);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonLeft);
- this.Controls.Add(this.buttonCreate);
this.Controls.Add(this.pictureBoxExcavator);
this.Name = "FormExcavator";
this.Text = "FormExcavator";
((System.ComponentModel.ISupportInitialize)(this.pictureBoxExcavator)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.numericUpDownKatkiNumber)).EndInit();
this.ResumeLayout(false);
}
@@ -137,11 +161,13 @@
#endregion
private PictureBox pictureBoxExcavator;
- private Button buttonCreate;
private Button buttonLeft;
private Button buttonRight;
private Button buttonUp;
private Button buttonDown;
- private NumericUpDown numericUpDownKatkiNumber;
+ private Button buttonCreateExKovsh;
+ private Button buttonCreateEx;
+ private Button buttonStep;
+ private ComboBox comboBoxStrategy;
}
}
\ No newline at end of file
diff --git a/ProjectExcavator/ProjectExcavator/FormExcavator.cs b/ProjectExcavator/ProjectExcavator/FormExcavator.cs
index 5899697..e1a68aa 100644
--- a/ProjectExcavator/ProjectExcavator/FormExcavator.cs
+++ b/ProjectExcavator/ProjectExcavator/FormExcavator.cs
@@ -1,12 +1,22 @@
+using ProjectExcavator.DrawingObjects;
+using ProjectExcavator.MovementStrategy;
+
namespace ProjectExcavator
{
public partial class FormExcavator : Form
{
private DrawingExcavator? _drawingExcavator;
+ ///
+ ///
+ ///
+ private AbstractStrategy? _abstractStrategy;
public FormExcavator()
{
InitializeComponent();
+ comboBoxStrategy.Items.Add("");
+ comboBoxStrategy.Items.Add("");
+
}
private void Draw()
@@ -20,21 +30,27 @@ namespace ProjectExcavator
_drawingExcavator.DrawTransport(g);
pictureBoxExcavator.Image = bmp;
}
-
- private void buttonCreate_Click(object sender, EventArgs e)
+ private void buttonCreateExKovsh_Click(object sender, EventArgs e)
{
Random random = new();
- _drawingExcavator = new DrawingExcavator();
- _drawingExcavator.Init(random.Next(300, 1000), random.Next(1000, 2000),
- 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)),
- pictureBoxExcavator.Width, pictureBoxExcavator.Height);
- _drawingExcavator.SetPosition(random.Next(100, 300), random.Next(100, 300));
- _drawingExcavator.Katki.KatNum = (int)numericUpDownKatkiNumber.Value;
+ _drawingExcavator = new DrawingExcavatorKovsh(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)),
+ pictureBoxExcavator.Width, pictureBoxExcavator.Height, random.Next(1, 4), random.Next(1, 4));
+ _drawingExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ Draw();
+ }
+ private void buttonCreateEx_Click(object sender, EventArgs e)
+ {
+ Random random = new();
+ _drawingExcavator = new DrawingExcavator(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, random.Next(1, 4), random.Next(1, 4));
+ _drawingExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
}
-
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingExcavator == null)
@@ -59,5 +75,46 @@ namespace ProjectExcavator
}
Draw();
}
+ ///
+ /// ""
+ ///
+ ///
+ ///
+ private void buttonStep_Click(object sender, EventArgs e)
+ {
+ if (_drawingExcavator == null)
+ {
+ return;
+ }
+ if (comboBoxStrategy.Enabled)
+ {
+ _abstractStrategy = comboBoxStrategy.SelectedIndex
+ switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_abstractStrategy == null)
+ {
+ return;
+ }
+ _abstractStrategy.SetData(new
+ DrawingObjectExcavator(_drawingExcavator), 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/ProjectExcavator/ProjectExcavator/IDrawingKatki.cs b/ProjectExcavator/ProjectExcavator/IDrawingKatki.cs
new file mode 100644
index 0000000..7b69999
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/IDrawingKatki.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectWarmlyShip
+{
+ public interface IDrawingKatki
+ {
+ int Properties { get; set; }
+ void Draw(int _startPosX, int _startPosY, Color katkiColor, Graphics g);
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/IMoveableObject.cs b/ProjectExcavator/ProjectExcavator/IMoveableObject.cs
new file mode 100644
index 0000000..048b833
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/IMoveableObject.cs
@@ -0,0 +1,34 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectExcavator.MovementStrategy
+{
+ ///
+ /// Интерфейс для работы с перемещаемым объектом
+ ///
+ public interface IMoveableObject
+ {
+ ///
+ /// Получение координаты X объекта
+ ///
+ ObjectParameters? GetObjectPosition { get; }
+ ///
+ /// Шаг объекта
+ ///
+ int GetStep { get; }
+ ///
+ /// Проверка, можно ли переместиться по нужному направлению
+ ///
+ ///
+ ///
+ bool CheckCanMove(DirectionType direction);
+ ///
+ /// Изменение направления перемещения объекта
+ ///
+ /// Направление
+ void MoveObject(DirectionType direction);
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/MoveToBorder.cs b/ProjectExcavator/ProjectExcavator/MoveToBorder.cs
new file mode 100644
index 0000000..27cbbfe
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/MoveToBorder.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectExcavator.MovementStrategy
+{
+ ///
+ /// Стратегия перемещения объекта в правый нижний угол экрана
+ ///
+ public class MoveToBorder : AbstractStrategy
+ {
+ protected override bool IsTargetDestinaion()
+ {
+ var objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.ObjectBorderRight <= FieldWidth &&
+ objParams.ObjectBorderRight + GetStep() >= FieldWidth &&
+ objParams.ObjectBorderDown <= FieldHeight &&
+ objParams.ObjectBorderDown + GetStep() >= FieldHeight;
+ }
+ protected override void MoveToTarget()
+ {
+ var objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ var diffX = objParams.ObjectBorderRight - FieldWidth;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+
+ }
+ var diffY = objParams.ObjectBorderDown - FieldHeight;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/MoveToCenter.cs b/ProjectExcavator/ProjectExcavator/MoveToCenter.cs
new file mode 100644
index 0000000..9d91eff
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/MoveToCenter.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectExcavator.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/ProjectExcavator/ProjectExcavator/ObjectParameters.cs b/ProjectExcavator/ProjectExcavator/ObjectParameters.cs
new file mode 100644
index 0000000..7f05a69
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/ObjectParameters.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectExcavator.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 int ObjectBorderRight => _x + _width;
+ public int ObjectBorderDown => _y + _height;
+ ///
+ /// Конструктор
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина
+ /// Высота
+ public ObjectParameters(int x, int y, int width, int height)
+ {
+ _x = x;
+ _y = y;
+ _width = width;
+ _height = height;
+ }
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/Status.cs b/ProjectExcavator/ProjectExcavator/Status.cs
new file mode 100644
index 0000000..78ad5b4
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/Status.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectExcavator.MovementStrategy
+{
+ public enum Status
+ {
+ NotInit, InProgress, Finish
+ }
+}