diff --git a/WinFormsApp1.sln b/BoykoSolution.sln
similarity index 85%
rename from WinFormsApp1.sln
rename to BoykoSolution.sln
index 2ff6889..41ea15c 100644
--- a/WinFormsApp1.sln
+++ b/BoykoSolution.sln
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34607.119
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lab1", "Lab1\Lab1.csproj", "{5FE81003-1286-435E-8F6F-C2D1ADCA4B2C}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProjectElectroTrans", "ProjectElectroTrans\ProjectElectroTrans.csproj", "{5FE81003-1286-435E-8F6F-C2D1ADCA4B2C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/Lab1/Config.cs b/Lab1/Config.cs
deleted file mode 100644
index 959c995..0000000
--- a/Lab1/Config.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Numerics;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Lab1
-{
- internal class Config
- {
- public static Size screenSize = new Size(923, 597);
- }
-}
diff --git a/Lab1/DrawingElectroTrans.cs b/Lab1/DrawingElectroTrans.cs
deleted file mode 100644
index 1a1b5a0..0000000
--- a/Lab1/DrawingElectroTrans.cs
+++ /dev/null
@@ -1,244 +0,0 @@
-using System.Drawing;
-
-namespace Lab1;
-
-public class DrawingElectroTrans
-{
- ///
- /// Класс-сущность
- ///
- public EntityElectroTrans? EntityElectroTrans { get; private set; }
-
- ///
- /// Ширина окна
- ///
- private int? _pictureWidth;
-
- ///
- /// Высота окна
- ///
- private int? _pictureHeight;
-
- ///
- /// Левая координата прорисовки автомобиля
- ///
- private int? _startPosX;
-
- ///
- /// Верхняя кооридната прорисовки автомобиля
- ///
- private int? _startPosY;
-
- ///
- /// Ширина прорисовки автомобиля
- ///
- private readonly int _drawningTransWidth = 80;
-
- ///
- /// Высота прорисовки автомобиля
- ///
- private readonly int _drawningTransHeight = 60;
-
- ///
- /// Инициализация свойств
- ///
- /// Скорость
- /// Вес автомобиля
- /// Основной цвет
- /// Дополнительный цвет
- /// Признак активности усов
- /// Признак колличества колес
- /// Признак наличия бптпрей
-
- public void Init(int speed, double weight, Color bodyColor, Color
- additionalColor, bool horns, int wheels, bool battery)
- {
- EntityElectroTrans = new EntityElectroTrans();
- EntityElectroTrans.Init(speed, weight, bodyColor, additionalColor, horns, wheels, battery);
- _pictureWidth = null;
- _pictureHeight = null;
- _startPosX = null;
- _startPosY = null;
- }
- ///
- /// Установка границ поля
- ///
- /// Ширина поля
- /// Высота поля
- /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах
- public bool SetPictureSize(int width, int height)
- {
- if (width >= _drawningTransWidth || height >= _drawningTransWidth)
- {
- _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 = 0;
- }else if (x > _pictureWidth - _drawningTransWidth)
- {
- x = _pictureWidth.Value - _drawningTransWidth;
- }
-
- if (y < 0)
- {
- y = 0;
- }
- else if (y > _pictureHeight - _drawningTransHeight)
- {
- y = _pictureHeight.Value - _drawningTransHeight;
- }
-
- _startPosX = x;
- _startPosY = y;
- }
-
- ///
- /// Изменение направления перемещения
- ///
- /// Направление
- /// true - перемещене выполнено, false - перемещение невозможно
- public bool MoveTransport(DirectionType direction)
- {
- if (EntityElectroTrans == null || !_startPosX.HasValue ||
- !_startPosY.HasValue)
- {
- return false;
- }
- if (_startPosX.Value < 0 || _startPosY.Value < 0 || _startPosX > _pictureWidth - _drawningTransWidth || _startPosY > _pictureHeight - _drawningTransHeight)
- {
- return false;
- }
- switch (direction)
- {
- //влево
- case DirectionType.Left:
- if (_startPosX.Value - EntityElectroTrans.Step > 0)
- {
- _startPosX -= (int)EntityElectroTrans.Step;
- }
-
- return true;
- //вверх
- case DirectionType.Up:
- if (_startPosY.Value - EntityElectroTrans.Step > 0)
- {
- _startPosY -= (int)EntityElectroTrans.Step;
- }
-
- return true;
- // вправо
- case DirectionType.Right:
- if (_startPosX.Value + EntityElectroTrans.Step < _pictureWidth - _drawningTransWidth)
- {
- _startPosX += (int)EntityElectroTrans.Step;
- }
- return true;
- //вниз
- case DirectionType.Down:
- if (_startPosY.Value + EntityElectroTrans.Step < _pictureHeight - _drawningTransHeight)
- {
- _startPosY += (int)EntityElectroTrans.Step;
- }
-
- return true;
- default:
- return false;
- }
-
- }
- ///
- /// Прорисовка объекта
- ///
- ///
- public void DrawTransport(Graphics g)
- {
- if (EntityElectroTrans == null || !_startPosX.HasValue ||
- !_startPosY.HasValue)
- {
- return;
- }
- Pen pen = new(EntityElectroTrans.BodyColor);
- Pen additionalPen = new(EntityElectroTrans.AdditionalColor);
- Brush brush = new SolidBrush(EntityElectroTrans.BodyColor);
- Brush additionalBrush = new SolidBrush(EntityElectroTrans.AdditionalColor);
- int _centerPosX = _startPosX.Value + _drawningTransWidth / 2;
- int _centerPosY = _startPosY.Value + _drawningTransHeight / 2;
- g.DrawPolygon(pen, new Point[] {
- new Point(_centerPosX - 40, _centerPosY),
- new Point(_centerPosX - 30, _centerPosY - 20),
- new Point(_centerPosX + 30, _centerPosY - 20),
- new Point(_centerPosX + 40, _centerPosY),
- new Point(_centerPosX + 40, _centerPosY + 20),
- new Point(_centerPosX - 40, _centerPosY + 20),
- });
-
- for (int i = 0; i < EntityElectroTrans.Wheels; i++)
- {
- g.FillEllipse(additionalBrush, new Rectangle((_centerPosX - 40) + (70 / EntityElectroTrans.Wheels) * (i + 1) + -4, _centerPosY + 16, 8, 8));
- }
- g.FillPolygon(additionalBrush, new Point[] {
- new Point(_centerPosX - 38, _centerPosY),
- new Point(_centerPosX - 30, _centerPosY - 17),
- new Point(_centerPosX + 30, _centerPosY - 17),
- new Point(_centerPosX + 38, _centerPosY),
- });
-
- if (EntityElectroTrans.Horns)
- {
- g.DrawPolygon(additionalPen, new Point[] {
- new Point(_centerPosX, _centerPosY - 20),
- new Point(_centerPosX - 20, _centerPosY - 30),
- new Point(_centerPosX + 20, _centerPosY - 30),
-
- });
- }
- else
- {
- g.DrawPolygon(additionalPen, new Point[] {
- new Point(_centerPosX, _centerPosY - 20),
- new Point(_centerPosX - 20, _centerPosY - 23),
- new Point(_centerPosX + 20, _centerPosY - 23),
-
- });
- }
- if (EntityElectroTrans.Battery){
- g.FillPolygon(additionalBrush, new Point[] {
- new Point(_centerPosX - 15, _centerPosY + 2),
- new Point(_centerPosX - 15, _centerPosY + 6),
- new Point(_centerPosX - 18, _centerPosY + 6),
- new Point(_centerPosX - 18, _centerPosY + 10),
- new Point(_centerPosX - 15, _centerPosY + 10),
- new Point(_centerPosX - 15, _centerPosY + 16),
- new Point(_centerPosX + 18, _centerPosY + 16),
- new Point(_centerPosX + 18, _centerPosY + 2),
-
- });
- }
- }
-
-
-
-}
\ No newline at end of file
diff --git a/Lab1/EntityElectroTrans.cs b/Lab1/EntityElectroTrans.cs
deleted file mode 100644
index 2db3db1..0000000
--- a/Lab1/EntityElectroTrans.cs
+++ /dev/null
@@ -1,68 +0,0 @@
-using System.Drawing;
-
-namespace Lab1;
-
-public class EntityElectroTrans
-{
- ///
- /// Скорость
- ///
- 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 Horns { get; private set; }
-
- ///
- /// Признак (опция) кол-во колес
- ///
- public int Wheels { get; private set; }
-
- ///
- /// Признак (опция) налиция батерей
- ///
- public bool Battery { get; private set; }
-
- ///
- /// Шаг перемещения электропоезда
- ///
- public double Step => Speed * 100 / Weight; // lambda выражение
-
- ///
- /// Инициализация полей объекта-класса спортивного автомобиля
- ///
- /// Скорость
- /// Вес автомобиля
- /// Основной цвет
- /// Дополнительный цвет
- /// Признак активности усов
- /// Признак колличества колес
- /// Признак наличия батарей
- public void Init(int speed, double weight, Color bodyColor, Color
- additionalColor, bool horns, int wheels, bool battery)
- {
- Speed = speed;
- Weight = weight;
- BodyColor = bodyColor;
- AdditionalColor = additionalColor;
- Horns = horns;
- Wheels = wheels;
- Battery = battery;
- }
-}
\ No newline at end of file
diff --git a/Lab1/Form1.Designer.cs b/Lab1/Form1.Designer.cs
deleted file mode 100644
index 1dbfc1a..0000000
--- a/Lab1/Form1.Designer.cs
+++ /dev/null
@@ -1,134 +0,0 @@
-namespace Lab1
-{
- partial class Form1
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- pictureBoxSportCar = new PictureBox();
- buttonCreateSportCar = new Button();
- buttonLeft = new Button();
- buttonUp = new Button();
- buttonDown = new Button();
- buttonRight = new Button();
- ((System.ComponentModel.ISupportInitialize)pictureBoxSportCar).BeginInit();
- SuspendLayout();
- //
- // pictureBoxSportCar
- //
- pictureBoxSportCar.Dock = DockStyle.Fill;
- pictureBoxSportCar.Location = new Point(0, 0);
- pictureBoxSportCar.Name = "pictureBoxSportCar";
- pictureBoxSportCar.Size = Config.screenSize;
- pictureBoxSportCar.TabIndex = 0;
- pictureBoxSportCar.TabStop = false;
- //
- // buttonCreateSportCar
- //
- buttonCreateSportCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateSportCar.Location = new Point(12, 562);
- buttonCreateSportCar.Name = "buttonCreateSportCar";
- buttonCreateSportCar.Size = new Size(75, 23);
- buttonCreateSportCar.TabIndex = 1;
- buttonCreateSportCar.Text = "Create";
- buttonCreateSportCar.UseVisualStyleBackColor = true;
- buttonCreateSportCar.Click += ButtonCreateElectroTrans_Click;
- //
- // buttonLeft
- //
- buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
- buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
- buttonLeft.Location = new Point(787, 550);
- buttonLeft.Name = "buttonLeft";
- buttonLeft.Size = new Size(35, 35);
- buttonLeft.TabIndex = 2;
- buttonLeft.UseVisualStyleBackColor = true;
- buttonLeft.Click += ButtonMove_Click;
- //
- // buttonUp
- //
- buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonUp.BackgroundImage = Properties.Resources.arrowUp;
- buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
- buttonUp.Location = new Point(828, 509);
- buttonUp.Name = "buttonUp";
- buttonUp.Size = new Size(35, 35);
- buttonUp.TabIndex = 3;
- buttonUp.UseVisualStyleBackColor = true;
- buttonUp.Click += ButtonMove_Click;
- //
- // buttonDown
- //
- buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonDown.BackgroundImage = Properties.Resources.arrowDown;
- buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
- buttonDown.Location = new Point(828, 550);
- buttonDown.Name = "buttonDown";
- buttonDown.Size = new Size(35, 35);
- buttonDown.TabIndex = 4;
- buttonDown.UseVisualStyleBackColor = true;
- buttonDown.Click += ButtonMove_Click;
- //
- // buttonRight
- //
- buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
- buttonRight.BackgroundImage = Properties.Resources.arrowRight;
- buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
- buttonRight.Location = new Point(869, 550);
- buttonRight.Name = "buttonRight";
- buttonRight.Size = new Size(35, 35);
- buttonRight.TabIndex = 5;
- buttonRight.UseVisualStyleBackColor = true;
- buttonRight.Click += ButtonMove_Click;
- //
- // FormElectroTrans
- //
- AutoScaleDimensions = new SizeF(7F, 15F);
- AutoScaleMode = AutoScaleMode.Font;
- ClientSize = Config.screenSize;
- Controls.Add(buttonRight);
- Controls.Add(buttonDown);
- Controls.Add(buttonUp);
- Controls.Add(buttonLeft);
- Controls.Add(buttonCreateSportCar);
- Controls.Add(pictureBoxSportCar);
- Name = "FormElectroTrans";
- Text = "ElectroTrans";
- ((System.ComponentModel.ISupportInitialize)pictureBoxSportCar).EndInit();
- ResumeLayout(false);
- }
-
- #endregion
-
- private PictureBox pictureBoxSportCar;
- private Button buttonCreateSportCar;
- private Button buttonLeft;
- private Button buttonUp;
- private Button buttonDown;
- private Button buttonRight;
- }
-}
diff --git a/Lab1/Form1.cs b/Lab1/Form1.cs
deleted file mode 100644
index d701cf0..0000000
--- a/Lab1/Form1.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-namespace Lab1
-{
- public partial class Form1 : Form
- {
- ///
- /// -
- ///
- private DrawingElectroTrans _drawningElectroTrans;
-
- public Form1()
- {
- InitializeComponent();
- _drawningElectroTrans = new DrawingElectroTrans();
- }
-
- ///
- ///
- ///
- private void Draw()
- {
- if (_drawningElectroTrans == null)
- {
- return;
- }
-
- Bitmap bmp = new(pictureBoxSportCar.Width, pictureBoxSportCar.Height);
- Graphics gr = Graphics.FromImage(bmp);
- _drawningElectroTrans.DrawTransport(gr);
- pictureBoxSportCar.Image = bmp;
- }
- private void ButtonCreateElectroTrans_Click(object sender, EventArgs e)
- {
- Random random = new();
- _drawningElectroTrans.Init(random.Next(500, 1500), 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)), random.Next(3, 8), Convert.ToBoolean(random.Next(0, 2)));
- _drawningElectroTrans.SetPictureSize(pictureBoxSportCar.Size.Width, pictureBoxSportCar.Size.Height);
- _drawningElectroTrans.SetPosition(random.Next(0, 5), random.Next(0, 5));
- Draw();
- }
-
- ///
- /// ( )
- ///
- ///
- ///
- private void ButtonMove_Click(object sender, EventArgs e)
- {
- if (_drawningElectroTrans == null)
- {
- return;
- }
-
- string name = ((Button)sender)?.Name ?? string.Empty;
- bool result = false;
- switch (name)
- {
- case "buttonUp":
- result = _drawningElectroTrans.MoveTransport(DirectionType.Up);
- break;
- case "buttonDown":
- result = _drawningElectroTrans.MoveTransport(DirectionType.Down);
- break;
- case "buttonLeft":
- result = _drawningElectroTrans.MoveTransport(DirectionType.Left);
- break;
- case "buttonRight":
- result = _drawningElectroTrans.MoveTransport(DirectionType.Right);
- break;
- }
-
- if (result)
- {
- Draw();
- }
- }
- }
-}
diff --git a/ProjectElectroTrans/Drawnings/DirectionType.cs b/ProjectElectroTrans/Drawnings/DirectionType.cs
new file mode 100644
index 0000000..6e6c370
--- /dev/null
+++ b/ProjectElectroTrans/Drawnings/DirectionType.cs
@@ -0,0 +1,32 @@
+namespace ProjectSportCar.Drawnings;
+
+///
+/// Направление перемещения
+///
+public enum DirectionType
+{
+ ///
+ /// Неизвестное направление
+ ///
+ Unknow = -1,
+
+ ///
+ /// Вверх
+ ///
+ Up = 1,
+
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+
+ ///
+ /// Влево
+ ///
+ Left = 3,
+
+ ///
+ /// Вправо
+ ///
+ Right = 4
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/Drawnings/DrawingElectroTrans.cs b/ProjectElectroTrans/Drawnings/DrawingElectroTrans.cs
new file mode 100644
index 0000000..44f206c
--- /dev/null
+++ b/ProjectElectroTrans/Drawnings/DrawingElectroTrans.cs
@@ -0,0 +1,71 @@
+using ProjectElectroTrans.Entities;
+
+namespace ProjectElectroTrans.Drawnings;
+
+///
+/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
+///
+public class DrawingElectroTrans : DrawingTrans
+{
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Признак наличия обвеса
+ /// Признак наличия антикрыла
+ /// Признак наличия гоночной полосы
+ public DrawingElectroTrans(int speed, double weight, Color bodyColor, Color
+ additionalColor, bool horns, bool battery) : base(110, 60)
+ {
+ EntityTrans = new EntityElectroTrans(speed, weight, bodyColor, additionalColor, horns, battery);
+ }
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityTrans == null || EntityTrans is not EntityElectroTrans electroTrans ||
+ !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ Pen pen = new(electroTrans.BodyColor);
+ Brush additionalBrush= new SolidBrush(electroTrans.AdditionalColor);
+
+ base.DrawTransport(g);
+
+ if (electroTrans.Horns)
+ {
+ g.DrawPolygon(pen, new Point[] {
+ new Point(_startPosX.Value + 40, _startPosY.Value + 10),
+ new Point(_startPosX.Value + 20, _startPosY.Value),
+ new Point(_startPosX.Value + 60, _startPosY.Value),
+
+ });
+ }
+ else
+ {
+ g.DrawPolygon(pen, new Point[] {
+ new Point(_startPosX.Value + 40, _startPosY.Value + 7),
+ new Point(_startPosX.Value + 20, _startPosY.Value + 7),
+ new Point(_startPosX.Value + 60, _startPosY.Value + 7),
+
+ });
+ }
+ if (electroTrans.Battery)
+ {
+ g.FillPolygon(additionalBrush, new Point[] {
+ new Point(_startPosX.Value + 25, _startPosY.Value + 32),
+ new Point(_startPosX.Value + 25, _startPosY.Value + 36),
+ new Point(_startPosX.Value + 22, _startPosY.Value + 36),
+ new Point(_startPosX.Value + 22, _startPosY.Value + 40),
+ new Point(_startPosX.Value + 25, _startPosY.Value + 40),
+ new Point(_startPosX.Value + 25, _startPosY.Value + 46),
+ new Point(_startPosX.Value + 58, _startPosY.Value + 46),
+ new Point(_startPosX.Value + 58, _startPosY.Value + 32),
+
+ });
+ }
+ }
+}
diff --git a/ProjectElectroTrans/Drawnings/DrawingTrans.cs b/ProjectElectroTrans/Drawnings/DrawingTrans.cs
new file mode 100644
index 0000000..59270e8
--- /dev/null
+++ b/ProjectElectroTrans/Drawnings/DrawingTrans.cs
@@ -0,0 +1,226 @@
+using ProjectElectroTrans.Entities;
+using ProjectSportCar.Drawnings;
+
+namespace ProjectElectroTrans.Drawnings;
+
+public class DrawingTrans
+{
+ ///
+ /// Класс-сущность
+ ///
+ public EntityTrans? EntityTrans { get; protected set; }
+
+ ///
+ /// Ширина окна
+ ///
+ private int? _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ private int? _pictureHeight;
+
+ ///
+ /// Левая координата прорисовки автомобиля
+ ///
+ protected int? _startPosX;
+
+ ///
+ /// Верхняя кооридната прорисовки автомобиля
+ ///
+ protected int? _startPosY;
+
+ ///
+ /// Ширина прорисовки автомобиля
+ ///
+ private readonly int _drawningTransWidth = 80;
+
+ ///
+ /// Высота прорисовки автомобиля
+ ///
+ private readonly int _drawningTransHeight = 60;
+ ///
+ /// Координата X объекта
+ ///
+ public int? GetPosX => _startPosX;
+ ///
+ /// Координата Y объекта
+ ///
+ public int? GetPosY => _startPosY;
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _drawningTransWidth;
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _drawningTransHeight;
+
+ ///
+ /// Пустой конструктор
+ ///
+ private DrawingTrans()
+ {
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+ }
+
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ public DrawingTrans(int speed, double weight, Color bodyColor) : this()
+ {
+ EntityTrans = new EntityTrans(speed, weight, bodyColor);
+ }
+ ///
+ /// Конструктор для наследников
+ ///
+ /// Ширина прорисовки автомобиля
+ /// Высота прорисовки автомобиля
+ protected DrawingTrans(int drawningCarWidth, int drawningCarHeight) : this()
+ {
+ _drawningTransWidth = drawningCarWidth;
+ _pictureHeight = drawningCarHeight;
+ }
+
+ ///
+ /// Установка границ поля
+ ///
+ /// Ширина поля
+ /// Высота поля
+ /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах
+ public bool SetPictureSize(int width, int height)
+ {
+ if (width >= _drawningTransWidth || height >= _drawningTransWidth)
+ {
+ _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 = 0;
+ }
+ else if (x > _pictureWidth - _drawningTransWidth)
+ {
+ x = _pictureWidth.Value - _drawningTransWidth;
+ }
+
+ if (y < 0)
+ {
+ y = 0;
+ }
+ else if (y > _pictureHeight - _drawningTransHeight)
+ {
+ y = _pictureHeight.Value - _drawningTransHeight;
+ }
+ _startPosX = x;
+ _startPosY = y;
+ }
+ ///
+ /// Изменение направления перемещения
+ ///
+ /// Направление
+ /// true - перемещене выполнено, false - перемещениеневозможно
+ public bool MoveTransport(DirectionType direction)
+ {
+ if (EntityTrans == null || !_startPosX.HasValue ||
+ !_startPosY.HasValue)
+ {
+ return false;
+ }
+ switch (direction)
+ {
+ //влево
+ case DirectionType.Left:
+ if (_startPosX.Value - EntityTrans.Step > 0)
+ {
+ _startPosX -= (int)EntityTrans.Step;
+ }
+ return true;
+ //вверх
+ case DirectionType.Up:
+ if (_startPosY.Value - EntityTrans.Step > 0)
+ {
+ _startPosY -= (int)EntityTrans.Step;
+ }
+ return true;
+ // вправо
+ case DirectionType.Right:
+ if (_startPosX.Value + EntityTrans.Step < _pictureWidth - _drawningTransWidth)
+ {
+ _startPosX += (int)EntityTrans.Step;
+ }
+ return true;
+ //вниз
+ case DirectionType.Down:
+ if (_startPosY.Value + EntityTrans.Step < _pictureHeight - _drawningTransHeight)
+ {
+ _startPosY += (int)EntityTrans.Step;
+ }
+ return true;
+ default:
+ return false;
+ }
+ }
+ ///
+ /// Прорисовка объекта
+ ///
+ ///
+ public virtual void DrawTransport(Graphics g)
+ {
+ if (EntityTrans == null || !_startPosX.HasValue ||
+ !_startPosY.HasValue)
+ {
+ return;
+ }
+ Pen pen = new(EntityTrans.BodyColor);
+
+
+ // Тело
+
+ g.DrawPolygon(pen, new Point[] {
+ new Point(_startPosX.Value, _startPosY.Value + 30),
+ new Point(_startPosX.Value + 10, _startPosY.Value + 10),
+ new Point(_startPosX.Value + 70, _startPosY.Value + 10),
+ new Point(_startPosX.Value + 80, _startPosY.Value + 30),
+ new Point(_startPosX.Value + 80, _startPosY.Value + 50),
+ new Point(_startPosX.Value, _startPosY.Value + 50),
+ });
+ // Колеса
+ for (int i = 0; i < 4; i++)
+ {
+ g.DrawEllipse(pen, new Rectangle((_startPosX.Value) + (70 / 4) * (i + 1) + -4, _startPosY.Value + 46, 8, 8));
+ }
+ // Стекла
+ g.DrawPolygon(pen, new Point[] {
+ new Point(_startPosX.Value + 2, _startPosY.Value + 30),
+ new Point(_startPosX.Value + 10, _startPosY.Value + 13),
+ new Point(_startPosX.Value + 70, _startPosY.Value + 13),
+ new Point(_startPosX.Value + 78, _startPosY.Value + 30),
+ });
+ }
+}
diff --git a/ProjectElectroTrans/Entities/EntityElectroTrans.cs b/ProjectElectroTrans/Entities/EntityElectroTrans.cs
new file mode 100644
index 0000000..8220a76
--- /dev/null
+++ b/ProjectElectroTrans/Entities/EntityElectroTrans.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectroTrans.Entities;
+
+internal class EntityElectroTrans : EntityTrans
+{
+ ///
+ /// Дополнительный цвет (для опциональных элементов)
+ ///
+ public Color AdditionalColor { get; private set; }
+
+ ///
+ /// Признак (опция) подняты ли рога
+ ///
+ public bool Horns { get; private set; }
+
+ ///
+ /// Признак (опция) налиция батерей
+ ///
+ public bool Battery { get; private set; }
+ ///
+ /// Конструктор сущности
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Основной цвет
+ /// /// Дополнительный цвет
+ /// Признак активности усов
+ /// Признак наличия батарей
+ public EntityElectroTrans(int speed, double weight, Color bodyColor, Color
+ additionalColor, bool horns, bool battery) : base(speed, weight, bodyColor)
+ {
+ AdditionalColor = additionalColor;
+ Horns = horns;
+ Battery = battery;
+ }
+}
diff --git a/ProjectElectroTrans/Entities/EntityTrans.cs b/ProjectElectroTrans/Entities/EntityTrans.cs
new file mode 100644
index 0000000..86825b7
--- /dev/null
+++ b/ProjectElectroTrans/Entities/EntityTrans.cs
@@ -0,0 +1,37 @@
+namespace ProjectElectroTrans.Entities;
+
+///
+/// Класс-сущность "Поезд"
+///
+public class EntityTrans
+{
+ ///
+ /// Скорость
+ ///
+ 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 EntityTrans(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+
+}
diff --git a/ProjectElectroTrans/FormElectroTrans.Designer.cs b/ProjectElectroTrans/FormElectroTrans.Designer.cs
new file mode 100644
index 0000000..c605eaa
--- /dev/null
+++ b/ProjectElectroTrans/FormElectroTrans.Designer.cs
@@ -0,0 +1,178 @@
+using static System.Net.Mime.MediaTypeNames;
+using System.Windows.Forms;
+using System.Xml.Linq;
+
+namespace ProjectElectroTrans
+{
+ partial class FormElectroTrans
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ pictureBoxElectroTrans = new PictureBox();
+ buttonCreateElectroTrans = new Button();
+ buttonLeft = new Button();
+ buttonUp = new Button();
+ buttonDown = new Button();
+ buttonRight = new Button();
+ buttonCreateCar = new Button();
+ comboBoxStrategy = new ComboBox();
+ buttonStrategyStep = new Button();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxElectroTrans).BeginInit();
+ SuspendLayout();
+ //
+ // pictureBoxElectroTrans
+ //
+ pictureBoxElectroTrans.Dock = DockStyle.Fill;
+ pictureBoxElectroTrans.Location = new Point(0, 0);
+ pictureBoxElectroTrans.Name = "pictureBoxElectroTrans";
+ pictureBoxElectroTrans.Size = new Size(923, 597);
+ pictureBoxElectroTrans.TabIndex = 0;
+ pictureBoxElectroTrans.TabStop = false;
+ //
+ // buttonCreateElectroTrans
+ //
+ buttonCreateElectroTrans.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateElectroTrans.Location = new Point(12, 562);
+ buttonCreateElectroTrans.Name = "buttonCreateElectroTrans";
+ buttonCreateElectroTrans.Size = new Size(223, 23);
+ buttonCreateElectroTrans.TabIndex = 1;
+ buttonCreateElectroTrans.Text = "Создать электропоезд";
+ buttonCreateElectroTrans.UseVisualStyleBackColor = true;
+ buttonCreateElectroTrans.Click += ButtonCreateElectroTrans_Click;
+ //
+ // buttonLeft
+ //
+ buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonLeft.BackgroundImage = Properties.Resources.arrowLeft;
+ buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonLeft.Location = new Point(787, 550);
+ buttonLeft.Name = "buttonLeft";
+ buttonLeft.Size = new Size(35, 35);
+ buttonLeft.TabIndex = 2;
+ buttonLeft.UseVisualStyleBackColor = true;
+ buttonLeft.Click += ButtonMove_Click;
+ //
+ // buttonUp
+ //
+ buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonUp.BackgroundImage = Properties.Resources.arrowUp;
+ buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonUp.Location = new Point(828, 509);
+ buttonUp.Name = "buttonUp";
+ buttonUp.Size = new Size(35, 35);
+ buttonUp.TabIndex = 3;
+ buttonUp.UseVisualStyleBackColor = true;
+ buttonUp.Click += ButtonMove_Click;
+ //
+ // buttonDown
+ //
+ buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonDown.BackgroundImage = Properties.Resources.arrowDown;
+ buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonDown.Location = new Point(828, 550);
+ buttonDown.Name = "buttonDown";
+ buttonDown.Size = new Size(35, 35);
+ buttonDown.TabIndex = 4;
+ buttonDown.UseVisualStyleBackColor = true;
+ buttonDown.Click += ButtonMove_Click;
+ //
+ // buttonRight
+ //
+ buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
+ buttonRight.BackgroundImage = Properties.Resources.arrowRight;
+ buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonRight.Location = new Point(869, 550);
+ buttonRight.Name = "buttonRight";
+ buttonRight.Size = new Size(35, 35);
+ buttonRight.TabIndex = 5;
+ buttonRight.UseVisualStyleBackColor = true;
+ buttonRight.Click += ButtonMove_Click;
+ //
+ // buttonCreateCar
+ //
+ buttonCreateCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreateCar.Location = new Point(250, 562);
+ buttonCreateCar.Name = "buttonCreateTrans";
+ buttonCreateCar.Size = new Size(223, 23);
+ buttonCreateCar.TabIndex = 6;
+ buttonCreateCar.Text = "Создать поезд";
+ buttonCreateCar.UseVisualStyleBackColor = true;
+ buttonCreateCar.Click += ButtonCreateTrans_Click;
+ //
+ // comboBoxStrategy
+ //
+ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxStrategy.FormattingEnabled = true;
+ comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
+ comboBoxStrategy.Location = new Point(790, 12);
+ comboBoxStrategy.Name = "comboBoxStrategy";
+ comboBoxStrategy.Size = new Size(121, 23);
+ comboBoxStrategy.TabIndex = 7;
+ //
+ // buttonStrategyStep
+ //
+ buttonStrategyStep.Location = new Point(836, 41);
+ buttonStrategyStep.Name = "buttonStrategyStep";
+ buttonStrategyStep.Size = new Size(75, 23);
+ buttonStrategyStep.TabIndex = 8;
+ buttonStrategyStep.Text = "Шаг";
+ buttonStrategyStep.UseVisualStyleBackColor = true;
+ buttonStrategyStep.Click += ButtonStrategyStep_Click;
+ //
+ // FormElectroTrans
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(923, 597);
+ Controls.Add(buttonStrategyStep);
+ Controls.Add(comboBoxStrategy);
+ Controls.Add(buttonCreateCar);
+ Controls.Add(buttonRight);
+ Controls.Add(buttonDown);
+ Controls.Add(buttonUp);
+ Controls.Add(buttonLeft);
+ Controls.Add(buttonCreateElectroTrans);
+ Controls.Add(pictureBoxElectroTrans);
+ Name = "FormElectroTrans";
+ Text = "Электропоезд";
+ ((System.ComponentModel.ISupportInitialize)pictureBoxElectroTrans).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxElectroTrans;
+ private Button buttonCreateElectroTrans;
+ private Button buttonLeft;
+ private Button buttonUp;
+ private Button buttonDown;
+ private Button buttonRight;
+ private Button buttonCreateCar;
+ private ComboBox comboBoxStrategy;
+ private Button buttonStrategyStep;
+ }
+}
diff --git a/ProjectElectroTrans/FormElectroTrans.cs b/ProjectElectroTrans/FormElectroTrans.cs
new file mode 100644
index 0000000..0b486b8
--- /dev/null
+++ b/ProjectElectroTrans/FormElectroTrans.cs
@@ -0,0 +1,156 @@
+using ProjectElectroTrans.Drawnings;
+using ProjectElectroTrans.MovementStrategy;
+using ProjectSportCar.Drawnings;
+using ProjectSportCar.MovementStrategy;
+
+namespace ProjectElectroTrans;
+
+public partial class FormElectroTrans : Form
+{
+ ///
+ /// -
+ ///
+ private DrawingTrans? _drawingTrans;
+
+ ///
+ ///
+ ///
+ private AbstractStrategy? _strategy;
+
+ public FormElectroTrans()
+ {
+ InitializeComponent();
+ _strategy = null;
+ }
+
+ ///
+ ///
+ ///
+ private void Draw()
+ {
+ if (_drawingTrans == null)
+ {
+ return;
+ }
+
+ Bitmap bmp = new(pictureBoxElectroTrans.Width, pictureBoxElectroTrans.Height);
+ Graphics gr = Graphics.FromImage(bmp);
+ _drawingTrans.DrawTransport(gr);
+ pictureBoxElectroTrans.Image = bmp;
+ }
+ private void CreateObject(string type)
+ {
+ Random random = new();
+ switch (type)
+ {
+ case nameof(DrawingTrans):
+ _drawingTrans = new DrawingTrans(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(DrawingElectroTrans):
+ _drawingTrans = new DrawingElectroTrans(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)));
+ break;
+ default:
+ return;
+ }
+
+ _drawingTrans.SetPictureSize(pictureBoxElectroTrans.Width, pictureBoxElectroTrans.Height);
+ _drawingTrans.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ _strategy = null;
+ comboBoxStrategy.Enabled = true;
+ Draw();
+ }
+ ///
+ /// " "
+ ///
+ ///
+ ///
+ private void ButtonCreateElectroTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingElectroTrans));
+
+ ///
+ /// " "
+ ///
+ ///
+ ///
+ private void ButtonCreateTrans_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingTrans));
+ ///
+ /// ( )
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_drawingTrans == null)
+ {
+ return;
+ }
+
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ bool result = false;
+ switch (name)
+ {
+ case "buttonUp":
+ result = _drawingTrans.MoveTransport(DirectionType.Up);
+ break;
+ case "buttonDown":
+ result = _drawingTrans.MoveTransport(DirectionType.Down);
+ break;
+ case "buttonLeft":
+ result = _drawingTrans.MoveTransport(DirectionType.Left);
+ break;
+ case "buttonRight":
+ result = _drawingTrans.MoveTransport(DirectionType.Right);
+ break;
+ }
+
+ if (result)
+ {
+ Draw();
+ }
+ }
+ ///
+ /// ""
+ ///
+ ///
+ ///
+ private void ButtonStrategyStep_Click(object sender, EventArgs e)
+ {
+ if (_drawingTrans == null)
+ {
+ return;
+ }
+
+ if (comboBoxStrategy.Enabled)
+ {
+ _strategy = comboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_strategy == null)
+ {
+ return;
+ }
+ _strategy.SetData(new MoveableTrans(_drawingTrans), pictureBoxElectroTrans.Width, pictureBoxElectroTrans.Height);
+ }
+
+ if (_strategy == null)
+ {
+ return;
+ }
+
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+
+ if (_strategy.GetStatus() == StrategyStatus.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+ }
+}
diff --git a/Lab1/Form1.resx b/ProjectElectroTrans/FormElectroTrans.resx
similarity index 100%
rename from Lab1/Form1.resx
rename to ProjectElectroTrans/FormElectroTrans.resx
diff --git a/ProjectElectroTrans/MovementStrategy/AbstractStrategy.cs b/ProjectElectroTrans/MovementStrategy/AbstractStrategy.cs
new file mode 100644
index 0000000..becddea
--- /dev/null
+++ b/ProjectElectroTrans/MovementStrategy/AbstractStrategy.cs
@@ -0,0 +1,123 @@
+
+namespace ProjectElectroTrans.MovementStrategy;
+
+
+///
+/// Класс-стратегия перемещения объекта
+///
+public abstract class AbstractStrategy
+{
+ ///
+ /// Перемещаемый объект
+ ///
+ private IMoveableObject? _moveableObject;
+ ///
+ /// Статус перемещения
+ ///
+ private StrategyStatus _state = StrategyStatus.NotInit;
+ ///
+ /// Ширина поля
+ ///
+ protected int FieldWidth { get; private set; }
+ ///
+ /// Высота поля
+ ///
+ protected int FieldHeight { get; private set; }
+ ///
+ /// Статус перемещения
+ ///
+ public StrategyStatus GetStatus() { return _state; }
+ ///
+ /// Установка данных
+ ///
+ /// Перемещаемый объект
+ /// Ширина поля
+ /// Высота поля
+ public void SetData(IMoveableObject moveableObject, int width, int height)
+ {
+ if (moveableObject == null)
+ {
+ _state = StrategyStatus.NotInit;
+ return;
+ }
+ _state = StrategyStatus.InProgress;
+ _moveableObject = moveableObject;
+ FieldWidth = width;
+ FieldHeight = height;
+ }
+ ///
+ /// Шаг перемещения
+ ///
+ public void MakeStep()
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return;
+ }
+ if (IsTargetDestinaion())
+ {
+ _state = StrategyStatus.Finish;
+ return;
+ }
+ MoveToTarget();
+ }
+ ///
+ /// Перемещение влево
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveLeft() => MoveTo(MovementDirection.Left);
+ ///
+ /// Перемещение вправо
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveRight() => MoveTo(MovementDirection.Right);
+ ///
+ /// Перемещение вверх
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveUp() => MoveTo(MovementDirection.Up);
+ ///
+ /// Перемещение вниз
+ ///
+ /// Результат перемещения (true - удалось переместиться, false - неудача)
+ protected bool MoveDown() => MoveTo(MovementDirection.Down);
+ ///
+ /// Параметры объекта
+ ///
+ protected ObjectParameters? GetObjectParameters =>
+ _moveableObject?.GetObjectPosition;
+ ///
+ /// Шаг объекта
+ ///
+ ///
+ protected int? GetStep()
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return null;
+ }
+ return _moveableObject?.GetStep;
+ }
+ ///
+ /// Перемещение к цели
+ ///
+ protected abstract void MoveToTarget();
+ ///
+ /// Достигнута ли цель
+ ///
+ ///
+ protected abstract bool IsTargetDestinaion();
+ ///
+ /// Попытка перемещения в требуемом направлении
+ ///
+ /// Направление
+ /// Результат попытки (true - удалось переместиться, false - неудача)
+ private bool MoveTo(MovementDirection movementDirection)
+ {
+ if (_state != StrategyStatus.InProgress)
+ {
+ return false;
+ }
+ return _moveableObject?.TryMoveObject(movementDirection) ?? false;
+ }
+}
diff --git a/ProjectElectroTrans/MovementStrategy/IMoveableObject.cs b/ProjectElectroTrans/MovementStrategy/IMoveableObject.cs
new file mode 100644
index 0000000..9ec739e
--- /dev/null
+++ b/ProjectElectroTrans/MovementStrategy/IMoveableObject.cs
@@ -0,0 +1,22 @@
+
+
+namespace ProjectElectroTrans.MovementStrategy;
+
+public interface IMoveableObject
+{
+ ///
+ /// Получение координаты объекта
+ ///
+ ObjectParameters? GetObjectPosition { get; }
+ ///
+ /// Шаг объекта
+ ///
+ int GetStep { get; }
+ ///
+ /// Попытка переместить объект в указанном направлении
+ ///
+ /// Направление
+ /// true - объект перемещен, false - перемещение невозможно
+bool TryMoveObject(MovementDirection direction);
+}
+
diff --git a/ProjectElectroTrans/MovementStrategy/MoveToBorder.cs b/ProjectElectroTrans/MovementStrategy/MoveToBorder.cs
new file mode 100644
index 0000000..f4581b7
--- /dev/null
+++ b/ProjectElectroTrans/MovementStrategy/MoveToBorder.cs
@@ -0,0 +1,52 @@
+using ProjectElectroTrans.MovementStrategy;
+
+namespace ProjectSportCar.MovementStrategy;
+
+public class MoveToBorder : AbstractStrategy
+{
+ protected override bool IsTargetDestinaion()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth
+ && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth &&
+ objParams.ObjectMiddleVertical - GetStep() <= FieldHeight
+ && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight;
+ }
+
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ int diffX = objParams.ObjectMiddleHorizontal - FieldWidth;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+ int diffY = objParams.ObjectMiddleVertical - FieldHeight;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectElectroTrans/MovementStrategy/MoveToCenter.cs b/ProjectElectroTrans/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..b228615
--- /dev/null
+++ b/ProjectElectroTrans/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,50 @@
+
+namespace ProjectElectroTrans.MovementStrategy;
+
+public class MoveToCenter : AbstractStrategy
+{
+ protected override bool IsTargetDestinaion()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2
+ && objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
+ objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
+ && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
+ }
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+ int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+}
diff --git a/ProjectElectroTrans/MovementStrategy/MoveableTrans.cs b/ProjectElectroTrans/MovementStrategy/MoveableTrans.cs
new file mode 100644
index 0000000..965fda9
--- /dev/null
+++ b/ProjectElectroTrans/MovementStrategy/MoveableTrans.cs
@@ -0,0 +1,61 @@
+using ProjectElectroTrans.Drawnings;
+using ProjectSportCar.Drawnings;
+
+
+namespace ProjectElectroTrans.MovementStrategy;
+public class MoveableTrans : IMoveableObject
+{
+ ///
+ /// Поле-объект класса DrawningTrans или его наследника
+ ///
+ private readonly DrawingTrans? _trans = null;
+ ///
+ /// Конструктор
+ ///
+ /// Объект класса DrawningTrans
+ public MoveableTrans(DrawingTrans trans)
+ {
+ _trans = trans;
+ }
+
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_trans == null || _trans.EntityTrans == null ||
+ !_trans.GetPosX.HasValue || !_trans.GetPosY.HasValue)
+ {
+ return null;
+ }
+ return new ObjectParameters(_trans.GetPosX.Value,
+ _trans.GetPosY.Value, _trans.GetWidth, _trans.GetHeight);
+ }
+ }
+ public int GetStep => (int)(_trans?.EntityTrans?.Step ?? 0);
+ public bool TryMoveObject(MovementDirection direction)
+ {
+ if (_trans == null || _trans.EntityTrans == null)
+ {
+ return false;
+ }
+ return _trans.MoveTransport(GetDirectionType(direction));
+ }
+ ///
+ /// Конвертация из MovementDirection в DirectionType
+ ///
+ /// MovementDirection
+ /// DirectionType
+ private static DirectionType GetDirectionType(MovementDirection direction)
+ {
+ return direction switch
+ {
+ MovementDirection.Left => DirectionType.Left,
+ MovementDirection.Right => DirectionType.Right,
+ MovementDirection.Up => DirectionType.Up,
+ MovementDirection.Down => DirectionType.Down,
+ _ => DirectionType.Unknow,
+ };
+ }
+
+
+}
diff --git a/Lab1/DirectionType.cs b/ProjectElectroTrans/MovementStrategy/MovementDirection.cs
similarity index 77%
rename from Lab1/DirectionType.cs
rename to ProjectElectroTrans/MovementStrategy/MovementDirection.cs
index b2c0f37..86b1159 100644
--- a/Lab1/DirectionType.cs
+++ b/ProjectElectroTrans/MovementStrategy/MovementDirection.cs
@@ -1,6 +1,6 @@
-namespace Lab1;
+namespace ProjectElectroTrans.MovementStrategy;
-public enum DirectionType
+public enum MovementDirection
{
///
/// Вверх
@@ -18,5 +18,4 @@ public enum DirectionType
/// Вправо
///
Right = 4
-
-}
\ No newline at end of file
+}
diff --git a/ProjectElectroTrans/MovementStrategy/ObjectParameters.cs b/ProjectElectroTrans/MovementStrategy/ObjectParameters.cs
new file mode 100644
index 0000000..92df948
--- /dev/null
+++ b/ProjectElectroTrans/MovementStrategy/ObjectParameters.cs
@@ -0,0 +1,60 @@
+namespace ProjectElectroTrans.MovementStrategy;
+
+public class ObjectParameters
+{
+ ///
+ /// Координата X
+ ///
+ private readonly int _x;
+ ///
+ /// Координата Y
+ ///
+ private readonly int _y;
+ ///
+ /// Ширина объекта
+ ///
+ private readonly int _width;
+ ///
+ /// Высота объекта
+ ///
+ private readonly int _height;
+ ///
+ /// Левая граница
+ ///
+ public int LeftBorder => _x;
+ ///
+ /// Верхняя граница
+ ///
+ public int TopBorder => _y;
+ ///
+ /// Правая граница
+ ///
+ public int RightBorder => _x + _width;
+ ///
+ /// Нижняя граница
+ ///
+ public int DownBorder => _y + _height;
+ ///
+ /// Середина объекта
+ ///
+ public int ObjectMiddleHorizontal => _x + _width / 2;
+ ///
+ /// Середина объекта
+ ///
+ public int ObjectMiddleVertical => _y + _height / 2;
+ ///
+ /// Конструктор
+ ///
+ /// Координата X
+ /// Координата Y
+ /// Ширина объекта
+ /// Высота объекта
+ public ObjectParameters(int x, int y, int width, int height)
+ {
+ _x = x;
+ _y = y;
+ _width = width;
+ _height = height;
+ }
+
+}
diff --git a/ProjectElectroTrans/MovementStrategy/StrategyStatus.cs b/ProjectElectroTrans/MovementStrategy/StrategyStatus.cs
new file mode 100644
index 0000000..0dadbec
--- /dev/null
+++ b/ProjectElectroTrans/MovementStrategy/StrategyStatus.cs
@@ -0,0 +1,17 @@
+namespace ProjectElectroTrans.MovementStrategy;
+
+public enum StrategyStatus
+{
+ ///
+ /// Все готово к началу
+ ///
+ NotInit,
+ ///
+ /// Выполняется
+ ///
+ InProgress,
+ ///
+ /// Завершено
+ ///
+ Finish
+}
diff --git a/Lab1/Program.cs b/ProjectElectroTrans/Program.cs
similarity index 83%
rename from Lab1/Program.cs
rename to ProjectElectroTrans/Program.cs
index 45c9ca1..d25ed3f 100644
--- a/Lab1/Program.cs
+++ b/ProjectElectroTrans/Program.cs
@@ -1,4 +1,4 @@
-namespace Lab1
+namespace ProjectElectroTrans
{
internal static class Program
{
@@ -11,7 +11,7 @@ namespace Lab1
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new Form1());
+ Application.Run(new FormElectroTrans());
}
}
}
\ No newline at end of file
diff --git a/Lab1/Lab1.csproj b/ProjectElectroTrans/ProjectElectroTrans.csproj
similarity index 100%
rename from Lab1/Lab1.csproj
rename to ProjectElectroTrans/ProjectElectroTrans.csproj
diff --git a/Lab1/Properties/Resources.Designer.cs b/ProjectElectroTrans/Properties/Resources.Designer.cs
similarity index 96%
rename from Lab1/Properties/Resources.Designer.cs
rename to ProjectElectroTrans/Properties/Resources.Designer.cs
index 775892f..13cc393 100644
--- a/Lab1/Properties/Resources.Designer.cs
+++ b/ProjectElectroTrans/Properties/Resources.Designer.cs
@@ -8,7 +8,7 @@
//
//------------------------------------------------------------------------------
-namespace Lab1.Properties {
+namespace ProjectElectroTrans.Properties {
using System;
@@ -39,7 +39,7 @@ namespace Lab1.Properties {
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
- global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Lab1.Properties.Resources", typeof(Resources).Assembly);
+ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectElectroTrans.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
diff --git a/Lab1/Properties/Resources.resx b/ProjectElectroTrans/Properties/Resources.resx
similarity index 100%
rename from Lab1/Properties/Resources.resx
rename to ProjectElectroTrans/Properties/Resources.resx
diff --git a/Lab1/Resources/arrowDown.jpg b/ProjectElectroTrans/Resources/arrowDown.jpg
similarity index 100%
rename from Lab1/Resources/arrowDown.jpg
rename to ProjectElectroTrans/Resources/arrowDown.jpg
diff --git a/Lab1/Resources/arrowLeft.jpg b/ProjectElectroTrans/Resources/arrowLeft.jpg
similarity index 100%
rename from Lab1/Resources/arrowLeft.jpg
rename to ProjectElectroTrans/Resources/arrowLeft.jpg
diff --git a/Lab1/Resources/arrowRight.jpg b/ProjectElectroTrans/Resources/arrowRight.jpg
similarity index 100%
rename from Lab1/Resources/arrowRight.jpg
rename to ProjectElectroTrans/Resources/arrowRight.jpg
diff --git a/Lab1/Resources/arrowUp.jpg b/ProjectElectroTrans/Resources/arrowUp.jpg
similarity index 100%
rename from Lab1/Resources/arrowUp.jpg
rename to ProjectElectroTrans/Resources/arrowUp.jpg