diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DirectionType.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DirectionType.cs
new file mode 100644
index 0000000..805eb17
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DirectionType.cs
@@ -0,0 +1,31 @@
+namespace SelfPropelledArtilleryUnit.Drawnings;
+///
+/// Направление перемещения
+///
+public enum DirectionType
+{
+ ///
+ /// Неизвестное направление
+ ///
+ Unknow = -1,
+
+ ///
+ /// Вверх
+ ///
+ Up = 1,
+
+ ///
+ /// Вниз
+ ///
+ Down = 2,
+
+ ///
+ /// Влево
+ ///
+ Left = 3,
+
+ ///
+ /// Вправо
+ ///
+ Right = 4
+}
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningPropelledArtillery.cs
similarity index 55%
rename from SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtilleryUnit.cs
rename to SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningPropelledArtillery.cs
index 90570b1..8c05e24 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DrawningSelfPropelledArtilleryUnit.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningPropelledArtillery.cs
@@ -1,14 +1,20 @@
-namespace SelfPropelledArtilleryUnit;
-///
-/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
-///
+using SelfPropelledArtilleryUnit.Entities;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
-public class DrawningSelfPropelledArtilleryUnit
+namespace SelfPropelledArtilleryUnit.Drawnings;
+///
+/// Класс, отвечающий за прорисовку и перемещение базового объекта-сущности
+///
+public class DrawningPropelledArtillery
{
///
/// Класс-сущность
///
- public EntitySelfPropelledArtilleryUnit? EntitySelfPropelledArtilleryUnit { get; private set; }
+ public EntityPropelledArtillery? EntityPropelledArtillery { get; protected set; }
///
/// Ширина окна
@@ -23,43 +29,77 @@ public class DrawningSelfPropelledArtilleryUnit
///
/// Левая координата прорисовки cамоходной арт. установки
///
- private int? _startPosX;
+ protected int? _startPosX;
///
/// Верхняя кооридната прорисовки cамоходной арт. установки
///
- private int? _startPosY;
+ protected int? _startPosY;
///
/// Ширина прорисовки cамоходной арт. установки
///
- private readonly int _drawningSelfPropelledArtilleryUnitWidth = 135;
+ private readonly int _drawningPropelledArtilleryWidth = 135;
///
/// Высота прорисовки cамоходной арт. установки
///
- private readonly int _drawningSelfPropelledArtilleryUnitHeight = 105;
+ private readonly int _drawningPropelledArtilleryHeight = 105;
///
- /// Инициализация полей объекта-класса Самоходная арт. установка
- ///
- /// Скорость
- /// Вес автомобиля
- /// Основной цвет
- /// Дополнительный цвет
- /// Признак наличия башни
- /// Признак наличия орудия
+ /// Координата X объекта
+ ///
+ public int? GetPosX => _startPosX;
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool turretCannon, bool launchBattery)
+ ///
+ /// Координата Y объекта
+ ///
+ public int? GetPosY => _startPosY;
+
+ ///
+ /// Ширина объекта
+ ///
+ public int GetWidth => _drawningPropelledArtilleryWidth;
+
+ ///
+ /// Высота объекта
+ ///
+ public int GetHeight => _drawningPropelledArtilleryHeight;
+
+ ///
+ /// Пустой конструктор
+ ///
+ private DrawningPropelledArtillery()
{
- EntitySelfPropelledArtilleryUnit = new EntitySelfPropelledArtilleryUnit();
- EntitySelfPropelledArtilleryUnit.Init(speed, weight, bodyColor, additionalColor, turretCannon, launchBattery);
_pictureWidth = null;
_pictureHeight = null;
_startPosX = null;
_startPosY = null;
}
+ ///
+ /// Конструктор
+ ///
+ /// Скорость
+ /// Вес автомобиля
+ /// Основной цвет
+
+ public DrawningPropelledArtillery(int speed, double weight, Color bodyColor): this()
+ {
+ EntityPropelledArtillery = new EntityPropelledArtillery(speed, weight, bodyColor);
+ }
+ ///
+ /// Конструктор для наследников
+ ///
+ /// Ширина прорисовки cамоходной арт. установки
+ /// Высота прорисовки cамоходной арт. установки
+
+ protected DrawningPropelledArtillery(int drawningPropelledArtilleryWidth, int drawningPropelledArtilleryHeight):this()
+ {
+ _drawningPropelledArtilleryWidth = drawningPropelledArtilleryWidth;
+ _drawningPropelledArtilleryHeight = drawningPropelledArtilleryHeight;
+ }
+
///
/// Установка границ поля
///
@@ -68,7 +108,7 @@ public class DrawningSelfPropelledArtilleryUnit
/// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах
public bool SetPictureSize(int width, int height)
{
- if (_drawningSelfPropelledArtilleryUnitWidth > width || _drawningSelfPropelledArtilleryUnitHeight > height)
+ if (_drawningPropelledArtilleryWidth > width || _drawningPropelledArtilleryHeight > height)
{
return false;
}
@@ -77,14 +117,14 @@ public class DrawningSelfPropelledArtilleryUnit
_pictureHeight = height;
if (_startPosX.HasValue || _startPosY.HasValue)
{
- if (_startPosX + _drawningSelfPropelledArtilleryUnitWidth > _pictureWidth)
+ if (_startPosX + _drawningPropelledArtilleryWidth > _pictureWidth)
{
- _startPosX = _pictureWidth - _drawningSelfPropelledArtilleryUnitWidth;
+ _startPosX = _pictureWidth - _drawningPropelledArtilleryWidth;
}
else if (_startPosX < 0) _startPosX = 0;
- if (_startPosY + _drawningSelfPropelledArtilleryUnitHeight > _pictureHeight)
+ if (_startPosY + _drawningPropelledArtilleryHeight > _pictureHeight)
{
- _startPosY = _pictureHeight - _drawningSelfPropelledArtilleryUnitHeight;
+ _startPosY = _pictureHeight - _drawningPropelledArtilleryHeight;
}
else if (_startPosY < 0) _startPosY = 0;
}
@@ -105,16 +145,16 @@ public class DrawningSelfPropelledArtilleryUnit
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
// то надо изменить координаты, чтобы он оставался в этих границах
- if (x + _drawningSelfPropelledArtilleryUnitWidth > _pictureWidth)
+ if (x + _drawningPropelledArtilleryWidth > _pictureWidth)
{
- _startPosX = _pictureWidth - _drawningSelfPropelledArtilleryUnitWidth;
+ _startPosX = _pictureWidth - _drawningPropelledArtilleryWidth;
}
else if (x < 0) _startPosX = 0;
else _startPosX = x;
- if (y + _drawningSelfPropelledArtilleryUnitHeight > _pictureHeight)
+ if (y + _drawningPropelledArtilleryHeight > _pictureHeight)
{
- _startPosY = _pictureHeight - _drawningSelfPropelledArtilleryUnitHeight;
+ _startPosY = _pictureHeight - _drawningPropelledArtilleryHeight;
}
else if (y < 0) _startPosY = 0;
else _startPosY = y;
@@ -128,7 +168,7 @@ public class DrawningSelfPropelledArtilleryUnit
/// true - перемещене выполнено, false - перемещение невозможно
public bool MoveTransport(DirectionType direction)
{
- if (EntitySelfPropelledArtilleryUnit == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ if (EntityPropelledArtillery == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return false;
}
@@ -137,30 +177,30 @@ public class DrawningSelfPropelledArtilleryUnit
{
//влево
case DirectionType.Left:
- if (_startPosX.Value - EntitySelfPropelledArtilleryUnit.Step > 0)
+ if (_startPosX.Value - EntityPropelledArtillery.Step > 0)
{
- _startPosX -= (int)EntitySelfPropelledArtilleryUnit.Step;
+ _startPosX -= (int)EntityPropelledArtillery.Step;
}
return true;
//вверх
case DirectionType.Up:
- if (_startPosY.Value - EntitySelfPropelledArtilleryUnit.Step > 0)
+ if (_startPosY.Value - EntityPropelledArtillery.Step > 0)
{
- _startPosY -= (int)EntitySelfPropelledArtilleryUnit.Step;
+ _startPosY -= (int)EntityPropelledArtillery.Step;
}
return true;
// вправо
case DirectionType.Right:
- if (_startPosX + _drawningSelfPropelledArtilleryUnitWidth + EntitySelfPropelledArtilleryUnit.Step < _pictureWidth)
+ if (_startPosX + _drawningPropelledArtilleryWidth + EntityPropelledArtillery.Step < _pictureWidth)
{
- _startPosX += (int)EntitySelfPropelledArtilleryUnit.Step;
+ _startPosX += (int)EntityPropelledArtillery.Step;
}
return true;
// вниз
case DirectionType.Down:
- if (_startPosY + _drawningSelfPropelledArtilleryUnitHeight + EntitySelfPropelledArtilleryUnit.Step < _pictureHeight)
+ if (_startPosY + _drawningPropelledArtilleryHeight + EntityPropelledArtillery.Step < _pictureHeight)
{
- _startPosY += (int)EntitySelfPropelledArtilleryUnit.Step;
+ _startPosY += (int)EntityPropelledArtillery.Step;
}
return true;
default:
@@ -173,37 +213,36 @@ public class DrawningSelfPropelledArtilleryUnit
/// Прорисовка объекта
///
///
- public void DrawTransport(Graphics g)
+ public virtual void DrawTransport(Graphics g)
{
- if (EntitySelfPropelledArtilleryUnit == null || !_startPosX.HasValue || !_startPosY.HasValue)
+ if (EntityPropelledArtillery == null || !_startPosX.HasValue || !_startPosY.HasValue)
{
return;
}
-
+
Pen pen = new(Color.Black);
- Brush additionalBrush = new SolidBrush(EntitySelfPropelledArtilleryUnit.AdditionalColor);
-
+ Brush brush = new SolidBrush(EntityPropelledArtillery.BodyColor);
+ Brush brSlateGray = new SolidBrush(Color.SlateGray);
+
g.DrawEllipse(pen, _startPosX.Value + 0, _startPosY.Value + 75, 30, 30);
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 75, 30, 30);
g.DrawRectangle(pen, _startPosX.Value + 15, _startPosY.Value + 75, 90, 30);
//границы ЦВЕТ
- Brush brOlive = new SolidBrush(Color.Olive);
- g.FillRectangle(brOlive, _startPosX.Value + 25, _startPosY.Value + 40, 35, 30);//башня
- g.FillEllipse(brOlive, _startPosX.Value +0, _startPosY.Value + 75, 30, 30);
- g.FillEllipse(brOlive, _startPosX.Value + 90, _startPosY.Value + 75, 30, 30);
- g.FillRectangle(brOlive, _startPosX.Value + 15, _startPosY.Value + 75, 90, 30);
+ g.FillRectangle(brush, _startPosX.Value + 25, _startPosY.Value + 40, 35, 30);//башня
+ g.FillEllipse(brush, _startPosX.Value + 0, _startPosY.Value + 75, 30, 30);
+ g.FillEllipse(brush, _startPosX.Value + 90, _startPosY.Value + 75, 30, 30);
+ g.FillRectangle(brush, _startPosX.Value + 15, _startPosY.Value + 75, 90, 30);
// границы арт. установки
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 40, 35, 30);
g.DrawRectangle(pen, _startPosX.Value + 0, _startPosY.Value + 65, 120, 13);//крыша
// верхние катки ЦВЕТ
- Brush brCadetBlue = new SolidBrush(Color.CadetBlue);
- g.FillEllipse(brCadetBlue, _startPosX.Value + 30, _startPosY.Value + 70, 20, 20);
- g.FillEllipse(brCadetBlue, _startPosX.Value + 50, _startPosY.Value + 70, 20, 20);
- g.FillEllipse(brCadetBlue, _startPosX.Value + 70, _startPosY.Value + 70, 20, 20);
+ g.FillEllipse(brSlateGray, _startPosX.Value + 30, _startPosY.Value + 70, 20, 20);
+ g.FillEllipse(brSlateGray, _startPosX.Value + 50, _startPosY.Value + 70, 20, 20);
+ g.FillEllipse(brSlateGray, _startPosX.Value + 70, _startPosY.Value + 70, 20, 20);
// верхние катки ОТРИСОВКА
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 70, 20, 20);
@@ -223,8 +262,6 @@ public class DrawningSelfPropelledArtilleryUnit
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 90, 15, 15);
g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 90, 15, 15);
- //Большие катки ЦВЕТ
- Brush brSlateGray = new SolidBrush(Color.SlateGray);
g.FillEllipse(brSlateGray, _startPosX.Value + 3, _startPosY.Value + 78, 24, 24);
g.FillEllipse(brSlateGray, _startPosX.Value + 93, _startPosY.Value + 78, 24, 24);
@@ -232,30 +269,9 @@ public class DrawningSelfPropelledArtilleryUnit
g.DrawEllipse(pen, _startPosX.Value + 3, _startPosY.Value + 78, 24, 24);
g.DrawEllipse(pen, _startPosX.Value + 93, _startPosY.Value + 78, 24, 24);
- g.FillRectangle(brOlive, _startPosX.Value + 0, _startPosY.Value + 65, 120, 13);//
+ g.FillRectangle(brush, _startPosX.Value + 0, _startPosY.Value + 65, 120, 13);//
- if (EntitySelfPropelledArtilleryUnit.TurretCannon)
- {
- g.FillEllipse(additionalBrush, _startPosX.Value + 26, _startPosY.Value + 35, 50, 30);
- g.FillRectangle(additionalBrush, _startPosX.Value + 25, _startPosY.Value + 36, 20, 29);
- g.FillRectangle(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 45, 60, 5);
- g.FillEllipse(additionalBrush, _startPosX.Value + 113, _startPosY.Value + 42, 20, 10);
- }
-
- if (EntitySelfPropelledArtilleryUnit.LaunchBattery)
- {
- g.FillRectangle(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 45, 20, 20);
- g.FillPolygon(additionalBrush, new Point[]
- {
- new Point(_startPosX.Value + 0, _startPosY.Value + 15), new Point(_startPosX.Value + 0, _startPosY.Value + 65),
- new Point(_startPosX.Value + 20, _startPosY.Value + 65), new Point(_startPosX.Value + 20, _startPosY.Value + 45),
- new Point(_startPosX.Value + 0, _startPosY.Value + 15)
- });
- g.FillEllipse(additionalBrush, _startPosX.Value + 0, _startPosY.Value + 5, 10, 30);
- g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 15, 20, 5);
- g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 25, 15, 5);
- }
+
}
-
-}
\ No newline at end of file
+}
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningSelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningSelfPropelledArtilleryUnit.cs
new file mode 100644
index 0000000..c0cea51
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Drawnings/DrawningSelfPropelledArtilleryUnit.cs
@@ -0,0 +1,57 @@
+using SelfPropelledArtilleryUnit.Entities;
+
+namespace SelfPropelledArtilleryUnit.Drawnings;
+///
+/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
+///
+
+public class DrawningSelfPropelledArtilleryUnit : DrawningPropelledArtillery
+{
+ ///
+ /// Конструктор
+ ///
+ /// Дополнительный цвет
+ /// Признак наличия башни
+ /// Признак наличия орудия
+ public DrawningSelfPropelledArtilleryUnit(int speed, double weight, Color bodyColor, Color additionalColor, bool turretCannon, bool launchBattery) : base(135, 105)
+ {
+ EntityPropelledArtillery = new EntitySelfPropelledArtilleryUnit(speed, weight, bodyColor, additionalColor, turretCannon, launchBattery);
+ //дописать
+ }
+
+ public override void DrawTransport(Graphics g)
+ {
+ if (EntityPropelledArtillery == null || EntityPropelledArtillery is not EntitySelfPropelledArtilleryUnit selfpropelledartilleryunit || !_startPosX.HasValue || !_startPosY.HasValue)
+ {
+ return;
+ }
+
+ Pen pen = new(Color.Black);
+ Brush brush = new SolidBrush(selfpropelledartilleryunit.AdditionalColor);
+
+ base.DrawTransport(g);
+ if (selfpropelledartilleryunit.TurretCannon)
+ {
+ g.FillEllipse(brush, _startPosX.Value + 26, _startPosY.Value + 35, 50, 30);
+ g.FillRectangle(brush, _startPosX.Value + 25, _startPosY.Value + 36, 20, 29);
+ g.FillRectangle(brush, _startPosX.Value + 60, _startPosY.Value + 45, 60, 5);
+ g.FillEllipse(brush, _startPosX.Value + 113, _startPosY.Value + 42, 20, 10);
+ }
+
+ if (selfpropelledartilleryunit.LaunchBattery)
+ {
+ g.FillRectangle(brush, _startPosX.Value + 0, _startPosY.Value + 45, 20, 20);
+ g.FillPolygon(brush, new Point[]
+ {
+ new Point(_startPosX.Value + 0, _startPosY.Value + 15), new Point(_startPosX.Value + 0, _startPosY.Value + 65),
+ new Point(_startPosX.Value + 20, _startPosY.Value + 65), new Point(_startPosX.Value + 20, _startPosY.Value + 45),
+ new Point(_startPosX.Value + 0, _startPosY.Value + 15)
+ });
+ g.FillEllipse(brush, _startPosX.Value + 0, _startPosY.Value + 5, 10, 30);
+ g.FillRectangle(brush, _startPosX.Value + 10, _startPosY.Value + 15, 20, 5);
+ g.FillRectangle(brush, _startPosX.Value + 10, _startPosY.Value + 25, 15, 5);
+ }
+
+
+ }
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntityPropelledArtillery.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntityPropelledArtillery.cs
new file mode 100644
index 0000000..0967e4a
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntityPropelledArtillery.cs
@@ -0,0 +1,35 @@
+namespace SelfPropelledArtilleryUnit.Entities;
+///
+/// Класс-сущность "Бронированная машина"
+///
+public class EntityPropelledArtillery
+{
+ ///
+ /// Скорость
+ ///
+ 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 EntityPropelledArtillery(int speed, double weight, Color bodyColor)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodyColor;
+ }
+}
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntitySelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntitySelfPropelledArtilleryUnit.cs
new file mode 100644
index 0000000..66b2507
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/Entities/EntitySelfPropelledArtilleryUnit.cs
@@ -0,0 +1,37 @@
+namespace SelfPropelledArtilleryUnit.Entities;
+///
+/// Класс-сущность "Самоходная арт. установка"
+///
+public class EntitySelfPropelledArtilleryUnit : EntityPropelledArtillery
+{
+ ///
+ /// Дополнительный цвет (для опциональных элементов)
+ ///
+ public Color AdditionalColor { get; private set; }
+ ///
+ /// Признак - Башня с орудием
+ ///
+ public bool TurretCannon { get; private set; }
+ ///
+ /// Признак - Залповая батарея сзади
+ ///
+ public bool LaunchBattery { get; private set; }
+ ///
+ /// Шаг перемещения артеллерийской установки
+ ///
+ public double Step => Speed * 100 / Weight;
+
+ ///
+ /// Инициализация полей объекта-класса EntitySelfPropelledArtilleryUnit
+ ///
+ /// Дополнительный цвет
+ /// Башня с орудием
+ /// Залповая батарея сзади
+ public EntitySelfPropelledArtilleryUnit(int speed, double weight, Color bodycolor, Color additionalcolor, bool turretcannon, bool launchbattery) : base(speed, weight, bodycolor)
+ {
+ AdditionalColor = additionalcolor;
+ TurretCannon = turretcannon;
+ LaunchBattery = launchbattery;
+ }
+}
+
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntitySelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntitySelfPropelledArtilleryUnit.cs
deleted file mode 100644
index 51c67fc..0000000
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/EntitySelfPropelledArtilleryUnit.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-namespace SelfPropelledArtilleryUnit;
-///
-/// Класс-сущность "Самоходная арт. установка "
-///
-public class EntitySelfPropelledArtilleryUnit
-{
- ///
- /// Скорость
- ///
- 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 TurretCannon { get; private set; }
-
- ///
- /// Признак - Залповая батарея сзади
- ///
- public bool LaunchBattery { get; private set; }
-
- ///
- /// Шаг перемещения артеллерийской установки
- ///
- public double Step => Speed * 100 / Weight;
-
- ///
- /// Инициализация полей объекта-класса Самоходная арт. установка
- ///
- /// Скорость
- /// Вес автомобиля
- /// Основной цвет
- /// Дополнительный цвет
- /// Башня с орудием
- /// Залповая батарея сзади
- public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool turretCannon, bool launchBattery)
- {
- Speed = speed;
- Weight = weight;
- BodyColor = bodyColor;
- AdditionalColor = additionalColor;
- TurretCannon = turretCannon;
- LaunchBattery = launchBattery;
- }
-}
-
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.Designer.cs
deleted file mode 100644
index 419aba2..0000000
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.Designer.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-namespace SelfPropelledArtilleryUnit
-{
- partial class FormSelfPropelledArtilleryUnit
- {
- ///
- /// 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()
- {
- this.components = new System.ComponentModel.Container();
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Text = "FormSelfPropelledArtilleryUnit";
- }
-
- #endregion
- }
-}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs
deleted file mode 100644
index 299f56c..0000000
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/FormSelfPropelledArtilleryUnit.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Forms;
-
-namespace SelfPropelledArtilleryUnit
-{
- public partial class FormSelfPropelledArtilleryUnit : Form
- {
- public FormSelfPropelledArtilleryUnit()
- {
- InitializeComponent();
- }
- }
-}
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/AbstractStrategy.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/AbstractStrategy.cs
new file mode 100644
index 0000000..794ba0a
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/AbstractStrategy.cs
@@ -0,0 +1,139 @@
+namespace SelfPropelledArtilleryUnit.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/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/IMoveableObject.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/IMoveableObject.cs
new file mode 100644
index 0000000..5da7a46
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/IMoveableObject.cs
@@ -0,0 +1,24 @@
+namespace SelfPropelledArtilleryUnit.MovementStrategy;
+
+///
+/// Интерфейс для работы с перемещаемым объектом
+///
+public interface IMoveableObject
+{
+ ///
+ /// Получение координаты объекта
+ ///
+ ObjectParameters? GetObjectPosition { get; }
+
+ ///
+ /// Шаг объекта
+ ///
+ int GetStep { get; }
+
+ ///
+ /// Попытка переместить объект в указанном направлении
+ ///
+ /// Направление
+ /// true - объект перемещен, false - перемещение невозможно
+ bool TryMoveObject(MovementDirection direction);
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToBorder.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToBorder.cs
new file mode 100644
index 0000000..e48881e
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToBorder.cs
@@ -0,0 +1,31 @@
+namespace SelfPropelledArtilleryUnit.MovementStrategy;
+
+public class MoveToBorder : AbstractStrategy
+{
+ protected override bool IsTargetDestinaion()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return false;
+ }
+ return objParams.LeftBorder - GetStep() <= 0 ||
+ objParams.RightBorder + GetStep() >= FieldWidth ||
+ objParams.TopBorder - GetStep() <= 0
+ || objParams.ObjectMiddleVertical + GetStep() >= FieldHeight;
+ }
+
+ protected override void MoveToTarget()
+ {
+ ObjectParameters? objParams = GetObjectParameters;
+ if (objParams == null)
+ {
+ return;
+ }
+ //реализация в правый нижний угол
+ int x = objParams.RightBorder;
+ if (x + GetStep() < FieldWidth) MoveRight();
+ int y = objParams.DownBorder;
+ if (y + GetStep() < FieldHeight) MoveDown();
+ }
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToCenter.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToCenter.cs
new file mode 100644
index 0000000..45214d3
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveToCenter.cs
@@ -0,0 +1,53 @@
+namespace SelfPropelledArtilleryUnit.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();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveablePropelledArtillery.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveablePropelledArtillery.cs
new file mode 100644
index 0000000..9208f1b
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MoveablePropelledArtillery.cs
@@ -0,0 +1,63 @@
+using SelfPropelledArtilleryUnit.Drawnings;
+
+namespace SelfPropelledArtilleryUnit.MovementStrategy;
+///
+/// Класс-реализация IMoveableObject с использованием DrawningPropelledArtillery
+///
+public class MoveablePropelledArtillery : IMoveableObject
+{
+ ///
+ /// Поле-объект класса DrawningPropelledArtillery или его наследника
+ ///
+ private readonly DrawningPropelledArtillery? _PropelledArtillery = null;
+
+ ///
+ /// Конструктор
+ ///
+ /// Объект класса DrawningPropelledArtillery
+ public MoveablePropelledArtillery(DrawningPropelledArtillery PropelledArtillery)
+ {
+ _PropelledArtillery = PropelledArtillery;
+ }
+
+ public ObjectParameters? GetObjectPosition
+ {
+ get
+ {
+ if (_PropelledArtillery == null || _PropelledArtillery.EntityPropelledArtillery == null || !_PropelledArtillery.GetPosX.HasValue || !_PropelledArtillery.GetPosY.HasValue)
+ {
+ return null;
+ }
+ return new ObjectParameters(_PropelledArtillery.GetPosX.Value, _PropelledArtillery.GetPosY.Value, _PropelledArtillery.GetWidth, _PropelledArtillery.GetHeight);
+ }
+ }
+
+ public int GetStep => (int)(_PropelledArtillery?.EntityPropelledArtillery?.Step ?? 0);
+
+ public bool TryMoveObject(MovementDirection direction)
+ {
+ if (_PropelledArtillery == null || _PropelledArtillery.EntityPropelledArtillery == null)
+ {
+ return false;
+ }
+
+ return _PropelledArtillery.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,
+ };
+ }
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DirectionType.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MovementDirection.cs
similarity index 80%
rename from SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DirectionType.cs
rename to SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MovementDirection.cs
index aac0d0b..2dae8cc 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/DirectionType.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/MovementDirection.cs
@@ -1,8 +1,8 @@
-namespace SelfPropelledArtilleryUnit;
+namespace SelfPropelledArtilleryUnit.MovementStrategy;
///
/// Направление перемещения
///
-public enum DirectionType
+public enum MovementDirection
{
///
/// Вверх
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/ObjectParameters.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/ObjectParameters.cs
new file mode 100644
index 0000000..d7cdaba
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/ObjectParameters.cs
@@ -0,0 +1,69 @@
+namespace SelfPropelledArtilleryUnit.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/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/StrategyStatus.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/StrategyStatus.cs
new file mode 100644
index 0000000..6315c8d
--- /dev/null
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/MovementStrategy/StrategyStatus.cs
@@ -0,0 +1,21 @@
+namespace SelfPropelledArtilleryUnit.MovementStrategy;
+///
+/// Статус выполнения операции перемещения
+///
+public enum StrategyStatus
+{
+ ///
+ /// Все готово к началу
+ ///
+ NotInit,
+
+ ///
+ /// Выполняется
+ ///
+ InProgress,
+
+ ///
+ /// Завершено
+ ///
+ Finish
+}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs
index b2f161a..10f2ab7 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.Designer.cs
@@ -34,6 +34,9 @@
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
+ button1 = new Button();
+ comboBoxStrategy = new ComboBox();
+ buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxSelfPropelledArtilleryUnit).BeginInit();
SuspendLayout();
//
@@ -49,13 +52,13 @@
// buttonCreate
//
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(12, 438);
+ buttonCreate.Location = new Point(12, 446);
buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(94, 43);
+ buttonCreate.Size = new Size(226, 35);
buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать";
+ buttonCreate.Text = "Создать самоходную арт. установку";
buttonCreate.UseVisualStyleBackColor = true;
- buttonCreate.Click += buttonCreate_Click;
+ buttonCreate.Click += buttonCreateSelfPropelledArtilleryUnit_Click;
//
// buttonLeft
//
@@ -105,11 +108,46 @@
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
+ // button1
+ //
+ button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
+ button1.Location = new Point(253, 446);
+ button1.Name = "button1";
+ button1.Size = new Size(226, 35);
+ button1.TabIndex = 6;
+ button1.Text = "Создать бронированную машину";
+ button1.UseVisualStyleBackColor = true;
+ button1.Click += buttonCreatePropelledArtillery_Click;
+ //
+ // comboBoxStrategy
+ //
+ comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxStrategy.FormattingEnabled = true;
+ comboBoxStrategy.Items.AddRange(new object[] { "К центру ", "К краю" });
+ comboBoxStrategy.Location = new Point(784, 12);
+ comboBoxStrategy.Name = "comboBoxStrategy";
+ comboBoxStrategy.Size = new Size(121, 23);
+ comboBoxStrategy.TabIndex = 7;
+ comboBoxStrategy.SelectedIndexChanged += comboBoxStrategy_SelectedIndexChanged;
+ //
+ // buttonStrategyStep
+ //
+ buttonStrategyStep.Location = new Point(829, 41);
+ buttonStrategyStep.Name = "buttonStrategyStep";
+ buttonStrategyStep.Size = new Size(75, 23);
+ buttonStrategyStep.TabIndex = 8;
+ buttonStrategyStep.Text = "Шаг";
+ buttonStrategyStep.UseVisualStyleBackColor = true;
+ buttonStrategyStep.Click += buttonStrategyStep_Click;
+ //
// SelfPropelledArtilleryUnit
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(923, 493);
+ Controls.Add(buttonStrategyStep);
+ Controls.Add(comboBoxStrategy);
+ Controls.Add(button1);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
@@ -130,5 +168,8 @@
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
+ private Button button1;
+ private ComboBox comboBoxStrategy;
+ private Button buttonStrategyStep;
}
}
\ No newline at end of file
diff --git a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.cs b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.cs
index ae685fb..e6cbfc4 100644
--- a/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.cs
+++ b/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit/SelfPropelledArtilleryUnit.cs
@@ -7,45 +7,84 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
+using SelfPropelledArtilleryUnit.Drawnings;
+using SelfPropelledArtilleryUnit.MovementStrategy;
namespace SelfPropelledArtilleryUnit
{
public partial class SelfPropelledArtilleryUnit : Form
{
- private DrawningSelfPropelledArtilleryUnit? _drawningSelfPropelledArtilleryUnit;
+ private DrawningPropelledArtillery? _drawningPropelledArtillery;
+ ///
+ /// Стратегия перемещения
+ ///
+ private AbstractStrategy? _strategy;
+
+ ///
+ /// Конструктор формы
+ ///
public SelfPropelledArtilleryUnit()
{
InitializeComponent();
+ _strategy = null;
}
+
private void Draw()
{
- if (_drawningSelfPropelledArtilleryUnit == null)
+ if (_drawningPropelledArtillery == null)
{
return;
}
Bitmap bmp = new(pictureBoxSelfPropelledArtilleryUnit.Width, pictureBoxSelfPropelledArtilleryUnit.Height);
Graphics gr = Graphics.FromImage(bmp);
- _drawningSelfPropelledArtilleryUnit.DrawTransport(gr);
+ _drawningPropelledArtillery.DrawTransport(gr);
pictureBoxSelfPropelledArtilleryUnit.Image = bmp;
}
-
- private void buttonCreate_Click(object sender, EventArgs e)
+ private void CreateObject(string type)
{
Random random = new();
- _drawningSelfPropelledArtilleryUnit = new DrawningSelfPropelledArtilleryUnit();
- _drawningSelfPropelledArtilleryUnit.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)));
- _drawningSelfPropelledArtilleryUnit.SetPictureSize(pictureBoxSelfPropelledArtilleryUnit.Width, pictureBoxSelfPropelledArtilleryUnit.Height);
- _drawningSelfPropelledArtilleryUnit.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ switch (type)
+ {
+ case nameof(DrawningPropelledArtillery):
+ _drawningPropelledArtillery = new DrawningPropelledArtillery(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(DrawningSelfPropelledArtilleryUnit):
+ _drawningPropelledArtillery = new DrawningSelfPropelledArtilleryUnit(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;
+ }
+
+ _drawningPropelledArtillery.SetPictureSize(pictureBoxSelfPropelledArtilleryUnit.Width, pictureBoxSelfPropelledArtilleryUnit.Height);
+ _drawningPropelledArtillery.SetPosition(random.Next(10, 100), random.Next(10, 100));
+ _strategy = null;
+ comboBoxStrategy.Enabled = true;
Draw();
}
+
+ ///
+ /// Обработка нажатия кнопки "Создать самоходную арт.установку"
+ ///
+ ///
+ ///
+ private void buttonCreateSelfPropelledArtilleryUnit_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSelfPropelledArtilleryUnit));
+
+ ///
+ /// Обработка нажатия кнопки "Создать бронированную машину"
+ ///
+ ///
+ ///
+ private void buttonCreatePropelledArtillery_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPropelledArtillery));
+
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_drawningSelfPropelledArtilleryUnit == null)
+ if (_drawningPropelledArtillery == null)
{
return;
}
@@ -55,13 +94,13 @@ namespace SelfPropelledArtilleryUnit
switch (name)
{
case "buttonUp":
- result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Up); break;
+ result = _drawningPropelledArtillery.MoveTransport(DirectionType.Up); break;
case "buttonDown":
- result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Down); break;
+ result = _drawningPropelledArtillery.MoveTransport(DirectionType.Down); break;
case "buttonLeft":
- result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Left); break;
+ result = _drawningPropelledArtillery.MoveTransport(DirectionType.Left); break;
case "buttonRight":
- result = _drawningSelfPropelledArtilleryUnit.MoveTransport(DirectionType.Right); break;
+ result = _drawningPropelledArtillery.MoveTransport(DirectionType.Right); break;
}
if (result)
@@ -69,5 +108,53 @@ namespace SelfPropelledArtilleryUnit
Draw();
}
}
+
+ ///
+ /// Обработка нажатия кнопки "Шаг"
+ ///
+ ///
+ ///
+ private void buttonStrategyStep_Click(object sender, EventArgs e)
+ {
+ if (_drawningPropelledArtillery == null)
+ {
+ return;
+ }
+
+ if (comboBoxStrategy.Enabled)
+ {
+ _strategy = comboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_strategy == null)
+ {
+ return;
+ }
+ _strategy.SetData(new MoveablePropelledArtillery(_drawningPropelledArtillery), pictureBoxSelfPropelledArtilleryUnit.Width, pictureBoxSelfPropelledArtilleryUnit.Height);
+ }
+
+ if (_strategy == null)
+ {
+ return;
+ }
+
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+
+ if (_strategy.GetStatus() == StrategyStatus.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+ }
+
+ private void comboBoxStrategy_SelectedIndexChanged(object sender, EventArgs e)
+ {
+
+ }
}
}