From 72b7375d44ec4a1def286626327ab2a28399288c Mon Sep 17 00:00:00 2001
From: mara-1 <147929076+mara-1@users.noreply.github.com>
Date: Tue, 12 Mar 2024 16:39:33 +0400
Subject: [PATCH 1/2] =?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
---
.../ProjectBulldozer/DrawingBulldozer.cs | 278 ------------------
.../DirectionType.cs} | 10 +-
.../Drawnings/DrawingBulldozer.cs | 104 +++++++
.../Drawnings/DrawningBulldozerProstoy.cs | 234 +++++++++++++++
.../{ => Entities}/EntityBulldozer.cs | 34 +--
.../Entities/EntityBulldozerProstoy.cs | 41 +++
.../FormBulldozer.Designer.cs | 18 +-
.../ProjectBulldozer/FormBulldozer.cs | 74 +++--
8 files changed, 458 insertions(+), 335 deletions(-)
delete mode 100644 ProjectBulldozer/ProjectBulldozer/DrawingBulldozer.cs
rename ProjectBulldozer/ProjectBulldozer/{DirectionType1.cs => Drawnings/DirectionType.cs} (59%)
create mode 100644 ProjectBulldozer/ProjectBulldozer/Drawnings/DrawingBulldozer.cs
create mode 100644 ProjectBulldozer/ProjectBulldozer/Drawnings/DrawningBulldozerProstoy.cs
rename ProjectBulldozer/ProjectBulldozer/{ => Entities}/EntityBulldozer.cs (63%)
create mode 100644 ProjectBulldozer/ProjectBulldozer/Entities/EntityBulldozerProstoy.cs
diff --git a/ProjectBulldozer/ProjectBulldozer/DrawingBulldozer.cs b/ProjectBulldozer/ProjectBulldozer/DrawingBulldozer.cs
deleted file mode 100644
index 0ca5b8b..0000000
--- a/ProjectBulldozer/ProjectBulldozer/DrawingBulldozer.cs
+++ /dev/null
@@ -1,278 +0,0 @@
-namespace ProjectBulldozer;
-
-///
-/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
-///
-public class DrawningBulldozer
-{
- ///
- /// Класс-сущность
- ///
- public EntityBulldozer? EntityBulldozer { get; private set; }
- ///
- /// Ширина окна
- ///
- private int? _pictureWidth;
- ///
- /// Высота окна
- ///
- private int? _pictureHeight;
- ///
- /// Левая координата прорисовки автомобиля
- ///
- private int? _startPosX;
- ///
- /// Верхняя кооридната прорисовки автомобиля
- ///
- private int? _startPosY;
-
- ///
- /// Ширина прорисовки автомобиля
- ///
- private readonly int _BulldozerWidth = 180;
- ///
- /// Высота прорисовки автомобиля
- ///
- private readonly int _BulldozerHeight = 140;
- ///
- /// Инициализация свойств
- ///
- /// Скорость
- /// Вес
- /// Основной цвет
- /// Дополнительный цвет
- /// Признак наличия отвала спереди
- /// Признак наличия рыхлителя сзади
-
- public void Init(int speed, double weight, Color bodyColor, Color
- additionalColor, bool additionalOtval, bool additionalRihl)
- {
- EntityBulldozer = new EntityBulldozer();
- EntityBulldozer.Init(speed, weight, bodyColor, additionalColor, additionalOtval,
- additionalRihl);
-
- _pictureWidth = null;
- _pictureHeight = null;
- _startPosX = null;
- _startPosY = null;
-
- }
- ///
- /// Установка границ поля
- ///
- /// Ширина поля
- /// Высота поля
- /// true - границы заданы, false - проверка не пройдена, нельзя
- public bool SetPictureSize(int width, int height)
- {
- if (_BulldozerWidth < width && _BulldozerHeight < height)
- {
- _pictureWidth = width;
- _pictureHeight = height;
- if (_startPosX.HasValue && _startPosY.HasValue)
- {
- SetPosition(_startPosX.Value, _startPosY.Value);
- }
-
- return true;
- }
- return false;
- }
- ///
- /// Установка позиции
- ///
- /// Координата X
- /// Координата Y
- public void SetPosition(int x, int y)
- {
- if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
- {
- return;
- }
- if (x < 0 || x + _BulldozerWidth > _pictureWidth || y < 0 || y + _BulldozerHeight > _pictureHeight)
- {
- _startPosX = _pictureWidth - _BulldozerWidth;
- _startPosY = _pictureHeight - _BulldozerHeight;
- }
- else
- {
- _startPosX = x;
- _startPosY = y;
- }
- }
- ///
- /// Изменение направления перемещения
- ///
- /// Направление
- /// true - перемещене выполнено, false - перемещение
- public bool MoveTransport(DirectionType1 direction) {
-
- if (EntityBulldozer == null || !_startPosX.HasValue ||
- !_startPosY.HasValue)
- {
- return false;
- }
- switch (direction)
- {
- //влево
- case DirectionType1.Left:
- if (_startPosX.Value - EntityBulldozer.Step > 0)
- {
- _startPosX -= (int)EntityBulldozer.Step;
- }
- return true;
-
- //вверх
- case DirectionType1.Up:
- if (_startPosY.Value - EntityBulldozer.Step > 0)
- {
- _startPosY -= (int)EntityBulldozer.Step;
- }
- return true;
-
- // вправо
- case DirectionType1.Right:
- if (_startPosX + _BulldozerWidth + EntityBulldozer.Step < _pictureWidth)
- {
- _startPosX += (int)EntityBulldozer.Step;
- }
- return true;
-
- //вниз
- case DirectionType1.Down:
- if (_startPosY + _BulldozerHeight + EntityBulldozer.Step < _pictureHeight)
- {
- _startPosY += (int)EntityBulldozer.Step;
- }
- return true;
- default:
- return false;
- }
- }
-
- ///
- /// Прорисовка объекта
- ///
- ///
- public void DrawTransport(Graphics g)
- {
- if (EntityBulldozer == null || !_startPosX.HasValue ||
- !_startPosY.HasValue)
- {
- return;
- }
- Pen pen = new(Color.Black);
- Brush brush = new SolidBrush(Color.Black);
- Brush bl = new SolidBrush(EntityBulldozer.AdditionalColor);
- Brush bodyBrush = new SolidBrush(EntityBulldozer.BodyColor);
- Brush bodyBrush2 = new SolidBrush(EntityBulldozer.AdditionalColor);
-
-
-
-
- //основное тело
- g.FillRectangle(bodyBrush, _startPosX.Value + 20, _startPosY.Value + 40, 120, 60);
-
- g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 40, 120, 60);
-
-
-
- //Гусеницы
- Brush gg = new SolidBrush(Color.LightGray);
- g.FillEllipse(gg, _startPosX.Value + 23, _startPosY.Value + 101, 118, 35);
- g.DrawEllipse(pen, _startPosX.Value + 23, _startPosY.Value + 101, 118, 35);
-
-
-
-
- g.DrawEllipse(pen, _startPosX.Value + 26, _startPosY.Value + 103, 110, 30);
-
- //катки в гусеницах
- Brush gr = new SolidBrush(Color.Gray);
- g.FillEllipse(gr, _startPosX.Value + 40, _startPosY.Value + 108, 20, 20);
- g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 108, 20, 20);
-
-
- g.FillEllipse(gr, _startPosX.Value + 65, _startPosY.Value + 110, 20, 20);
- g.DrawEllipse(pen, _startPosX.Value + 65, _startPosY.Value + 110, 20, 20);
-
- g.FillEllipse(gr, _startPosX.Value + 115, _startPosY.Value + 110, 15, 15);
- g.DrawEllipse(pen, _startPosX.Value + 115, _startPosY.Value + 110, 15, 15);
-
- g.FillEllipse(gr, _startPosX.Value + 90, _startPosY.Value + 110, 20, 20);
- g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 110, 20, 20);
-
-
-
-
- //кабина водителя
- g.FillRectangle(bodyBrush2, _startPosX.Value + 20, _startPosY.Value, 40, 40);
- g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value, 40, 40);
-
-
- //выхлопная труба
- Brush brBr = new SolidBrush(Color.Brown);
-
- g.FillRectangle(brBr, _startPosX.Value + 110, _startPosY.Value, 15, 40);
- g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value, 15, 40);
-
-
-
- //Brush bl = new SolidBrush(Color.LightYellow);
- /////////отвал
- ///
- if (EntityBulldozer.AdditionalOtval)
- {
- Point[] Otval =
- {
- new Point(_startPosX.Value + 142, _startPosY.Value + 70),
- new Point(_startPosX.Value + 172, _startPosY.Value + 130),
- new Point(_startPosX.Value+ 142, _startPosY.Value + 130),
-
-
- };
-
- g.FillPolygon(bl, Otval);
- g.DrawPolygon(pen, Otval);
- }
-
-
-
-
-
- ///рыхлитель
- if (EntityBulldozer.AdditionalRihl)
- {
- Brush black = new SolidBrush(Color.Black);
- Point[] Rihl =
- {
- new Point(_startPosX.Value + 18 , _startPosY.Value + 60),
- new Point(_startPosX.Value + 18, _startPosY.Value + 80),
- new Point(_startPosX.Value, _startPosY.Value + 120),
-
- };
-
- g.FillPolygon(black, Rihl);
- g.DrawPolygon(pen, Rihl);
-
- Point[] Ttt =
- {
- new Point(_startPosX.Value + 18 , _startPosY.Value + 80),
- new Point(_startPosX.Value + 18, _startPosY.Value + 120),
- new Point(_startPosX.Value, _startPosY.Value + 50),
-
- };
- g.FillPolygon(black, Ttt);
- g.DrawPolygon(pen, Ttt);
-
- }
-
-
-
-
-
- }
-}
-
-
-
diff --git a/ProjectBulldozer/ProjectBulldozer/DirectionType1.cs b/ProjectBulldozer/ProjectBulldozer/Drawnings/DirectionType.cs
similarity index 59%
rename from ProjectBulldozer/ProjectBulldozer/DirectionType1.cs
rename to ProjectBulldozer/ProjectBulldozer/Drawnings/DirectionType.cs
index 0afc190..9607f86 100644
--- a/ProjectBulldozer/ProjectBulldozer/DirectionType1.cs
+++ b/ProjectBulldozer/ProjectBulldozer/Drawnings/DirectionType.cs
@@ -1,12 +1,6 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+namespace ProjectBulldozer.Drawnings;
-namespace ProjectBulldozer;
-
-public enum DirectionType1
+public enum DirectionType
{
///
/// Вверх
diff --git a/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawingBulldozer.cs b/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawingBulldozer.cs
new file mode 100644
index 0000000..05f54f3
--- /dev/null
+++ b/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawingBulldozer.cs
@@ -0,0 +1,104 @@
+using ProjectBulldozer.Entities;
+using System.Drawing;
+
+namespace ProjectBulldozer.Drawnings;
+
+///
+/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
+///
+public class DrawningBulldozer : DrawningBulldozerProstoy
+{
+
+ ///
+ /// конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Признак наличия отвала спереди
+ /// Признак наличия рыхлителя сзади
+
+ public DrawningBulldozer(int speed, double weight, Color bodyColor, Color
+ additionalColor, bool additionalOtval, bool additionalRihl, bool v) : base(180, 140)
+ {
+ EntityBulldozerProstoy = new EntityBulldozer(speed, weight, bodyColor, additionalColor, additionalOtval,
+ additionalRihl);
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityBulldozerProstoy == null || EntityBulldozerProstoy is not EntityBulldozer Bulldozer || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush bodyBrush = new SolidBrush(Bulldozer.BodyColor);
+ Brush bodyBrush2 = new SolidBrush(Bulldozer.AdditionalColor);
+
+
+
+
+ _startPosX += 10;
+ _startPosY += 5;
+
+ base.DrawTransport(g);
+ _startPosX -= 10;
+ _startPosY -= 5;
+
+ Brush bl = new SolidBrush(Bulldozer.AdditionalColor);
+ /////////отвал
+ ///
+ if (Bulldozer.AdditionalOtval)
+ {
+ Point[] Otval =
+ {
+ new Point(_startPosX.Value + 142, _startPosY.Value + 70),
+ new Point(_startPosX.Value + 172, _startPosY.Value + 130),
+ new Point(_startPosX.Value+ 142, _startPosY.Value + 130),
+
+
+ };
+
+ g.FillPolygon(bl, Otval);
+ g.DrawPolygon(pen, Otval);
+ }
+
+
+
+
+
+ ///рыхлитель
+ if (Bulldozer.AdditionalRihl)
+ {
+ Brush black = new SolidBrush(Color.Black);
+ Point[] Rihl =
+ {
+ new Point(_startPosX.Value + 18 , _startPosY.Value + 60),
+ new Point(_startPosX.Value + 18, _startPosY.Value + 80),
+ new Point(_startPosX.Value, _startPosY.Value + 120),
+
+ };
+
+ g.FillPolygon(black, Rihl);
+ g.DrawPolygon(pen, Rihl);
+
+ Point[] Ttt =
+ {
+ new Point(_startPosX.Value + 18 , _startPosY.Value + 80),
+ new Point(_startPosX.Value + 18, _startPosY.Value + 120),
+ new Point(_startPosX.Value, _startPosY.Value + 50),
+
+ };
+ g.FillPolygon(black, Ttt);
+ g.DrawPolygon(pen, Ttt);
+
+ }
+ }
+}
+
+
+
+
+
+
diff --git a/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawningBulldozerProstoy.cs b/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawningBulldozerProstoy.cs
new file mode 100644
index 0000000..1522616
--- /dev/null
+++ b/ProjectBulldozer/ProjectBulldozer/Drawnings/DrawningBulldozerProstoy.cs
@@ -0,0 +1,234 @@
+using ProjectBulldozer.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectBulldozer.Drawnings;
+
+public class DrawningBulldozerProstoy
+{
+ ///
+ /// Класс-сущность
+ ///
+ public EntityBulldozerProstoy? EntityBulldozerProstoy { get; protected set; }
+ ///
+ /// Ширина окна
+ ///
+ private int? _pictureWidth;
+ ///
+ /// Высота окна
+ ///
+ private int? _pictureHeight;
+ ///
+ /// Левая координата прорисовки автомобиля
+ ///
+ protected int? _startPosX;
+ ///
+ /// Верхняя кооридната прорисовки автомобиля
+ ///
+ protected int? _startPosY;
+
+ ///
+ /// Ширина прорисовки бульдозера
+ ///
+ private readonly int _BulldozerWidth = 130;
+ ///
+ /// Высота прорисовки бульдозера
+ ///
+ private readonly int _BulldozerHeight = 120;
+
+ ///
+ /// Пустой конструктор
+ ///
+ private DrawningBulldozerProstoy()
+ {
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+ }
+
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ public DrawningBulldozerProstoy(int speed, double weight, Color bodyColor) : this()
+ {
+ EntityBulldozerProstoy = new EntityBulldozerProstoy(speed, weight, bodyColor);
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+
+ }
+
+ ///
+ /// Конструктор для наследников
+ ///
+ /// Ширина прорисовки бульдозера
+ /// Высота прорисовки бульдозера
+ protected DrawningBulldozerProstoy(int BulldozerWidth, int BulldozerHeight) : this()
+ {
+ _BulldozerWidth = BulldozerWidth;
+ _BulldozerHeight = BulldozerHeight;
+
+
+ }
+
+ ///
+ /// Установка границ поля
+ ///
+ /// Ширина поля
+ /// Высота поля
+ /// true - границы заданы, false - проверка не пройдена, нельзя
+ public bool SetPictureSize(int width, int height)
+ {
+ if (_BulldozerWidth < width && _BulldozerHeight < height)
+ {
+ _pictureWidth = width;
+ _pictureHeight = height;
+ if (_startPosX.HasValue && _startPosY.HasValue)
+ {
+ SetPosition(_startPosX.Value, _startPosY.Value);
+ }
+
+ return true;
+ }
+ return false;
+ }
+ ///
+ /// Установка позиции
+ ///
+ /// Координата X
+ /// Координата Y
+ public void SetPosition(int x, int y)
+ {
+ if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
+ {
+ return;
+ }
+ if (x < 0 || x + _BulldozerWidth > _pictureWidth || y < 0 || y + _BulldozerHeight > _pictureHeight)
+ {
+ _startPosX = _pictureWidth - _BulldozerWidth;
+ _startPosY = _pictureHeight - _BulldozerHeight;
+ }
+ else
+ {
+ _startPosX = x;
+ _startPosY = y;
+ }
+ }
+ ///
+ /// Изменение направления перемещения
+ ///
+ /// Направление
+ /// true - перемещене выполнено, false - перемещение
+ public bool MoveTransport(DirectionType direction)
+ {
+
+ if (EntityBulldozerProstoy == null || !_startPosX.HasValue ||
+ !_startPosY.HasValue)
+ {
+ return false;
+ }
+ switch (direction)
+ {
+ //влево
+ case DirectionType.Left:
+ if (_startPosX.Value - EntityBulldozerProstoy.Step > 0)
+ {
+ _startPosX -= (int)EntityBulldozerProstoy.Step;
+ }
+ return true;
+
+ //вверх
+ case DirectionType.Up:
+ if (_startPosY.Value - EntityBulldozerProstoy.Step > 0)
+ {
+ _startPosY -= (int)EntityBulldozerProstoy.Step;
+ }
+ return true;
+
+ // вправо
+ case DirectionType.Right:
+ if (_startPosX + _BulldozerWidth + EntityBulldozerProstoy.Step < _pictureWidth)
+ {
+ _startPosX += (int)EntityBulldozerProstoy.Step;
+ }
+ return true;
+
+ //вниз
+ case DirectionType.Down:
+ if (_startPosY + _BulldozerHeight + EntityBulldozerProstoy.Step < _pictureHeight)
+ {
+ _startPosY += (int)EntityBulldozerProstoy.Step;
+ }
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ ///
+ /// Прорисовка объекта
+ ///
+ ///
+ public virtual void DrawTransport(Graphics g)
+ {
+ if (EntityBulldozerProstoy == null || !_startPosX.HasValue ||
+ !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush brush = new SolidBrush(Color.Black);
+ Brush bodyBrush = new SolidBrush(EntityBulldozerProstoy.BodyColor);
+
+
+ //основное тело
+ g.FillRectangle(bodyBrush, _startPosX.Value + 10, _startPosY.Value + 35, 120, 60);
+ g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 35, 120, 60);
+
+
+
+ //Гусеницы
+ Brush gg = new SolidBrush(Color.LightGray);
+ g.FillEllipse(gg, _startPosX.Value + 13, _startPosY.Value + 96, 118, 35);
+ g.DrawEllipse(pen, _startPosX.Value + 13, _startPosY.Value + 96, 118, 35);
+
+ g.DrawEllipse(pen, _startPosX.Value + 16, _startPosY.Value + 98, 110, 30);
+
+ //катки в гусеницах
+ Brush gr = new SolidBrush(Color.Gray);
+ g.FillEllipse(gr, _startPosX.Value + 30, _startPosY.Value + 104, 20, 20);
+ g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 104, 20, 20);////
+
+
+ g.FillEllipse(gr, _startPosX.Value + 55, _startPosY.Value + 105, 20, 20);
+ g.DrawEllipse(pen, _startPosX.Value + 55, _startPosY.Value + 105, 20, 20);
+
+ g.FillEllipse(gr, _startPosX.Value + 105, _startPosY.Value + 105, 15, 15);
+ g.DrawEllipse(pen, _startPosX.Value + 105, _startPosY.Value + 105, 15, 15);
+
+ g.FillEllipse(gr, _startPosX.Value + 80, _startPosY.Value + 105, 20, 20);
+ g.DrawEllipse(pen, _startPosX.Value + 80, _startPosY.Value + 105, 20, 20);
+
+ //кабина водителя
+ g.FillRectangle(bodyBrush, _startPosX.Value + 10, _startPosY.Value, 40, 40);
+ g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value, 40, 40);
+
+
+ //выхлопная труба
+ Brush brBr = new SolidBrush(Color.Brown);
+
+ g.FillRectangle(brBr, _startPosX.Value + 100, _startPosY.Value, 15, 40);
+ g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value, 15, 40);
+
+
+ }
+}
diff --git a/ProjectBulldozer/ProjectBulldozer/EntityBulldozer.cs b/ProjectBulldozer/ProjectBulldozer/Entities/EntityBulldozer.cs
similarity index 63%
rename from ProjectBulldozer/ProjectBulldozer/EntityBulldozer.cs
rename to ProjectBulldozer/ProjectBulldozer/Entities/EntityBulldozer.cs
index 49856e7..c2be6f2 100644
--- a/ProjectBulldozer/ProjectBulldozer/EntityBulldozer.cs
+++ b/ProjectBulldozer/ProjectBulldozer/Entities/EntityBulldozer.cs
@@ -1,20 +1,11 @@
-
-namespace ProjectBulldozer;
+namespace ProjectBulldozer.Entities;
-public class EntityBulldozer
+public class EntityBulldozer : EntityBulldozerProstoy
{
- ///
- /// Скорость
- ///
- public int Speed { get; private set; }
- ///
- /// Вес
- ///
- public double Weight { get; private set; }
- ///
- /// Основной цвет
- ///
- public Color BodyColor { get; private set; }
+ public EntityBulldozer(int speed, double weight, Color bodyColor) : base(speed, weight, bodyColor)
+ {
+ }
+
///
/// Дополнительный цвет (для опциональных элементов)
///
@@ -28,10 +19,8 @@ public class EntityBulldozer
///
public bool AdditionalRihl { get; private set; }
- ///
- /// Шаг перемещения автомобиля
- ///
- public double Step => Speed * 100 / Weight;
+
+
///
/// Инициализация полей объекта-класса спортивного автомобиля
///
@@ -41,12 +30,9 @@ public class EntityBulldozer
/// Дополнительный цвет
/// Признак наличия отвала спереди
/// Признак наличия рыхлителя сзади
- public void Init(int speed, double weight, Color bodyColor, Color
- additionalColor, bool additionalOtval, bool additionalRihl)
+ public EntityBulldozer(int speed, double weight, Color bodyColor, Color
+ additionalColor, bool additionalOtval, bool additionalRihl) : base(speed, weight, bodyColor)
{
- Speed = speed;
- Weight = weight;
- BodyColor = bodyColor;
AdditionalColor = additionalColor;
AdditionalOtval = additionalOtval;
AdditionalRihl = additionalRihl;
diff --git a/ProjectBulldozer/ProjectBulldozer/Entities/EntityBulldozerProstoy.cs b/ProjectBulldozer/ProjectBulldozer/Entities/EntityBulldozerProstoy.cs
new file mode 100644
index 0000000..ec67c8b
--- /dev/null
+++ b/ProjectBulldozer/ProjectBulldozer/Entities/EntityBulldozerProstoy.cs
@@ -0,0 +1,41 @@
+namespace ProjectBulldozer.Entities;
+
+///
+/// Класс-сущность "Бульдозер простой"
+///
+public class EntityBulldozerProstoy
+{
+ ///
+ /// Скорость
+ ///
+ public int Speed { get; private set; }
+ ///
+ /// Вес
+ ///
+ public double Weight { get; private set; }
+ ///
+ /// Основной цвет
+ ///
+ public Color BodyColor { get; private set; }
+
+ ///
+ /// Шаг перемещения автомобиля
+ ///
+ public double Step => Speed * 100 / Weight;
+
+ ///
+ /// Конструктор сущности
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Основной цвет
+
+ public EntityBulldozerProstoy(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+
+
+ }
+}
diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs
index 5d8a28c..013d371 100644
--- a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs
+++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.Designer.cs
@@ -34,6 +34,7 @@
buttonDown = new Button();
buttonLeft = new Button();
buttonUp = new Button();
+ buttonCreateBulldozerProstoy = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxBulldozer).BeginInit();
SuspendLayout();
//
@@ -51,9 +52,9 @@
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(12, 511);
buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(94, 29);
+ buttonCreate.Size = new Size(231, 29);
buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать";
+ buttonCreate.Text = "Создать бульозер с доп.";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreateBulldozer_Click;
//
@@ -105,9 +106,21 @@
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
+ // buttonCreateBulldozerProstoy
+ //
+ buttonCreateBulldozerProstoy.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateBulldozerProstoy.Location = new Point(274, 511);
+ buttonCreateBulldozerProstoy.Name = "buttonCreateBulldozerProstoy";
+ buttonCreateBulldozerProstoy.Size = new Size(231, 29);
+ buttonCreateBulldozerProstoy.TabIndex = 6;
+ buttonCreateBulldozerProstoy.Text = "Создать простой бульдозер";
+ buttonCreateBulldozerProstoy.UseVisualStyleBackColor = true;
+ buttonCreateBulldozerProstoy.Click += buttonCreateBulldozerProstoy_Click;
+ //
// FormBulldozer
//
ClientSize = new Size(899, 552);
+ Controls.Add(buttonCreateBulldozerProstoy);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
Controls.Add(buttonDown);
@@ -128,5 +141,6 @@
private Button buttonDown;
private Button buttonLeft;
private Button buttonUp;
+ private Button buttonCreateBulldozerProstoy;
}
}
\ No newline at end of file
diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs
index ffb86de..5aa2a3d 100644
--- a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs
+++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs
@@ -7,6 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using ProjectBulldozer.Drawnings;
namespace ProjectBulldozer
{
@@ -15,7 +16,7 @@ namespace ProjectBulldozer
///
/// Поле-объект для прорисовки объекта
///
- private DrawningBulldozer? _drawningBulldozer;
+ private DrawningBulldozerProstoy? _drawningBulldozerProstoy;
///
/// Конструктор формы
///
@@ -28,34 +29,61 @@ namespace ProjectBulldozer
///
private void Draw()
{
- if (_drawningBulldozer == null)
+ if (_drawningBulldozerProstoy == null)
{
return;
}
Bitmap bmp = new(pictureBoxBulldozer.Width,
pictureBoxBulldozer.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawningBulldozer.DrawTransport(gr);
+ _drawningBulldozerProstoy.DrawTransport(gr);
pictureBoxBulldozer.Image = bmp;
}
+
///
- /// Обработка нажатия кнопки "Создать"
+ /// создеание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ Random random = new();
+ switch (type)
+ {
+ case nameof(DrawningBulldozerProstoy):
+ _drawningBulldozerProstoy = new DrawningBulldozerProstoy(random.Next(100, 300),random.Next(1000, 3000),
+ Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
+ break;
+ case nameof(DrawningBulldozer):
+ _drawningBulldozerProstoy = new DrawningBulldozer(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)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+
+ _drawningBulldozerProstoy.SetPictureSize(pictureBoxBulldozer.Width,pictureBoxBulldozer.Height);
+ _drawningBulldozerProstoy.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ Draw();
+ }
+
+
+ ///
+ /// Обработка нажатия кнопки "Создать бульдозер с доп."
///
///
///
- private void ButtonCreateBulldozer_Click(object sender, EventArgs e)
- {
- Random random = new();
- _drawningBulldozer = new DrawningBulldozer();
-
- _drawningBulldozer.Init(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)));
- _drawningBulldozer.SetPictureSize(pictureBoxBulldozer.Width, pictureBoxBulldozer.Height);
- _drawningBulldozer.SetPosition(random.Next(10, 100), random.Next(10, 100));
- Draw();
- }
+ private void ButtonCreateBulldozer_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBulldozer));
+
+ ///
+ /// Обработка нажатия кнопки "Создать обычный бульдозер"
+ ///
+ ///
+ ///
+ private void buttonCreateBulldozerProstoy_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBulldozerProstoy));
+
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
///
@@ -63,7 +91,7 @@ namespace ProjectBulldozer
///
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_drawningBulldozer == null)
+ if (_drawningBulldozerProstoy == null)
{
return;
}
@@ -73,19 +101,19 @@ namespace ProjectBulldozer
{
case "buttonUp":
result =
- _drawningBulldozer.MoveTransport(DirectionType1.Up);
+ _drawningBulldozerProstoy.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
result =
- _drawningBulldozer.MoveTransport(DirectionType1.Down);
+ _drawningBulldozerProstoy.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
result =
- _drawningBulldozer.MoveTransport(DirectionType1.Left);
+ _drawningBulldozerProstoy.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
result =
- _drawningBulldozer.MoveTransport(DirectionType1.Right);
+ _drawningBulldozerProstoy.MoveTransport(DirectionType.Right);
break;
}
if (result)
@@ -94,6 +122,6 @@ namespace ProjectBulldozer
}
}
-
+
}
}
From 065c718be88a8c7f09f8f7156532e9de349d1e4a Mon Sep 17 00:00:00 2001
From: mara-1 <147929076+mara-1@users.noreply.github.com>
Date: Tue, 12 Mar 2024 18:33:09 +0400
Subject: [PATCH 2/2] =?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=81=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3?=
=?UTF-8?q?=D0=B8=D0=B8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs | 1 -
1 file changed, 1 deletion(-)
diff --git a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs
index 5aa2a3d..f2caaea 100644
--- a/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs
+++ b/ProjectBulldozer/ProjectBulldozer/FormBulldozer.cs
@@ -7,7 +7,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
-using ProjectBulldozer.Drawnings;
namespace ProjectBulldozer
{