From 534f99411176e9b02f2dd9ca340e66d4b21532ef Mon Sep 17 00:00:00 2001
From: sqdselo <147947144+sqdselo@users.noreply.github.com>
Date: Sat, 2 Mar 2024 21:31:53 +0400
Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?=
=?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=BE=D0=B4=D0=B8=D1=82=D0=B5=D0=BB?=
=?UTF-8?q?=D0=B5=D0=B9=20=D0=B8=20=D0=B2=D0=B2=D0=BE=D0=B4=20=D0=BA=D0=BE?=
=?UTF-8?q?=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=D0=BE?=
=?UTF-8?q?=D0=B2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
HoistingCrane/HoistingCrane.sln | 2 +-
.../{ => Drawning}/DirectionType.cs | 2 +-
.../Drawning/DrawningHoistingCrane.cs | 96 ++++++
.../Drawning/DrawningTrackedVehicle.cs | 291 ++++++++++++++++++
.../HoistingCrane/DrawningHoistingCrane.cs | 278 -----------------
.../Entities/EntityHoistingCrane.cs | 46 +++
.../Entities/EntityTrackedVehicle.cs | 52 ++++
.../HoistingCrane/EntityHoistingCrane.cs | 63 ----
.../FormHoistingCrane.Designer.cs | 46 ++-
.../HoistingCrane/FormHoistingCrane.cs | 83 +++--
10 files changed, 575 insertions(+), 384 deletions(-)
rename HoistingCrane/HoistingCrane/{ => Drawning}/DirectionType.cs (93%)
create mode 100644 HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs
create mode 100644 HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs
delete mode 100644 HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs
create mode 100644 HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs
create mode 100644 HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs
delete mode 100644 HoistingCrane/HoistingCrane/EntityHoistingCrane.cs
diff --git a/HoistingCrane/HoistingCrane.sln b/HoistingCrane/HoistingCrane.sln
index 11c2632..ef28e41 100644
--- a/HoistingCrane/HoistingCrane.sln
+++ b/HoistingCrane/HoistingCrane.sln
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34221.43
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HoistingCrane", "HoistingCrane\HoistingCrane.csproj", "{915BDF62-D64D-4AB9-BA2D-8E228E803B7F}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HoistingCrane", "HoistingCrane\HoistingCrane.csproj", "{915BDF62-D64D-4AB9-BA2D-8E228E803B7F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/HoistingCrane/HoistingCrane/DirectionType.cs b/HoistingCrane/HoistingCrane/Drawning/DirectionType.cs
similarity index 93%
rename from HoistingCrane/HoistingCrane/DirectionType.cs
rename to HoistingCrane/HoistingCrane/Drawning/DirectionType.cs
index ffff269..2643ba7 100644
--- a/HoistingCrane/HoistingCrane/DirectionType.cs
+++ b/HoistingCrane/HoistingCrane/Drawning/DirectionType.cs
@@ -1,4 +1,4 @@
-namespace HoistingCrane;
+namespace HoistingCrane.Drawning;
public enum DirectionType : byte //Создали не класс(class), а перечисление (enum)
{
diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs
new file mode 100644
index 0000000..fd24ee4
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Drawning/DrawningHoistingCrane.cs
@@ -0,0 +1,96 @@
+using HoistingCrane.Entities;
+
+namespace HoistingCrane.Drawning;
+
+//В данном классе мы будем думать над полем игры, размерами персонажа, размерами объектов и т.д.
+public class DrawningHoistingCrane : DrawningTrackedVehicle
+{
+ ///
+ /// Класс - сущность
+ ///
+ public EntityHoistingCrane? EntityHoistingCrane { get; private set; }
+
+ ///
+ /// Ширина окна
+ ///
+ private int? _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ private int? _pictureHeight;
+
+ ///
+ /// Ширина прорисовки автомобиля
+ ///
+ private readonly int _drawingCarWidth = 115;
+ ///
+ /// Высота прорисовки автомобиля
+ ///
+ private readonly int _drawingCarHeight = 63;
+
+
+ ///
+ /// конструктор класса отрисовки крана
+ ///
+ /// Дополнительный цвет
+ /// Противовес
+ /// Платформа
+ public DrawningHoistingCrane(int speed, int weight, Color bodyColor, Color additionalColor, bool counterweight, bool platform) : base(115, 63)
+ {
+ EntityTrackedVehicle = new EntityHoistingCrane(speed, weight, bodyColor, additionalColor, counterweight, platform);
+ }
+
+
+
+
+
+
+
+ ///
+ /// Метод отрисовки объекта
+ ///
+ ///
+ public override void DrawTransport(Graphics gr)
+ {
+ if (EntityTrackedVehicle == null || EntityTrackedVehicle is not EntityHoistingCrane EntityHoistingCrane || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ base.DrawTransport(gr);
+ Brush b = new SolidBrush(EntityHoistingCrane.AdditionalColor);
+ Pen pen = new Pen(EntityHoistingCrane.AdditionalColor);
+ Pen penBase = new Pen(EntityHoistingCrane.BodyColor);
+ if (EntityHoistingCrane.Counterweight)
+ {
+ //противовес
+
+ gr.DrawRectangle(pen, _startPosX.Value + 69, _startPosY.Value + 3, 10, 10);
+ gr.DrawLine(pen, _startPosX.Value + 68, _startPosY.Value + 3, _startPosX.Value + 78, _startPosY.Value + 12);
+ gr.DrawLine(pen, _startPosX.Value + 68, _startPosY.Value + 7, _startPosX.Value + 78, _startPosY.Value + 3);
+ }
+
+ if (EntityHoistingCrane.Platform) {
+ //Наличие спусковой платформы
+
+ gr.FillRectangle(b, _startPosX.Value + 101, _startPosY.Value + 40, 15, 5);
+ gr.FillRectangle(b, _startPosX.Value + 116, _startPosY.Value + 35, 4, 5);
+ gr.FillRectangle(b, _startPosX.Value + 97, _startPosY.Value + 35, 4, 5);
+ }
+
+
+ //Отрисовка крана, на котором держится платформа и противовес
+ gr.FillRectangle(b, _startPosX.Value + 65, _startPosY.Value, 5, 26);
+ gr.FillRectangle(b, _startPosX.Value + 65, _startPosY.Value, 50, 4);
+ gr.DrawLine(penBase, _startPosX.Value + 115, _startPosY.Value + 4, _startPosX.Value + 108, _startPosY.Value + 40);
+
+ }
+
+
+
+
+
+}
+
+
diff --git a/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs b/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs
new file mode 100644
index 0000000..a7e9b85
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Drawning/DrawningTrackedVehicle.cs
@@ -0,0 +1,291 @@
+using HoistingCrane.Entities;
+
+namespace HoistingCrane.Drawning
+{
+ //В данном классе мы будем думать над полем игры, размерами персонажа, размерами объектов и т.д.
+ public class DrawningTrackedVehicle
+ {
+
+
+
+
+
+
+ ///
+ /// Класс - сущность
+ ///
+ public EntityTrackedVehicle? EntityTrackedVehicle { get; protected set; }
+
+ ///
+ /// Ширина окна
+ ///
+ private int? _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ private int? _pictureHeight;
+
+ ///
+ /// Стартовая позиция по х
+ ///
+ protected int? _startPosX;
+ ///
+ /// Стартовая позиция по у
+ ///
+ protected int? _startPosY;
+
+ ///
+ /// Ширина прорисовки автомобиля
+ ///
+ private readonly int _drawingCarWidth = 83;
+ ///
+ /// Высота прорисовки автомобиля
+ ///
+ private readonly int _drawingCarHeight = 63;
+
+
+
+ ///
+ /// Конструктор класса, который принимает параметры автомобиля(скорость, вес и цвет) и создает объект класса с данными параметрами
+ ///
+ /// Скорость
+ /// Вес
+ /// Цвет
+ public DrawningTrackedVehicle(int speed, double weight, Color bodyColor) : this()
+ {
+ EntityTrackedVehicle = new EntityTrackedVehicle(speed, weight, bodyColor);
+ }
+
+
+
+ ///
+ /// Конструктор, при вызове которого можем менять границы транспорта
+ ///
+ /// Ширина прорисовки автомобиля
+ /// Высота прорисовки автомобиля
+ protected DrawningTrackedVehicle(int _drawingCarWidth, int _drawingCarHeight) : this()
+ {
+ this._drawingCarWidth = _drawingCarWidth;
+ this._drawingCarHeight = _drawingCarHeight;
+ }
+
+
+
+
+
+
+ ///
+ /// Приватный конструктор, который делает значения границ окна = null и стартовую позицию = null
+ ///
+ private DrawningTrackedVehicle()
+ {
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+ }
+
+
+
+
+
+
+ ///
+ /// Метод отрисовки игрового поля
+ ///
+ /// Ширина поля
+ /// Высота поля
+ ///
+
+ public bool SetPictureSize(int width, int height)
+ {
+ // TODO проверка, что объект "влезает" в размеры поля
+ // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена ✔
+
+ if (_drawingCarHeight > height || _drawingCarWidth > width)
+ {
+ return false;
+ }
+
+ _pictureHeight = height;
+ _pictureWidth = width;
+
+ if (_startPosX.HasValue && _startPosX.Value + _drawingCarWidth > _pictureWidth)
+ {
+ _startPosX = _pictureWidth - _drawingCarWidth;
+ }
+
+ if (_startPosY.HasValue && _startPosY.Value + _drawingCarHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight - _drawingCarHeight;
+ }
+ return true;
+
+ }
+
+
+
+ ///
+ /// Установим позицию игрока
+ ///
+ /// Координата по Х
+ /// Координата по У
+ public void SetPosition(int x, int y)
+ {
+ //Если размеры были заданы, то присваиваем х и у, иначе выходим из метода
+
+ if (x < 0)
+ x = -x;
+ if (y < 0)
+ y = -y;
+ if (x + _drawingCarWidth > _pictureWidth)
+ {
+ _startPosX = _pictureWidth - _drawingCarWidth;
+ }
+ else
+ {
+ _startPosX = x;
+ }
+ if (y + _drawingCarHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight - _drawingCarHeight;
+ }
+ else
+ {
+ _startPosY = y;
+ }
+
+
+ }
+
+ ///
+ /// Перемещение машины
+ ///
+ ///
+ ///
+ public bool MoveTransport(DirectionType direction)
+ {
+ if (EntityTrackedVehicle == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return false;
+ }
+
+ switch (direction)
+ {
+ //влево
+ case DirectionType.Left:
+ if (_startPosX.Value - EntityTrackedVehicle.Step > 0)
+ {
+ _startPosX -= (int)EntityTrackedVehicle.Step;
+ }
+
+ return true;
+ //вверх
+ case DirectionType.Up:
+ if (_startPosY.Value - EntityTrackedVehicle.Step > 0)
+ {
+ _startPosY -= (int)EntityTrackedVehicle.Step;
+ }
+ return true;
+
+ //вправо
+ case DirectionType.Right:
+ if (_startPosX.Value + EntityTrackedVehicle.Step + _drawingCarWidth < _pictureWidth)
+ {
+ _startPosX += (int)EntityTrackedVehicle.Step;
+ }
+ return true;
+
+ //вниз
+ case DirectionType.Down:
+ if (_startPosY.Value + EntityTrackedVehicle.Step + _drawingCarHeight < _pictureHeight)
+ {
+ _startPosY += (int)EntityTrackedVehicle.Step;
+ }
+ return true;
+
+ default: return false;
+
+
+ }
+
+
+
+
+ }
+
+ ///
+ /// Метод отрисовки объекта
+ ///
+ ///
+ public virtual void DrawTransport(Graphics gr)
+ {
+ if (EntityTrackedVehicle == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+ Pen pen = new Pen(Color.Black);
+
+
+
+
+
+
+ //границы
+ gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 25, 75, 20);
+ gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 25, 25);
+ gr.DrawRectangle(pen, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
+ gr.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
+ gr.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 45, 20, 20);
+ gr.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
+ gr.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
+ gr.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 46, 18, 18);
+ gr.DrawEllipse(pen, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
+ gr.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
+ gr.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
+ gr.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
+ gr.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
+ gr.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
+
+
+
+
+
+
+ //корпус
+ Brush br = new SolidBrush(EntityTrackedVehicle.BodyColor);
+ gr.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 75, 25);
+ gr.FillRectangle(br, _startPosX.Value, _startPosY.Value, 25, 25);
+
+
+ //окно
+ Brush brq = new SolidBrush(Color.AliceBlue);
+ gr.FillRectangle(brq, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
+
+
+ //выхлопная труба
+ Brush brBlack = new SolidBrush(Color.Black);
+ gr.FillRectangle(brBlack, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
+
+
+ //гусеница
+ Brush brDarkGray = new SolidBrush(Color.DarkGray);
+ gr.FillEllipse(brDarkGray, _startPosX.Value - 5, _startPosY.Value + 45, 20, 20);
+ gr.FillEllipse(brDarkGray, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
+ gr.FillRectangle(brDarkGray, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
+
+
+ gr.FillEllipse(brq, _startPosX.Value - 1, _startPosY.Value + 46, 18, 18);
+ gr.FillEllipse(brq, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
+ gr.FillEllipse(brq, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
+ gr.FillEllipse(brq, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
+ gr.FillEllipse(brq, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
+ gr.FillRectangle(brq, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
+ gr.FillRectangle(brq, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
+
+
+
+ }
+ }
+}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs b/HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs
deleted file mode 100644
index 0bf8c35..0000000
--- a/HoistingCrane/HoistingCrane/DrawningHoistingCrane.cs
+++ /dev/null
@@ -1,278 +0,0 @@
-
-namespace HoistingCrane;
-
-//В данном классе мы будем думать над полем игры, размерами персонажа, размерами объектов и т.д.
-public class DrawningHoistingCrane
-{
- ///
- /// Класс - сущность
- ///
- public EntityHoistingCrane? EntityHoistingCrane { get; private set; }
-
- ///
- /// Ширина окна
- ///
- private int? _pictureWidth;
-
- ///
- /// Высота окна
- ///
- private int? _pictureHeight;
-
- ///
- /// Стартовая позиция по х
- ///
- private int? _startPosX;
- ///
- /// Стартовая позиция по у
- ///
- private int? _startPosY;
-
- ///
- /// Ширина прорисовки автомобиля
- ///
- private readonly int _drawingCarWidth = 115;
- ///
- /// Высота прорисовки автомобиля
- ///
- private readonly int _drawingCarHeight = 63;
-
-
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool counterweight, bool platform)
- {
- EntityHoistingCrane = new EntityHoistingCrane();
- EntityHoistingCrane.Init(speed, weight, bodyColor, additionalColor, counterweight, platform);
- _pictureWidth = null;
- _pictureHeight = null;
- _startPosX = null;
- _startPosY = null;
-
- }
-
-
-
-
- ///
- /// Метод отрисовки игрового поля
- ///
- /// Ширина поля
- /// Высота поля
- ///
-
- public bool SetPictureSize(int width, int height)
- {
- // TODO проверка, что объект "влезает" в размеры поля
- // если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена ✔
-
- if (_drawingCarHeight > height || _drawingCarWidth > width)
- {
- return false;
- }
-
- _pictureHeight = height;
- _pictureWidth = width;
-
- if(_startPosX.HasValue && (_startPosX.Value + _drawingCarWidth > _pictureWidth))
- {
- _startPosX =_pictureWidth - _drawingCarWidth;
- }
-
- if(_startPosY.HasValue && (_startPosY.Value + _drawingCarHeight > _pictureHeight))
- {
- _startPosY = _pictureHeight - _drawingCarHeight;
- }
- return true;
-
- }
-
-
-
- ///
- /// Установим позицию игрока
- ///
- /// Координата по Х
- /// Координата по У
- public void SetPosition(int x, int y)
- {
- //Если размеры были заданы, то присваиваем х и у, иначе выходим из метода
-
- if (x < 0)
- x = -x;
- if (y < 0)
- y = -y;
- if(x + _drawingCarWidth > _pictureWidth)
- {
- _startPosX = _pictureWidth - _drawingCarWidth;
- }
- else
- {
- _startPosX = x;
- }
- if (y + _drawingCarHeight > _pictureHeight)
- {
- _startPosY = _pictureHeight - _drawingCarHeight;
- }
- else
- {
- _startPosY = y;
- }
-
-
- }
-
- ///
- /// Перемещение машины
- ///
- ///
- ///
- public bool MoveTransport(DirectionType direction)
- {
- if (EntityHoistingCrane == null || !_startPosX.HasValue || !_startPosY.HasValue)
- {
- return false;
- }
-
- switch (direction)
- {
- //влево
- case DirectionType.Left:
- if (_startPosX.Value - EntityHoistingCrane.Step > 0)
- {
- _startPosX -= (int)EntityHoistingCrane.Step;
- }
-
- return true;
- //вверх
- case DirectionType.Up:
- if (_startPosY.Value - EntityHoistingCrane.Step > 0)
- {
- _startPosY -= (int)EntityHoistingCrane.Step;
- }
- return true;
-
- //вправо
- case DirectionType.Right:
- if (_startPosX.Value + EntityHoistingCrane.Step + _drawingCarWidth < _pictureWidth)
- {
- _startPosX += (int)EntityHoistingCrane.Step;
- }
- return true;
-
- //вниз
- case DirectionType.Down:
- if (_startPosY.Value + EntityHoistingCrane.Step + _drawingCarHeight < _pictureHeight)
- {
- _startPosY += (int)EntityHoistingCrane.Step;
- }
- return true;
-
- default: return false;
-
-
- }
-
-
-
-
- }
-
- ///
- /// Метод отрисовки объекта
- ///
- ///
- public void DrawTransport(Graphics gr)
- {
- if (EntityHoistingCrane == null || !_startPosX.HasValue || !_startPosY.HasValue)
- {
- return;
- }
- Pen pen = new Pen(Color.Black);
-
-
-
-
-
-
- //границы
- gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 25, 75, 20);
- gr.DrawRectangle(pen, _startPosX.Value, _startPosY.Value, 25, 25);
- gr.DrawRectangle(pen, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
- gr.DrawRectangle(pen, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
- gr.DrawEllipse(pen, _startPosX.Value - 5, _startPosY.Value + 45, 20, 20);
- gr.DrawEllipse(pen, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
- gr.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
- gr.DrawEllipse(pen, _startPosX.Value - 1, _startPosY.Value + 46, 18, 18);
- gr.DrawEllipse(pen, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
- gr.DrawEllipse(pen, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
- gr.DrawEllipse(pen, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
- gr.DrawEllipse(pen, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
- gr.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
- gr.DrawRectangle(pen, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
-
-
-
-
-
-
- //корпус
- Brush br = new SolidBrush(EntityHoistingCrane.BodyColor);
- gr.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 75, 25);
- gr.FillRectangle(br, _startPosX.Value, _startPosY.Value, 25, 25);
-
- //кран
- Brush bb = new SolidBrush(EntityHoistingCrane.BodyColor);
- gr.FillRectangle(bb, _startPosX.Value + 65, _startPosY.Value, 7, 25);
- gr.FillRectangle(br, _startPosX.Value + 62, _startPosY.Value + 2, 45, 5);
- gr.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value + 2, _startPosX.Value + 107, _startPosY.Value + 40);
-
-
- //окно
- Brush brq = new SolidBrush(EntityHoistingCrane.AdditionalColor);
- gr.FillRectangle(brq, _startPosX.Value + 4, _startPosY.Value + 4, 17, 17);
-
-
-
- //выхлопная труба
- Brush brBlack = new SolidBrush(Color.Black);
- gr.FillRectangle(brBlack, _startPosX.Value + 52, _startPosY.Value + 7, 6, 18);
-
-
- //гусеница
- Brush brDarkGray = new SolidBrush(Color.DarkGray);
- gr.FillEllipse(brDarkGray, _startPosX.Value - 5, _startPosY.Value + 45, 20, 20);
- gr.FillEllipse(brDarkGray, _startPosX.Value + 63, _startPosY.Value + 45, 20, 20);
- gr.FillRectangle(brDarkGray, _startPosX.Value + 5, _startPosY.Value + 45, 68, 20);
-
-
- gr.FillEllipse(brq, _startPosX.Value - 1, _startPosY.Value + 46, 18, 18);
- gr.FillEllipse(brq, _startPosX.Value + 62, _startPosY.Value + 46, 18, 18);
- gr.FillEllipse(brq, _startPosX.Value + 20, _startPosY.Value + 53, 10, 10);
- gr.FillEllipse(brq, _startPosX.Value + 35, _startPosY.Value + 53, 10, 10);
- gr.FillEllipse(brq, _startPosX.Value + 50, _startPosY.Value + 53, 10, 10);
- gr.FillRectangle(brq, _startPosX.Value + 30, _startPosY.Value + 45, 4, 6);
- gr.FillRectangle(brq, _startPosX.Value + 45, _startPosY.Value + 45, 4, 6);
-
- //противовес
- if (EntityHoistingCrane.Counterweight)
- {
- Brush b = new SolidBrush(EntityHoistingCrane.AdditionalColor);
- gr.FillRectangle(b, _startPosX.Value + 68, _startPosY.Value + 5, 10, 10);
- }
-
-
- //Наличие спусковой платформы
- if (EntityHoistingCrane.Platform)
- {
- Pen n = new Pen(EntityHoistingCrane.AdditionalColor);
- gr.DrawRectangle(pen, _startPosX.Value + 101, _startPosY.Value + 40, 15, 5);
- }
-
- }
-
-
-
-
-
-}
-
-
diff --git a/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs b/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs
new file mode 100644
index 0000000..8d75df1
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Entities/EntityHoistingCrane.cs
@@ -0,0 +1,46 @@
+namespace HoistingCrane.Entities;
+
+
+///
+/// - ( )
+///
+public class EntityHoistingCrane : EntityTrackedVehicle
+{
+
+ ///
+ ///
+ ///
+ public Color AdditionalColor { get; protected set; }
+
+ ///
+ ///
+ ///
+ public bool Counterweight { get; protected set; }
+ ///
+ ///
+ ///
+ public bool Platform { get; protected set; }
+
+
+
+
+ ///
+ ///
+ ///
+ /// .
+ ///
+ ///
+
+
+
+ // .
+ public EntityHoistingCrane(int Speed, int Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform) : base(Speed, Weight, BodyColor)
+ {
+ this.AdditionalColor = AdditionalColor;
+ this.Counterweight = Counterweight;
+ this.Platform = Platform;
+
+ }
+
+
+}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs b/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs
new file mode 100644
index 0000000..eaf70c8
--- /dev/null
+++ b/HoistingCrane/HoistingCrane/Entities/EntityTrackedVehicle.cs
@@ -0,0 +1,52 @@
+namespace HoistingCrane.Entities
+{
+
+ ///
+ /// Класс-сущность (Гусеничная машина) Родительский класс
+ ///
+ public class EntityTrackedVehicle
+ {
+ ///
+ /// Скорость, которой обладает объект
+ ///
+ public int Speed { get; protected set; }
+
+
+ ///
+ /// Вес, которым обладает объект
+ ///
+ public double Weight { get; protected set; }
+
+
+ ///
+ /// Основной цвет объекта
+ ///
+ public Color BodyColor { get; protected set; }
+
+
+ ///
+ /// Шаг движения
+ ///
+ public double Step => Speed * 100 / Weight;
+
+
+
+
+
+ ///
+ /// Конструктор сущности
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+
+ public EntityTrackedVehicle(int Speed, double Weight, Color BodyColor)
+ {
+ this.Speed = Speed;
+ this.Weight = Weight;
+ this.BodyColor = BodyColor;
+ }
+
+
+ }
+}
diff --git a/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs b/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs
deleted file mode 100644
index 3fce867..0000000
--- a/HoistingCrane/HoistingCrane/EntityHoistingCrane.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-namespace HoistingCrane;
-
-
-
-public class EntityHoistingCrane
-{
- ///
- /// ,
- ///
- public int Speed { get; private set; }
- ///
- /// ,
- ///
- public double Weight { get; private set; }
- ///
- ///
- ///
- public Color BodyColor { get; private set; }
- ///
- ///
- ///
- public Color AdditionalColor { get; private set; }
-
- ///
- ///
- ///
- public bool Counterweight { get; private set; }
- ///
- ///
- ///
- public bool Platform{ get; private set; }
-
-
- ///
- ///
- ///
- public double Step => Speed * 100 / Weight;
-
-
-
-
- ///
- ///
- ///
- ///
- ///
- ///
- /// .
-
-
-
-
- public void Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor, bool Counterweight, bool Platform)
- {
- this.Speed = Speed;
- this.Weight = Weight;
- this.BodyColor = BodyColor;
- this.AdditionalColor = AdditionalColor;
- this.Counterweight = Counterweight;
- this.Platform = Platform;
- }
-
-}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs b/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs
index 3f8792b..09f3617 100644
--- a/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs
+++ b/HoistingCrane/HoistingCrane/FormHoistingCrane.Designer.cs
@@ -25,11 +25,12 @@ namespace HoistingCrane
private void InitializeComponent()
{
pictureBoxHoistingCrane = new PictureBox();
- buttonCreate = new Button();
+ buttonCreateHoistingCrane = new Button();
ButtonLeft = new Button();
ButtonRight = new Button();
ButtonUp = new Button();
ButtonDown = new Button();
+ buttonCreateTrackedVehicle = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxHoistingCrane).BeginInit();
SuspendLayout();
//
@@ -42,23 +43,23 @@ namespace HoistingCrane
pictureBoxHoistingCrane.TabIndex = 0;
pictureBoxHoistingCrane.TabStop = false;
//
- // buttonCreate
+ // buttonCreateHoistingCrane
//
- buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(0, 492);
- buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(75, 23);
- buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать";
- buttonCreate.UseVisualStyleBackColor = true;
- buttonCreate.Click += ButtonCreate_Click;
+ buttonCreateHoistingCrane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateHoistingCrane.Location = new Point(0, 492);
+ buttonCreateHoistingCrane.Name = "buttonCreateHoistingCrane";
+ buttonCreateHoistingCrane.Size = new Size(188, 23);
+ buttonCreateHoistingCrane.TabIndex = 1;
+ buttonCreateHoistingCrane.Text = "Создать подъемный кран";
+ buttonCreateHoistingCrane.UseVisualStyleBackColor = true;
+ buttonCreateHoistingCrane.Click += ButtonCreateHoistingCrane_Click;
//
// ButtonLeft
//
ButtonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonLeft.BackgroundImage = Properties.Resources.left_arrow;
ButtonLeft.BackgroundImageLayout = ImageLayout.Stretch;
- ButtonLeft.Location = new Point(118, 404);
+ ButtonLeft.Location = new Point(642, 475);
ButtonLeft.Name = "ButtonLeft";
ButtonLeft.Size = new Size(40, 40);
ButtonLeft.TabIndex = 2;
@@ -70,7 +71,7 @@ namespace HoistingCrane
ButtonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonRight.BackgroundImage = Properties.Resources.right_arrow;
ButtonRight.BackgroundImageLayout = ImageLayout.Stretch;
- ButtonRight.Location = new Point(207, 404);
+ ButtonRight.Location = new Point(734, 475);
ButtonRight.Name = "ButtonRight";
ButtonRight.Size = new Size(40, 40);
ButtonRight.TabIndex = 3;
@@ -82,7 +83,7 @@ namespace HoistingCrane
ButtonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonUp.BackgroundImage = Properties.Resources.up_arrow;
ButtonUp.BackgroundImageLayout = ImageLayout.Stretch;
- ButtonUp.Location = new Point(164, 367);
+ ButtonUp.Location = new Point(688, 429);
ButtonUp.Name = "ButtonUp";
ButtonUp.Size = new Size(40, 40);
ButtonUp.TabIndex = 4;
@@ -94,23 +95,35 @@ namespace HoistingCrane
ButtonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
ButtonDown.BackgroundImage = Properties.Resources.arrow_down_sign_to_navigate;
ButtonDown.BackgroundImageLayout = ImageLayout.Stretch;
- ButtonDown.Location = new Point(164, 440);
+ ButtonDown.Location = new Point(688, 475);
ButtonDown.Name = "ButtonDown";
ButtonDown.Size = new Size(40, 40);
ButtonDown.TabIndex = 5;
ButtonDown.UseVisualStyleBackColor = true;
ButtonDown.Click += ButtonMove_Click;
//
+ // buttonCreateTrackedVehicle
+ //
+ buttonCreateTrackedVehicle.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateTrackedVehicle.Location = new Point(203, 492);
+ buttonCreateTrackedVehicle.Name = "buttonCreateTrackedVehicle";
+ buttonCreateTrackedVehicle.Size = new Size(194, 23);
+ buttonCreateTrackedVehicle.TabIndex = 6;
+ buttonCreateTrackedVehicle.Text = "Создать бронебойную машину";
+ buttonCreateTrackedVehicle.UseVisualStyleBackColor = true;
+ buttonCreateTrackedVehicle.Click += buttonCreateTrackedVehicle_Click;
+ //
// FormHoistingCrane
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(818, 515);
+ Controls.Add(buttonCreateTrackedVehicle);
Controls.Add(ButtonDown);
Controls.Add(ButtonUp);
Controls.Add(ButtonRight);
Controls.Add(ButtonLeft);
- Controls.Add(buttonCreate);
+ Controls.Add(buttonCreateHoistingCrane);
Controls.Add(pictureBoxHoistingCrane);
Name = "FormHoistingCrane";
Text = "Подъемный кран";
@@ -121,10 +134,11 @@ namespace HoistingCrane
// #endregion
private PictureBox pictureBoxHoistingCrane;
- private Button buttonCreate;
+ private Button buttonCreateHoistingCrane;
private Button ButtonLeft;
private Button ButtonRight;
private Button ButtonUp;
private Button ButtonDown;
+ private Button buttonCreateTrackedVehicle;
}
}
\ No newline at end of file
diff --git a/HoistingCrane/HoistingCrane/FormHoistingCrane.cs b/HoistingCrane/HoistingCrane/FormHoistingCrane.cs
index 7250345..6c45118 100644
--- a/HoistingCrane/HoistingCrane/FormHoistingCrane.cs
+++ b/HoistingCrane/HoistingCrane/FormHoistingCrane.cs
@@ -1,9 +1,11 @@
-namespace HoistingCrane
+using HoistingCrane.Drawning;
+
+namespace HoistingCrane
{
public partial class FormHoistingCrane : Form
{
- private DrawningHoistingCrane? _drawningHoistingCrane;
+ private DrawningTrackedVehicle? _drawning;
public FormHoistingCrane()
{
@@ -14,47 +16,78 @@
{
Bitmap bmp = new(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawningHoistingCrane?.DrawTransport(gr);
+ _drawning?.DrawTransport(gr);
pictureBoxHoistingCrane.Image = bmp;
}
- private void ButtonCreate_Click(object sender, EventArgs e)
+
+ ///
+ /// Создать подъемный кран
+ ///
+ ///
+ ///
+ private void ButtonCreateHoistingCrane_Click(object sender, EventArgs e)
{
-
- Random rand = new();
- _drawningHoistingCrane = new DrawningHoistingCrane();
- _drawningHoistingCrane.Init(
- rand.Next(100, 300),
- rand.Next(1000, 3000),
- Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
- Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
- Convert.ToBoolean(rand.Next(0,2)),
- Convert.ToBoolean(rand.Next(0,2))
- );
- _drawningHoistingCrane.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
- _drawningHoistingCrane.SetPosition(rand.Next(0, 100), rand.Next(0, 100));
- Draw();
-
+ CreateObject(nameof(DrawningHoistingCrane));
}
+
+ ///
+ /// Создать бронебойную машину
+ ///
+ ///
+ ///
+ private void buttonCreateTrackedVehicle_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningTrackedVehicle));
+ }
+
+
+ private void CreateObject(string type)
+ {
+ Random rand = new();
+ switch (type)
+ {
+
+ case nameof(DrawningHoistingCrane):
+ _drawning = new DrawningHoistingCrane(rand.Next(100, 300),rand.Next(1000, 3000),Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)),
+ Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)), true, true);
+ break;
+
+ case nameof(DrawningTrackedVehicle):
+ _drawning = new DrawningTrackedVehicle(rand.Next(100, 300), rand.Next(1000, 3000), Color.FromArgb(rand.Next(0, 256), rand.Next(0, 256), rand.Next(0, 256)));
+ break;
+ default:
+ return;
+
+ }
+ _drawning.SetPictureSize(pictureBoxHoistingCrane.Width, pictureBoxHoistingCrane.Height);
+ _drawning.SetPosition(rand.Next(0, 100), rand.Next(0, 100));
+ Draw();
+ }
+
+
+
+
+
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_drawningHoistingCrane == null) { return; }
+ if (_drawning == null) { return; }
String name = ((Button)sender)?.Name ?? string.Empty;
bool result = false;
switch (name)
{
case "ButtonUp":
- result = _drawningHoistingCrane.MoveTransport(DirectionType.Up);
+ result = _drawning.MoveTransport(DirectionType.Up);
break;
case "ButtonDown":
- result = _drawningHoistingCrane.MoveTransport(DirectionType.Down);
+ result = _drawning.MoveTransport(DirectionType.Down);
break;
case "ButtonRight":
- result = _drawningHoistingCrane.MoveTransport(DirectionType.Right);
+ result = _drawning.MoveTransport(DirectionType.Right);
break;
case "ButtonLeft":
- result = _drawningHoistingCrane.MoveTransport(DirectionType.Left);
+ result = _drawning.MoveTransport(DirectionType.Left);
break;
}
if (result)
@@ -65,6 +98,6 @@
}
-
+
}
}