PIBD-13_Fomichev_V.S._LabWork02_Simple_ #3
@ -1,10 +1,12 @@
|
||||
|
||||
namespace AntiAircraftGun;
|
||||
namespace AntiAircraftGun.Drawnings;
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
{ /// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
@ -1,56 +1,96 @@
|
||||
namespace AntiAircraftGun;
|
||||
/// <summary>
|
||||
/// Класс отвечающий за прорисовку и перемещение объекта - сущности
|
||||
/// </summary>
|
||||
public class DrawningAntiAircraftGun
|
||||
using AntiAircraftGun.Entities;
|
||||
|
||||
namespace AntiAircraftGun.Drawnings;
|
||||
|
||||
public class DrawningAircraftGun
|
||||
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс - сущность
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAntiAircraftGun? EntityAntiAircraftGun { get; set; }
|
||||
public EntityAircraftGun? EntityAircraftGun { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// Ширина
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// Высота
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки зенитной установки
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя координата прорисовки зенитной установки
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки зенитной установки
|
||||
/// </summary>
|
||||
private readonly int _drawningGunWidth = 130;
|
||||
private readonly int _drawningGunWidth = 129;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки зенитной установки
|
||||
/// </summary>
|
||||
private readonly int _drawningGunHeight = 100;
|
||||
private readonly int _drawningGunHeight = 105;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса зенитной установки
|
||||
/// Координата Х объекта
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Наличие обвеса</param>
|
||||
/// <param name="tower">Наличие башни</param>
|
||||
/// <param name="radar">Наличие радара</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool tower, bool radar)
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningGunWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningGunHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningAircraftGun()
|
||||
{
|
||||
EntityAntiAircraftGun = new EntityAntiAircraftGun();
|
||||
EntityAntiAircraftGun.Init(speed, weight, bodyColor, additionalColor, bodyKit, tower, radar);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningAircraftGun(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityAircraftGun = new EntityAircraftGun(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningGunWidth">Ширина прорисовки зенитной установки</param>
|
||||
/// <param name="drawningGunHeight">Высота прорисовки зенитной установки</param>
|
||||
protected DrawningAircraftGun(int drawningGunWidth, int drawningGunHeight) : this()
|
||||
{
|
||||
_drawningGunWidth = drawningGunWidth;
|
||||
_drawningGunHeight = drawningGunHeight;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
@ -59,8 +99,7 @@ public class DrawningAntiAircraftGun
|
||||
/// <returns></returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта,если она была уже установлена
|
||||
|
||||
if (width < _drawningGunWidth || height < _drawningGunHeight) { return false; };
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
@ -93,8 +132,7 @@ public class DrawningAntiAircraftGun
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
@ -133,34 +171,34 @@ public class DrawningAntiAircraftGun
|
||||
/// <returns></returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAntiAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityAntiAircraftGun.Step > 0)
|
||||
if (_startPosX.Value - EntityAircraftGun.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityAntiAircraftGun.Step;
|
||||
_startPosX -= (int)EntityAircraftGun.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + _drawningGunWidth + EntityAntiAircraftGun.Step < _pictureWidth)
|
||||
if (_startPosX.Value + _drawningGunWidth + EntityAircraftGun.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityAntiAircraftGun.Step;
|
||||
_startPosX += (int)EntityAircraftGun.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + _drawningGunHeight + EntityAntiAircraftGun.Step < _pictureHeight)
|
||||
if (_startPosY.Value + _drawningGunHeight + EntityAircraftGun.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityAntiAircraftGun.Step;
|
||||
_startPosY += (int)EntityAircraftGun.Step;
|
||||
}
|
||||
return true;
|
||||
case DirectionType.Up: //вверх
|
||||
if (_startPosY - EntityAntiAircraftGun.Step > 0)
|
||||
case DirectionType.Up:
|
||||
if (_startPosY - EntityAircraftGun.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAntiAircraftGun.Step;
|
||||
_startPosY -= (int)EntityAircraftGun.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -171,22 +209,21 @@ public class DrawningAntiAircraftGun
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAntiAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityAntiAircraftGun.AdditionalColor);
|
||||
|
||||
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 75, 30, 30);
|
||||
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 75, 30, 30);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 75, 90, 30);
|
||||
|
||||
//границы ЦВЕТ
|
||||
Brush brDarkSlateGray = new SolidBrush(EntityAntiAircraftGun.BodyColor);
|
||||
Brush brDarkSlateGray = new SolidBrush(EntityAircraftGun.BodyColor);
|
||||
g.FillRectangle(brDarkSlateGray, _startPosX.Value + 35, _startPosY.Value + 40, 35, 30);
|
||||
g.FillEllipse(brDarkSlateGray, _startPosX.Value + 10, _startPosY.Value + 75, 30, 30);
|
||||
g.FillEllipse(brDarkSlateGray, _startPosX.Value + 100, _startPosY.Value + 75, 30, 30);
|
||||
@ -219,27 +256,8 @@ public class DrawningAntiAircraftGun
|
||||
g.DrawEllipse(pen, _startPosX.Value + 103, _startPosY.Value + 78, 24, 24);
|
||||
|
||||
g.FillRectangle(brDarkSlateGray, _startPosX.Value + 10, _startPosY.Value + 65, 120, 13);
|
||||
|
||||
|
||||
if (EntityAntiAircraftGun.Tower)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 50, 35, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 50, 35, 15);
|
||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 50, _startPosX.Value + 90, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 50);
|
||||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 20, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 20, _startPosX.Value + 100, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
|
||||
}
|
||||
|
||||
if (EntityAntiAircraftGun.Radar)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX.Value + 20, _startPosY.Value + 65, _startPosX.Value + 20, _startPosY.Value + 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 20, 20);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
63
AntiAircraftGun/Drawnings/DrawningAntiAircraftGun.cs
Normal file
63
AntiAircraftGun/Drawnings/DrawningAntiAircraftGun.cs
Normal file
@ -0,0 +1,63 @@
|
||||
using AntiAircraftGun.Entities;
|
||||
|
||||
namespace AntiAircraftGun.Drawnings;
|
||||
/// <summary>
|
||||
/// Класс отвечающий за прорисовку и перемещение объекта - сущности
|
||||
/// </summary>
|
||||
public class DrawningAntiAircraftGun : DrawningAircraftGun
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="tower">Признак наличия башни</param>
|
||||
/// <param name="radar">Признак наличия радара</param>
|
||||
|
||||
public DrawningAntiAircraftGun(int speed, double weight, Color bodyColor, Color additionalColor, bool radar, bool tower) : base(129, 105)
|
||||
{
|
||||
EntityAircraftGun = new EntityAntiAircraftGun(speed, weight, bodyColor, radar, tower, additionalColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAircraftGun == null || EntityAircraftGun is not EntityAntiAircraftGun aircraftGun || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(aircraftGun.AdditionalColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
|
||||
if (aircraftGun.Tower)
|
||||
{
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 50, 35, 15);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 50, 35, 15);
|
||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 50, _startPosX.Value + 90, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 50);
|
||||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 20, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 20, _startPosX.Value + 100, _startPosY.Value + 20);
|
||||
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 95, _startPosY.Value + 27);
|
||||
|
||||
}
|
||||
|
||||
if (aircraftGun.Radar)
|
||||
{
|
||||
g.DrawLine(pen, _startPosX.Value + 20, _startPosY.Value + 65, _startPosX.Value + 20, _startPosY.Value + 40);
|
||||
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 40, 20, 20);
|
||||
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 20, 20);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
36
AntiAircraftGun/Entities/EntityAircraftGun.cs
Normal file
36
AntiAircraftGun/Entities/EntityAircraftGun.cs
Normal file
@ -0,0 +1,36 @@
|
||||
namespace AntiAircraftGun.Entities;
|
||||
/// <summary>
|
||||
/// Класс - сущность Бронированная машина
|
||||
/// </summary>
|
||||
public class EntityAircraftGun
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Перемещение зенитной установки
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed"></param>
|
||||
/// <param name="weight"></param>
|
||||
/// <param name="bodyColor"></param>
|
||||
public EntityAircraftGun(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
@ -1,29 +1,14 @@
|
||||
namespace AntiAircraftGun;
|
||||
namespace AntiAircraftGun.Entities;
|
||||
/// <summary>
|
||||
/// Класс-сущность Зенитная установка
|
||||
/// </summary>
|
||||
public class EntityAntiAircraftGun
|
||||
{ /// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
public class EntityAntiAircraftGun : EntityAircraftGun
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополниетльный цвет
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Наличие обвеса
|
||||
/// </summary>
|
||||
public bool BodyKit { get; private set; }
|
||||
/// <summary>
|
||||
/// Наличие башни
|
||||
/// </summary>
|
||||
public bool Tower { get; private set; }
|
||||
@ -31,28 +16,20 @@ public class EntityAntiAircraftGun
|
||||
/// Наличие радара
|
||||
/// </summary>
|
||||
public bool Radar { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения гидросамолета
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса гидросамолета
|
||||
/// Инициализация полей объекта-класса зенитной установки
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="bodyKit">Наличие обвеса</param>
|
||||
/// <param name="tower">Наличие башни</param>
|
||||
/// <param name="radar">Наличие радара</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool tower, bool radar)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
BodyKit = bodyKit;
|
||||
Tower = tower;
|
||||
public EntityAntiAircraftGun(int speed, double weight, Color bodyColor, bool radar, bool tower, Color additionalColor) : base(speed, weight, bodyColor)
|
||||
{
|
||||
Radar = radar;
|
||||
Tower = tower;
|
||||
AdditionalColor = additionalColor;
|
||||
}
|
||||
}
|
66
AntiAircraftGun/FormAntiAircraftGun.Designer.cs
generated
66
AntiAircraftGun/FormAntiAircraftGun.Designer.cs
generated
@ -29,11 +29,14 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxAntiAircraftGun = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonCreate = new Button();
|
||||
buttonCreatAircraftGun = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAntiAircraftGun).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -46,17 +49,6 @@
|
||||
pictureBoxAntiAircraftGun.TabIndex = 0;
|
||||
pictureBoxAntiAircraftGun.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 406);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(95, 32);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
@ -105,11 +97,56 @@
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 406);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(215, 32);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать зенитную установку";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
// buttonCreatAircraftGun
|
||||
//
|
||||
buttonCreatAircraftGun.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreatAircraftGun.Location = new Point(233, 406);
|
||||
buttonCreatAircraftGun.Name = "buttonCreatAircraftGun";
|
||||
buttonCreatAircraftGun.Size = new Size(215, 32);
|
||||
buttonCreatAircraftGun.TabIndex = 6;
|
||||
buttonCreatAircraftGun.Text = "Создать бронированную машину";
|
||||
buttonCreatAircraftGun.UseVisualStyleBackColor = true;
|
||||
buttonCreatAircraftGun.Click += buttonCreatAircraftGun_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||
comboBoxStrategy.Location = new Point(667, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Location = new Point(713, 41);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(75, 23);
|
||||
buttonStrategyStep.TabIndex = 8;
|
||||
buttonStrategyStep.Text = "Шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += buttonStrategyStep_Click;
|
||||
//
|
||||
// FormAntiAircraftGun
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonCreatAircraftGun);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
@ -125,10 +162,13 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxAntiAircraftGun;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonUp;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCreatAircraftGun;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
}
|
@ -1,81 +1,155 @@
|
||||
namespace AntiAircraftGun
|
||||
{
|
||||
public partial class FormAntiAircraftGun : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningAntiAircraftGun? _drawningAntiAircraftGun;
|
||||
/// <summary>
|
||||
/// конструктор формы
|
||||
/// </summary>
|
||||
public FormAntiAircraftGun()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки транспорта
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAntiAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAntiAircraftGun.DrawTransport(gr);
|
||||
pictureBoxAntiAircraftGun.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка кнопик Создать
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningAntiAircraftGun = new DrawningAntiAircraftGun();
|
||||
_drawningAntiAircraftGun.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 255),
|
||||
random.Next(0, 255), random.Next(0, 255)), Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningAntiAircraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
_drawningAntiAircraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
using AntiAircraftGun.Drawnings;
|
||||
using AntiAircraftGun.MovementStrategy;
|
||||
|
||||
namespace AntiAircraftGun;
|
||||
|
||||
public partial class FormAntiAircraftGun : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningAircraftGun? _drawningAircraftGun;
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
/// <summary>
|
||||
/// конструктор формы
|
||||
/// </summary>
|
||||
public FormAntiAircraftGun()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод прорисовки транспорта
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAircraftGun.DrawTransport(gr);
|
||||
pictureBoxAntiAircraftGun.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод создания объекта
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningAircraftGun):
|
||||
_drawningAircraftGun = new DrawningAircraftGun(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(DrawningAntiAircraftGun):
|
||||
_drawningAircraftGun = new DrawningAntiAircraftGun(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;
|
||||
}
|
||||
|
||||
_drawningAircraftGun.SetPictureSize(pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
_drawningAircraftGun.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка кнопик Создать Зенитную установку
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAntiAircraftGun));
|
||||
/// <summary>
|
||||
/// Обработка кнопик Создать установку
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonCreatAircraftGun_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraftGun));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningAircraftGun.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
}
|
||||
/// <summary>
|
||||
/// Метод выбора стратегии
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAircraftGun == null)
|
||||
{
|
||||
if (_drawningAntiAircraftGun == null)
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningAntiAircraftGun.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
_strategy.SetData(new MoveableAircraftGun(_drawningAircraftGun), pictureBoxAntiAircraftGun.Width, pictureBoxAntiAircraftGun.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
}
|
121
AntiAircraftGun/MovementStrategy/AbstractStrategy.cs
Normal file
121
AntiAircraftGun/MovementStrategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,121 @@
|
||||
namespace AntiAircraftGun.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-стратегия перемещения объекта
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject? _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="movementDirection">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||
private bool MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||
}
|
||||
}
|
19
AntiAircraftGun/MovementStrategy/IMoveableObject.cs
Normal file
19
AntiAircraftGun/MovementStrategy/IMoveableObject.cs
Normal file
@ -0,0 +1,19 @@
|
||||
namespace AntiAircraftGun.MovementStrategy;
|
||||
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Попытка переместить объект в указанном направлении
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
50
AntiAircraftGun/MovementStrategy/MoveToBorder.cs
Normal file
50
AntiAircraftGun/MovementStrategy/MoveToBorder.cs
Normal file
@ -0,0 +1,50 @@
|
||||
namespace AntiAircraftGun.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
AntiAircraftGun/MovementStrategy/MoveToCenter.cs
Normal file
56
AntiAircraftGun/MovementStrategy/MoveToCenter.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AntiAircraftGun.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
58
AntiAircraftGun/MovementStrategy/MoveableAircraftGun.cs
Normal file
58
AntiAircraftGun/MovementStrategy/MoveableAircraftGun.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using AntiAircraftGun.Drawnings;
|
||||
|
||||
namespace AntiAircraftGun.MovementStrategy;
|
||||
|
||||
public class MoveableAircraftGun: IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningAircraftGun или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningAircraftGun? _drawningAircraftGun = null;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="trans">Объект класса DrawningTrans</param>
|
||||
public MoveableAircraftGun(DrawningAircraftGun trans)
|
||||
{
|
||||
_drawningAircraftGun = trans;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_drawningAircraftGun == null || _drawningAircraftGun.EntityAircraftGun == null ||
|
||||
!_drawningAircraftGun.GetPosX.HasValue || !_drawningAircraftGun.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_drawningAircraftGun.GetPosX.Value,
|
||||
_drawningAircraftGun.GetPosY.Value, _drawningAircraftGun.GetWidth, _drawningAircraftGun.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_drawningAircraftGun?.EntityAircraftGun?.Step ?? 0);
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_drawningAircraftGun == null || _drawningAircraftGun.EntityAircraftGun == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _drawningAircraftGun.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
/// </summary>
|
||||
/// <param name="direction">MovementDirection</param>
|
||||
/// <returns>DirectionType</returns>
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
21
AntiAircraftGun/MovementStrategy/MovementDirection.cs
Normal file
21
AntiAircraftGun/MovementStrategy/MovementDirection.cs
Normal file
@ -0,0 +1,21 @@
|
||||
namespace AntiAircraftGun.MovementStrategy;
|
||||
|
||||
public enum MovementDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
59
AntiAircraftGun/MovementStrategy/ObjectParameters.cs
Normal file
59
AntiAircraftGun/MovementStrategy/ObjectParameters.cs
Normal file
@ -0,0 +1,59 @@
|
||||
namespace AntiAircraftGun.MovementStrategy;
|
||||
|
||||
public class ObjectParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Координата X
|
||||
/// </summary>
|
||||
private readonly int _x;
|
||||
/// <summary>
|
||||
/// Координата Y
|
||||
/// </summary>
|
||||
private readonly int _y;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
private readonly int _width;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина объекта</param>
|
||||
/// <param name="height">Высота объекта</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
17
AntiAircraftGun/MovementStrategy/StrategyStatus.cs
Normal file
17
AntiAircraftGun/MovementStrategy/StrategyStatus.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace AntiAircraftGun.MovementStrategy;
|
||||
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Все готово к началу
|
||||
/// </summary>
|
||||
NotInit,
|
||||
/// <summary>
|
||||
/// Выполняется
|
||||
/// </summary>
|
||||
InProgress,
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user
Имя элемента проекта не соответствует указанному в задании