diff --git a/ProjectBomber/ProjectBomber/DrawningAirBomber.cs b/ProjectBomber/ProjectBomber/DrawningAirBomber.cs
deleted file mode 100644
index 224fcaf..0000000
--- a/ProjectBomber/ProjectBomber/DrawningAirBomber.cs
+++ /dev/null
@@ -1,211 +0,0 @@
-using ProjectAirBomber;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ProjectAirBomber;
-
-///
-///
-///
-public class DrawingAirBomber
-{
- ///
- /// класс-сущность
- ///
- public EntityAirBomber? EntityAirBomber { get; private set; }
-
- ///
- /// ширина окна
- ///
- private int? _pictureWight;
-
- ///
- /// высота окна
- ///
- private int? _pictureHight;
-
- ///
- /// левая координата прорисовки самолета
- ///
- private int? _startPosX;
-
- ///
- /// верхняя координата прорисовки самолета
- ///
- private int? _startPosY;
-
- ///
- /// ширина прорисовки самолета
- ///
- private readonly int _drawingPlaneWidth = 115;
-
- ///
- /// высота прорисовки самолета
- ///
- private readonly int _drawingPlaneHeight = 170;
-
- /// Скорость
- /// Вес автомобиля
- /// Основной цвет
- /// Дополнительный цвет
- /// наличие двигателя
- /// наличие двигателя
- public void Init(int speed, double weight, Color bodyColor, Color
- additionalColor, bool engine, bool bomb)
- {
- EntityAirBomber = new EntityAirBomber();
- EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, engine, bomb);
- _pictureWight = null;
- _pictureHight = null;
- _startPosX = null;
- _startPosY = null;
- }
-
- public bool SetPictureSize(int width, int height)
- {
- _pictureWight = width;
- _pictureHight = height;
- return true;
- }
-
- public void SetPosition(int x, int y)
- {
- if (!_pictureWight.HasValue || !_pictureHight.HasValue)
- {
- return;
- }
- _startPosX = x;
- _startPosY = y;
- }
-
- ///
- /// Изменение направления перемещения
- ///
- /// Направление
- /// true - перемещене выполнено, false - перемещение невозможно
- public bool MoveTransport(DirectionType direction)
- {
- if (EntityAirBomber == null || !_startPosX.HasValue || !_startPosY.HasValue)
- {
- return false;
- }
-
- switch (direction)
- {
- //влево
- case DirectionType.Left:
- if (_startPosX.Value - EntityAirBomber.Step > 0)
- {
- _startPosX -= (int)EntityAirBomber.Step;
- }
- return true;
- //вверх
- case DirectionType.Up:
- if (_startPosY.Value - EntityAirBomber.Step > 0)
- {
- _startPosY -= (int)EntityAirBomber.Step;
- }
- return true;
- // вправо
- case DirectionType.Right:
- if (_startPosX.Value + _drawingPlaneWidth < _pictureWight)
- _startPosX += (int)EntityAirBomber.Step;
- return true;
- //вниз
- case DirectionType.Down:
- if (_startPosY.Value + _drawingPlaneHeight < _pictureHight)
- _startPosY += (int)EntityAirBomber.Step;
- return true;
- default:
- return false;
- }
- }
-
- ///
- /// Прорисовка объекта
- ///
- ///
- ///
- public void DrawAirBomber(Graphics g)
- {
- if (EntityAirBomber == null || !_startPosX.HasValue || !_startPosY.HasValue)
- {
- return;
- }
-
- Pen pen = new(Color.Black);
-
- //главная часть
- Brush br = new SolidBrush(EntityAirBomber.BodyColor);
- g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 50, 100, 30);
- g.FillRectangle(br, _startPosX.Value + 10, _startPosY.Value + 50, 100, 30);
-
- //носовая часть
- Brush brBlack = new SolidBrush(Color.Black);
- Point point1 = new Point(_startPosX.Value - 15, _startPosY.Value + 65);
- Point point2 = new Point(_startPosX.Value + 10, _startPosY.Value + 80);
- Point point3 = new Point(_startPosX.Value + 10, _startPosY.Value + 50);
- Point[] curvePointsNos = { point1, point2, point3 };
- g.DrawPolygon(pen, curvePointsNos);
- g.FillPolygon(brBlack, curvePointsNos);
-
- //верхнее левое крыло
- Point point4 = new Point(_startPosX.Value + 60, _startPosY.Value);
- Point point5 = new Point(_startPosX.Value + 60, _startPosY.Value + 50);
- Point point6 = new Point(_startPosX.Value + 75, _startPosY.Value + 50);
- Point point7 = new Point(_startPosX.Value + 65, _startPosY.Value);
- Point[] Wings1 = { point4, point5, point6, point7 };
- g.DrawPolygon(pen, Wings1);
- g.FillPolygon(br, Wings1);
-
- //нижнее левое крыло
- Point point8 = new Point(_startPosX.Value + 60, _startPosY.Value + 140);
- Point point9 = new Point(_startPosX.Value + 60, _startPosY.Value + 80);
- Point point10 = new Point(_startPosX.Value + 75, _startPosY.Value + 80);
- Point point11 = new Point(_startPosX.Value + 65, _startPosY.Value + 140);
- Point[] Wings2 = { point8, point9, point10, point11 };
- g.DrawPolygon(pen, Wings2);
- g.FillPolygon(br, Wings2);
-
- //нижнее правое крыло
- Point point12 = new Point(_startPosX.Value + 110, _startPosY.Value + 100);
- Point point13 = new Point(_startPosX.Value + 110, _startPosY.Value + 80);
- Point point14 = new Point(_startPosX.Value + 95, _startPosY.Value + 80);
- Point point15 = new Point(_startPosX.Value + 100, _startPosY.Value + 100);
- Point[] Wings3 = { point12, point13, point14, point15 };
- g.DrawPolygon(pen, Wings3);
- g.FillPolygon(br, Wings3);
-
- //верхнее правое крыло
- Point point16 = new Point(_startPosX.Value + 110, _startPosY.Value + 30);
- Point point17 = new Point(_startPosX.Value + 110, _startPosY.Value + 50);
- Point point18 = new Point(_startPosX.Value + 95, _startPosY.Value + 50);
- Point point19 = new Point(_startPosX.Value + 100, _startPosY.Value + 30);
- Point[] Wings4 = { point16, point17, point18, point19 };
- g.DrawPolygon(pen, Wings4);
- g.FillPolygon(br, Wings4);
-
- //наличие топливных баков
- if (EntityAirBomber.Engine)
- {
- Brush brBrown = new SolidBrush(Color.Brown);
- g.DrawRectangle(pen, _startPosX.Value + 75, _startPosY.Value + 45, 20, 5);
- g.DrawRectangle(pen, _startPosX.Value + 75, _startPosY.Value + 80, 20, 5);
- g.FillRectangle(brBrown, _startPosX.Value + 75, _startPosY.Value + 45, 20, 5);
- g.FillRectangle(brBrown, _startPosX.Value + 75, _startPosY.Value + 80, 20, 5);
- }
-
- //наличие дополнительных бомб
- if (EntityAirBomber.Bomb)
- {
- Brush brGreen = new SolidBrush(Color.Green);
- g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 20, 20, 8);
- g.DrawRectangle(pen, _startPosX.Value + 40, _startPosY.Value + 100, 20, 8);
- g.FillRectangle(brGreen, _startPosX.Value + 40, _startPosY.Value + 20, 20, 8);
- g.FillRectangle(brGreen, _startPosX.Value + 40, _startPosY.Value + 100, 20, 8);
- }
- }
-}
\ No newline at end of file
diff --git a/ProjectBomber/ProjectBomber/DirectionType.cs b/ProjectBomber/ProjectBomber/Drawnings/DirectionType.cs
similarity index 79%
rename from ProjectBomber/ProjectBomber/DirectionType.cs
rename to ProjectBomber/ProjectBomber/Drawnings/DirectionType.cs
index 1c0d45e..7bcd90a 100644
--- a/ProjectBomber/ProjectBomber/DirectionType.cs
+++ b/ProjectBomber/ProjectBomber/Drawnings/DirectionType.cs
@@ -1,5 +1,4 @@
-
-namespace ProjectAirBomber;
+namespace ProjectAirBomber.Drawnings;
public enum DirectionType
{
@@ -18,6 +17,8 @@ public enum DirectionType
///
/// Вправо
///
- Right = 4
+ Right = 4,
+
+ Unknow = -1
}
\ No newline at end of file
diff --git a/ProjectBomber/ProjectBomber/Drawnings/DrawningAirBomber.cs b/ProjectBomber/ProjectBomber/Drawnings/DrawningAirBomber.cs
new file mode 100644
index 0000000..07ac006
--- /dev/null
+++ b/ProjectBomber/ProjectBomber/Drawnings/DrawningAirBomber.cs
@@ -0,0 +1,57 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Numerics;
+using System.Text;
+using System.Threading.Tasks;
+using ProjectAirBomber.Entities;
+
+namespace ProjectAirBomber.Drawnings;
+
+public class DrawingAirBomber : DrawningPlane
+{
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ /// Дополнительный цвет
+ /// Дополнительный цвет
+ /// Дополнительный цвет
+ public DrawingAirBomber(int speed, double weight, Color bodyColor, Color
+ additionalColor, bool engine, bool bomb) : base(100, 130)
+
+ {
+ EntityPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor,
+ engine, bomb);
+ }
+ public override void DrawPlane(Graphics g)
+ {
+ if (EntityPlane == null || EntityPlane is not EntityAirBomber airBomber || !_startPosX.HasValue || !_startPosY.HasValue)
+ return;
+ base.DrawPlane(g);
+
+ Pen pen = new(Color.Black);
+
+ //наличие топливных баков
+ if (airBomber.Engine)
+ {
+ Brush brBrown = new SolidBrush(Color.Brown);
+ g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 60, 20, 5);
+ g.DrawRectangle(pen, _startPosX.Value + 90, _startPosY.Value + 95, 20, 5);
+ g.FillRectangle(brBrown, _startPosX.Value + 90, _startPosY.Value + 60, 20, 5);
+ g.FillRectangle(brBrown, _startPosX.Value + 90, _startPosY.Value + 95, 20, 5);
+ }
+
+ //наличие дополнительных бомб
+ if (airBomber.Bomb)
+ {
+ Brush brGreen = new SolidBrush(Color.Green);
+ g.DrawRectangle(pen, _startPosX.Value + 55, _startPosY.Value + 35, 20, 8);
+ g.DrawRectangle(pen, _startPosX.Value + 55, _startPosY.Value + 115, 20, 8);
+ g.FillRectangle(brGreen, _startPosX.Value + 55, _startPosY.Value + 35, 20, 8);
+ g.FillRectangle(brGreen, _startPosX.Value + 55, _startPosY.Value + 115, 20, 8);
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectBomber/ProjectBomber/Drawnings/DrawningPlane.cs b/ProjectBomber/ProjectBomber/Drawnings/DrawningPlane.cs
new file mode 100644
index 0000000..ba88f1f
--- /dev/null
+++ b/ProjectBomber/ProjectBomber/Drawnings/DrawningPlane.cs
@@ -0,0 +1,230 @@
+using ProjectAirBomber.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirBomber.Drawnings;
+
+public class DrawningPlane
+{
+ ///
+ /// Класс-сущность
+ ///
+ public EntityPlane? EntityPlane { get; protected set; }
+ ///
+ /// Ширина окна
+ ///
+ private int? _pictureWidth;
+ ///
+ /// Высота окна
+ ///
+ private int? _pictureHeight;
+ ///
+ /// Левая координата прорисовки самолета
+ ///
+ protected int? _startPosX;
+ ///
+ /// Верхняя кооридната прорисовки самолета
+ ///
+ protected int? _startPosY;
+ ///
+ /// Ширина прорисовки самолета
+ ///
+ private readonly int _drawningPlaneWidth = 95;
+ ///
+ /// Высота прорисовки самолета
+ ///
+ private readonly int _drawningPlaneHeight = 130;
+ ///
+ /// Координата X
+ ///
+ public int? GetPosX => _startPosX;
+ ///
+ /// Координата Y
+ ///
+ public int? GetPosY => _startPosY;
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _drawningPlaneWidth;
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _drawningPlaneHeight;
+
+ ///
+ /// Пустой конструктор
+ ///
+ private DrawningPlane()
+ {
+ _pictureWidth = null;
+ _pictureHeight = null;
+ _startPosX = null;
+ _startPosY = null;
+ }
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес
+ /// Основной цвет
+ public DrawningPlane(int speed, double weight, Color bodyColor) : this()
+ {
+ EntityPlane = new EntityPlane(speed, weight, bodyColor);
+ }
+ ///
+ /// Конструктор для наследования
+ ///
+ /// ширина самолета
+ /// высота самолета
+ protected DrawningPlane(int drawningPlaneWidth, int drawningPlaneHeight) : this()
+ {
+ _drawningPlaneWidth = drawningPlaneWidth;
+ _drawningPlaneHeight = drawningPlaneHeight;
+ }
+
+ ///
+ /// Установка границ поля
+ ///
+ /// Ширина поля
+ /// Высота поля
+ /// true - границы заданы, false - проверка не пройдена, нельзя
+ public bool SetPictureSize(int width, int height)
+ {
+ if (_drawningPlaneWidth <= width && _drawningPlaneHeight <= height)
+ {
+ _pictureWidth = width;
+ _pictureHeight = height;
+ if (_startPosX.HasValue && _startPosY.HasValue)
+ {
+ if (_startPosX + _drawningPlaneWidth > _pictureWidth)
+ {
+ _startPosX = _pictureWidth - _drawningPlaneWidth;
+ }
+
+ if (_startPosY + _drawningPlaneHeight > _pictureHeight)
+ {
+ _startPosY = _pictureHeight - _drawningPlaneHeight;
+ }
+ }
+ 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 + _drawningPlaneWidth > _pictureWidth) x = _pictureWidth.Value - _drawningPlaneWidth;
+
+ if (y < 0) y = 0;
+ else if (y + _drawningPlaneHeight > _pictureHeight) y = _pictureHeight.Value - _drawningPlaneHeight;
+ _startPosX = x;
+ _startPosY = y;
+ }
+ public bool MoveTransport(DirectionType direction)
+ {
+ if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ return false;
+ switch (direction)
+ {
+ //влево
+ case DirectionType.Left:
+ if (_startPosX.Value - EntityPlane.Step > 0)
+ _startPosX -= (int)EntityPlane.Step;
+ return true;
+ //вверх
+ case DirectionType.Up:
+ if (_startPosY.Value - EntityPlane.Step > 0)
+ _startPosY -= (int)EntityPlane.Step;
+ return true;
+ // вправо
+ case DirectionType.Right:
+ if (_startPosX.Value + _drawningPlaneWidth + EntityPlane.Step < _pictureWidth)
+ _startPosX += (int)EntityPlane.Step;
+ return true;
+ //вниз
+ case DirectionType.Down:
+ if (_startPosY.Value + _drawningPlaneHeight + EntityPlane.Step < _pictureHeight)
+ _startPosY += (int)EntityPlane.Step;
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ ///
+ /// Прорисовка объекта
+ ///
+ ///
+ ///
+ public virtual void DrawPlane(Graphics g)
+ {
+ if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+
+ //главная часть
+ Brush br = new SolidBrush(EntityPlane.BodyColor);
+ g.DrawRectangle(pen, _startPosX.Value+25, _startPosY.Value + 65, 100, 30);
+ g.FillRectangle(br, _startPosX.Value+25, _startPosY.Value + 65, 100, 30);
+
+ //носовая часть
+ Brush brBlack = new SolidBrush(Color.Black);
+ Point point1 = new Point(_startPosX.Value, _startPosY.Value + 80);
+ Point point2 = new Point(_startPosX.Value + 25, _startPosY.Value + 95);
+ Point point3 = new Point(_startPosX.Value + 25, _startPosY.Value + 65);
+ Point[] curvePointsNos = { point1, point2, point3 };
+ g.DrawPolygon(pen, curvePointsNos);
+ g.FillPolygon(brBlack, curvePointsNos);
+
+ //верхнее левое крыло
+ Point point4 = new Point(_startPosX.Value + 75, _startPosY.Value + 25);
+ Point point5 = new Point(_startPosX.Value + 75, _startPosY.Value + 65);
+ Point point6 = new Point(_startPosX.Value + 90, _startPosY.Value + 65);
+ Point point7 = new Point(_startPosX.Value + 80, _startPosY.Value + 25);
+ Point[] Wings1 = { point4, point5, point6, point7 };
+ g.DrawPolygon(pen, Wings1);
+ g.FillPolygon(br, Wings1);
+
+ //нижнее левое крыло
+ Point point8 = new Point(_startPosX.Value + 75, _startPosY.Value + 155);
+ Point point9 = new Point(_startPosX.Value + 75, _startPosY.Value + 95);
+ Point point10 = new Point(_startPosX.Value + 90, _startPosY.Value + 95);
+ Point point11 = new Point(_startPosX.Value + 80, _startPosY.Value + 155);
+ Point[] Wings2 = { point8, point9, point10, point11 };
+ g.DrawPolygon(pen, Wings2);
+ g.FillPolygon(br, Wings2);
+
+ //нижнее правое крыло
+ Point point12 = new Point(_startPosX.Value + 125, _startPosY.Value + 115);
+ Point point13 = new Point(_startPosX.Value + 125, _startPosY.Value + 95);
+ Point point14 = new Point(_startPosX.Value + 110, _startPosY.Value + 95);
+ Point point15 = new Point(_startPosX.Value + 115, _startPosY.Value + 115);
+ Point[] Wings3 = { point12, point13, point14, point15 };
+ g.DrawPolygon(pen, Wings3);
+ g.FillPolygon(br, Wings3);
+
+ //верхнее правое крыло
+ Point point16 = new Point(_startPosX.Value + 125, _startPosY.Value + 45);
+ Point point17 = new Point(_startPosX.Value + 125, _startPosY.Value + 65);
+ Point point18 = new Point(_startPosX.Value + 110, _startPosY.Value + 65);
+ Point point19 = new Point(_startPosX.Value + 115, _startPosY.Value + 45);
+ Point[] Wings4 = { point16, point17, point18, point19 };
+ g.DrawPolygon(pen, Wings4);
+ g.FillPolygon(br, Wings4);
+ }
+}
\ No newline at end of file
diff --git a/ProjectBomber/ProjectBomber/EntityAirBomber.cs b/ProjectBomber/ProjectBomber/Entities/EntityAirBomber.cs
similarity index 50%
rename from ProjectBomber/ProjectBomber/EntityAirBomber.cs
rename to ProjectBomber/ProjectBomber/Entities/EntityAirBomber.cs
index e646a43..4c514f4 100644
--- a/ProjectBomber/ProjectBomber/EntityAirBomber.cs
+++ b/ProjectBomber/ProjectBomber/Entities/EntityAirBomber.cs
@@ -1,18 +1,10 @@
-namespace ProjectAirBomber;
-public class EntityAirBomber
+namespace ProjectAirBomber.Entities;
+
+///
+/// Класс сущность бомбардировщик
+///
+public class EntityAirBomber : EntityPlane
{
- ///
- /// Скорость
- ///
- public int Speed { get; private set; }
- ///
- /// Вес
- ///
- public double Weight { get; private set; }
- ///
- /// Основной цвет
- ///
- public Color BodyColor { get; private set; }
///
/// Дополнительный цвет (для опциональных элементов)
///
@@ -27,27 +19,15 @@ public class EntityAirBomber
/// наличие бомб
///
public bool Bomb { get; private set; }
-
- ///
- /// Шаг перемещения автомобиля
- ///
- public double Step => Speed * 100 / Weight;
///
/// Инициализация полей объекта-класса спортивного автомобиля
///
- /// Скорость
- /// Вес автомобиля
- /// Основной цвет
/// Дополнительный цвет
/// наличие двигателя
/// наличие двигателя
///
- public void Init(int speed, double weight, Color bodyColor, Color
- additionalColor, bool engine, bool bomb)
+ public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool engine, bool bomb) : base (speed,weight,bodyColor)
{
- Speed = speed;
- Weight = weight;
- BodyColor = bodyColor;
AdditionalColor = additionalColor;
Engine = engine;
Bomb = bomb;
diff --git a/ProjectBomber/ProjectBomber/Entities/EntityPlane.cs b/ProjectBomber/ProjectBomber/Entities/EntityPlane.cs
new file mode 100644
index 0000000..8e60d5b
--- /dev/null
+++ b/ProjectBomber/ProjectBomber/Entities/EntityPlane.cs
@@ -0,0 +1,43 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirBomber.Entities;
+
+///
+/// Класс сущность самолет
+///
+public class EntityPlane
+{
+ ///
+ /// Скорость
+ ///
+ 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 EntityPlane(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+}
diff --git a/ProjectBomber/ProjectBomber/FormAirBomber.Designer.cs b/ProjectBomber/ProjectBomber/FormAirBomber.Designer.cs
index b5ba0ef..6658de9 100644
--- a/ProjectBomber/ProjectBomber/FormAirBomber.Designer.cs
+++ b/ProjectBomber/ProjectBomber/FormAirBomber.Designer.cs
@@ -38,6 +38,9 @@ namespace ProjectAirBomber
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
+ buttonCreatePlane = new Button();
+ comboBoxStrategy = new ComboBox();
+ buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit();
SuspendLayout();
//
@@ -55,9 +58,9 @@ namespace ProjectAirBomber
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
buttonCreate.Location = new Point(0, 655);
buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(94, 29);
+ buttonCreate.Size = new Size(247, 29);
buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать";
+ buttonCreate.Text = "Создать бомбардировщик";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += ButtonCreate_Click;
//
@@ -94,7 +97,7 @@ namespace ProjectAirBomber
buttonDown.Location = new Point(1452, 637);
buttonDown.Name = "buttonDown";
buttonDown.Size = new Size(35, 35);
- buttonDown.TabIndex = 4;
+ buttonDown.TabIndex = 4;
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
@@ -110,11 +113,45 @@ namespace ProjectAirBomber
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
+ // buttonCreatePlane
+ //
+ buttonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ buttonCreatePlane.Location = new Point(253, 655);
+ buttonCreatePlane.Name = "buttonCreatePlane";
+ buttonCreatePlane.Size = new Size(247, 29);
+ buttonCreatePlane.TabIndex = 6;
+ buttonCreatePlane.Text = "Создать самолет";
+ buttonCreatePlane.UseVisualStyleBackColor = true;
+ buttonCreatePlane.Click += ButtonCreatePlane_Click;
+ //
+ // comboBoxStrategy
+ //
+ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxStrategy.FormattingEnabled = true;
+ comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
+ comboBoxStrategy.Location = new Point(1392, 12);
+ comboBoxStrategy.Name = "comboBoxStrategy";
+ comboBoxStrategy.Size = new Size(151, 28);
+ comboBoxStrategy.TabIndex = 7;
+ //
+ // buttonStrategyStep
+ //
+ buttonStrategyStep.Location = new Point(1434, 46);
+ buttonStrategyStep.Name = "buttonStrategyStep";
+ buttonStrategyStep.Size = new Size(94, 29);
+ buttonStrategyStep.TabIndex = 8;
+ buttonStrategyStep.Text = "Шаг";
+ buttonStrategyStep.UseVisualStyleBackColor = true;
+ buttonStrategyStep.Click += ButtonStrategyStep_Click;
+ //
// ProjectAirBomber
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(1555, 684);
+ Controls.Add(buttonStrategyStep);
+ Controls.Add(comboBoxStrategy);
+ Controls.Add(buttonCreatePlane);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
@@ -135,5 +172,8 @@ namespace ProjectAirBomber
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
+ private Button buttonCreatePlane;
+ private ComboBox comboBoxStrategy;
+ private Button buttonStrategyStep;
}
}
\ No newline at end of file
diff --git a/ProjectBomber/ProjectBomber/FormAirBomber.cs b/ProjectBomber/ProjectBomber/FormAirBomber.cs
index 600e100..eb92194 100644
--- a/ProjectBomber/ProjectBomber/FormAirBomber.cs
+++ b/ProjectBomber/ProjectBomber/FormAirBomber.cs
@@ -1,45 +1,92 @@
-using ProjectAirBomber;
+using ProjectAirBomber.Drawnings;
+using ProjectAirBomber.MovementStrategy;
using System.Windows.Forms;
namespace ProjectAirBomber
{
public partial class ProjectAirBomber : Form
{
- private DrawingAirBomber? _drawingAirBomber;
+ ///
+ /// Поле-объект для прорисовки объекта
+ ///
+ private DrawningPlane? _drawningPlane;
+
+ ///
+ /// Стратегия перемещения
+ ///
+ private AbstractStategy? _strategy;
+
+ ///
+ /// Конструктор формы
+ ///
public ProjectAirBomber()
{
InitializeComponent();
+ _strategy = null;
}
private void Draw()
{
- if (_drawingAirBomber == null)
+ if (_drawningPlane == null)
{
return;
}
Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawingAirBomber.DrawAirBomber(gr);
+ _drawningPlane.DrawPlane(gr);
pictureBoxAirBomber.Image = bmp;
}
- private void ButtonCreate_Click(object sender, EventArgs e)
+ private void CreateObject(string type)
{
- Random random = new();
- _drawingAirBomber = new DrawingAirBomber();
- _drawingAirBomber.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)));
- _drawingAirBomber.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
- _drawingAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ Random rnd = new Random();
+ switch (type)
+ {
+ case nameof(DrawningPlane):
+ _drawningPlane = new DrawningPlane(rnd.Next(100, 300), rnd.Next(1000, 3000),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ break;
+ case nameof(DrawingAirBomber):
+ _drawningPlane = new DrawingAirBomber(rnd.Next(650, 700), rnd.Next(15760, 16130),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Convert.ToBoolean(rnd.Next(0, 2)),
+ Convert.ToBoolean(rnd.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+ _drawningPlane.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
+ _drawningPlane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100));
+ _strategy = null;
+
Draw();
}
+ ///
+ /// Обработка нажатия кнопки "Создать автобус с гармошкой"
+ ///
+ ///
+ ///
+ private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingAirBomber));
+
+ ///
+ /// Обработка нажатия кнопки "Создать автобус"
+ ///
+ ///
+ ///
+ public void ButtonCreatePlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
+
+ ///
+ /// Перемещение объекта по форме (нажатие кнопок навигации)
+ ///
+ ///
+ ///
+
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_drawingAirBomber == null)
+ if (_drawningPlane == null)
{
return;
}
@@ -49,16 +96,16 @@ namespace ProjectAirBomber
switch (name)
{
case "buttonUp":
- result = _drawingAirBomber.MoveTransport(DirectionType.Up);
+ result = _drawningPlane.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
- result = _drawingAirBomber.MoveTransport(DirectionType.Down);
+ result = _drawningPlane.MoveTransport(DirectionType.Down);
break;
case "buttonLeft":
- result = _drawingAirBomber.MoveTransport(DirectionType.Left);
+ result = _drawningPlane.MoveTransport(DirectionType.Left);
break;
case "buttonRight":
- result = _drawingAirBomber.MoveTransport(DirectionType.Right);
+ result = _drawningPlane.MoveTransport(DirectionType.Right);
break;
}
@@ -67,5 +114,42 @@ namespace ProjectAirBomber
Draw();
}
}
+
+ private void ButtonStrategyStep_Click(object sender, EventArgs e)
+ {
+ {
+ if (_drawningPlane == null)
+ {
+ return;
+ }
+ if (comboBoxStrategy.Enabled)
+ {
+ _strategy = comboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_strategy == null)
+ {
+ return;
+ }
+ _strategy.SetData(new MoveablePlane(_drawningPlane),
+ pictureBoxAirBomber.Width, pictureBoxAirBomber.Height);
+ }
+ if (_strategy == null)
+ {
+ return;
+ }
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+ if (_strategy.GetStatus() == StrategyStatus.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+ }
+ }
}
}
\ No newline at end of file
diff --git a/ProjectBomber/ProjectBomber/MovementStrategy/AbstractStategy.cs b/ProjectBomber/ProjectBomber/MovementStrategy/AbstractStategy.cs
new file mode 100644
index 0000000..dccd7ee
--- /dev/null
+++ b/ProjectBomber/ProjectBomber/MovementStrategy/AbstractStategy.cs
@@ -0,0 +1,122 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirBomber.MovementStrategy;
+public abstract class AbstractStategy
+{
+ ///
+ /// Перемещаемый объект
+ ///
+ 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;
+ }
+}
\ No newline at end of file
diff --git a/ProjectBomber/ProjectBomber/MovementStrategy/IMoveableObjects.cs b/ProjectBomber/ProjectBomber/MovementStrategy/IMoveableObjects.cs
new file mode 100644
index 0000000..c4778e0
--- /dev/null
+++ b/ProjectBomber/ProjectBomber/MovementStrategy/IMoveableObjects.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirBomber.MovementStrategy;
+public interface IMoveableObject
+{
+ ///
+ /// Получение координаты объекта
+ ///
+ ObjectParameters? GetObjectPosition { get; }
+ ///
+ /// Шаг объекта
+ ///
+ int GetStep { get; }
+ ///
+ /// Попытка переместить объект в указанном направлении
+ ///
+ /// Направление
+ /// true - объект перемещен, false - перемещение невозможно
+ bool TryMoveObject(MovementDirection direction);
+}
diff --git a/ProjectBomber/ProjectBomber/MovementStrategy/MoveToBoarder.cs b/ProjectBomber/ProjectBomber/MovementStrategy/MoveToBoarder.cs
new file mode 100644
index 0000000..af8f398
--- /dev/null
+++ b/ProjectBomber/ProjectBomber/MovementStrategy/MoveToBoarder.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirBomber.MovementStrategy;
+
+public class MoveToBorder : AbstractStategy
+{
+ protected override bool IsTargetDestinaion()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.RightBorder <= FieldWidth && objParams.RightBorder + GetStep() >= FieldWidth &&
+ objParams.DownBorder <= FieldHeight && objParams.DownBorder + GetStep() >= FieldHeight;
+ }
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ int diffX = objParams.RightBorder - FieldWidth;
+ if (Math.Abs(diffX) > GetStep())
+ {
+ if (diffX > 0)
+ {
+ MoveLeft();
+ }
+ else
+ {
+ MoveRight();
+ }
+ }
+ int diffY = objParams.DownBorder - FieldHeight;
+ if (Math.Abs(diffY) > GetStep())
+ {
+ if (diffY > 0)
+ {
+ MoveUp();
+ }
+ else
+ {
+ MoveDown();
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/ProjectBomber/ProjectBomber/MovementStrategy/MoveToCenter.cs b/ProjectBomber/ProjectBomber/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..e12f500
--- /dev/null
+++ b/ProjectBomber/ProjectBomber/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,56 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirBomber.MovementStrategy;
+
+public class MoveToCenter : AbstractStategy
+{
+ 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();
+ }
+ }
+ }
+
+}
\ No newline at end of file
diff --git a/ProjectBomber/ProjectBomber/MovementStrategy/MoveablePlane.cs b/ProjectBomber/ProjectBomber/MovementStrategy/MoveablePlane.cs
new file mode 100644
index 0000000..5071bf8
--- /dev/null
+++ b/ProjectBomber/ProjectBomber/MovementStrategy/MoveablePlane.cs
@@ -0,0 +1,63 @@
+using ProjectAirBomber.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Numerics;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirBomber.MovementStrategy;
+
+public class MoveablePlane : IMoveableObject
+{
+ ///
+ /// Поле-объект класса Drawningplane или его наследника
+ ///
+ private readonly DrawningPlane? _plane = null;
+ ///
+ /// Конструктор
+ ///
+ /// Объект класса Drawningplane
+ public MoveablePlane(DrawningPlane plane)
+ {
+ _plane = plane;
+ }
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_plane == null || _plane.EntityPlane == null ||
+ !_plane.GetPosX.HasValue || !_plane.GetPosY.HasValue)
+ {
+ return null;
+ }
+ return new ObjectParameters(_plane.GetPosX.Value,
+ _plane.GetPosY.Value, _plane.GetWidth, _plane.GetHeight);
+ }
+ }
+ public int GetStep => (int)(_plane?.EntityPlane?.Step ?? 0);
+ public bool TryMoveObject(MovementDirection direction)
+ {
+ if (_plane == null || _plane.EntityPlane == null)
+ {
+ return false;
+ }
+ return _plane.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/ProjectBomber/ProjectBomber/MovementStrategy/MovementDirection.cs b/ProjectBomber/ProjectBomber/MovementStrategy/MovementDirection.cs
new file mode 100644
index 0000000..015865f
--- /dev/null
+++ b/ProjectBomber/ProjectBomber/MovementStrategy/MovementDirection.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirBomber.MovementStrategy;
+
+public enum MovementDirection
+{
+ Up = 1, Down = 2, Left = 3, Right = 4
+}
diff --git a/ProjectBomber/ProjectBomber/MovementStrategy/ObjectParameters.cs b/ProjectBomber/ProjectBomber/MovementStrategy/ObjectParameters.cs
new file mode 100644
index 0000000..d2198df
--- /dev/null
+++ b/ProjectBomber/ProjectBomber/MovementStrategy/ObjectParameters.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirBomber.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;
+ }
+}
\ No newline at end of file
diff --git a/ProjectBomber/ProjectBomber/MovementStrategy/StrategyStatus.cs b/ProjectBomber/ProjectBomber/MovementStrategy/StrategyStatus.cs
new file mode 100644
index 0000000..0907741
--- /dev/null
+++ b/ProjectBomber/ProjectBomber/MovementStrategy/StrategyStatus.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectAirBomber.MovementStrategy;
+
+public enum StrategyStatus
+{
+ ///
+ ///Всё готово к началу
+ ///
+ NotInit,
+
+ ///
+ ///Выполняется
+ ///
+ InProgress,
+
+ ///
+ ///Завершено
+ ///
+ Finish
+}
\ No newline at end of file