PIbd-11_Nekrasov_A.A._LabWork02_Simple #2
32
ProjectAirPlane/ProjectAirPlane/Drawnings/DirectionType.cs
Normal file
32
ProjectAirPlane/ProjectAirPlane/Drawnings/DirectionType.cs
Normal file
@ -0,0 +1,32 @@
|
||||
namespace ProjectAirPlane.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
using ProjectAirPlane.Entites;
|
||||
|
||||
namespace ProjectAirPlane.Drawnings;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningAirPlane : DrawningPlane
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="radar">Признак наличия обвеса</param>
|
||||
/// <param name="dopBak">Признак наличия антикрыла</param>
|
||||
/// <param name="chassi">Признак наличия гоночной полосы</param>
|
||||
public DrawningAirPlane(int speed, double weight, Color bodyColor, Color additionalColor, bool radar, bool dopBak, bool chassi) : base(195, 70)
|
||||
{
|
||||
EntityPlane = new EntityAirPlane(speed, weight, bodyColor, additionalColor, radar, dopBak, chassi);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityPlane == null || EntityPlane is not EntityAirPlane airPlane || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityPlane.BodyColor);
|
||||
|
||||
if (airPlane.Chassi)
|
||||
{
|
||||
//шасси
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 55, _startPosX.Value + 50, _startPosY.Value + 70);
|
||||
g.DrawLine(pen, _startPosX.Value + 150, _startPosY.Value + 55, _startPosX.Value + 150, _startPosY.Value + 70);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 65, 10, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 65, 10, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 145, _startPosY.Value + 65, 10, 10);
|
||||
|
||||
}
|
||||
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
|
||||
|
||||
if (airPlane.DopBak)
|
||||
{
|
||||
//бак
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 45, 40, 20);
|
||||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 45, 40, 20);
|
||||
|
||||
}
|
||||
|
||||
if (airPlane.Radar)
|
||||
{
|
||||
//радар
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 25, _startPosX.Value + 60, _startPosY.Value + 15);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 15, _startPosX.Value + 67, _startPosY.Value + 11);
|
||||
Point point7 = new Point(_startPosX.Value + 60, _startPosY.Value + 15);
|
||||
Point point8 = new Point(_startPosX.Value + 60, _startPosY.Value + 5);
|
||||
Point point9 = new Point(_startPosX.Value + 70, _startPosY.Value + 25);
|
||||
Point[] curvePoints3 =
|
||||
{
|
||||
point7,
|
||||
point8,
|
||||
point9,
|
||||
};
|
||||
g.FillPolygon(additionalBrush, curvePoints3);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,65 +1,104 @@
|
||||
namespace ProjectAirPlane;
|
||||
using ProjectAirPlane.Entites;
|
||||
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningAirPlane
|
||||
namespace ProjectAirPlane.Drawnings;
|
||||
|
||||
public class DrawningPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityAirPlane? EntityAirPlane { get; private set; }
|
||||
public EntityPlane? EntityPlane { 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 _drawningAirPlaneWidth = 197;
|
||||
private readonly int _drawningAirPlaneWidth = 195;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки самолёта
|
||||
/// </summary>
|
||||
private readonly int _drawningAirPlaneHeight = 65;
|
||||
private readonly int _drawningAirPlaneHeight = 70;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="radar">Признак наличия обвеса</param>
|
||||
/// <param name="dopBak">Признак наличия доп бака</param>
|
||||
/// <param name="chassi">Признак наличия шасси</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool radar, bool dopBak, bool chassi)
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningAirPlaneWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningAirPlaneHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningPlane()
|
||||
{
|
||||
EntityAirPlane = new EntityAirPlane();
|
||||
EntityAirPlane.Init(speed, weight, bodyColor, additionalColor, radar, dopBak, chassi);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public DrawningPlane(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследования
|
||||
/// </summary>
|
||||
/// <param name="drawningAirPlaneWidth">Ширина прорисовки самолёта </param>
|
||||
/// <param name="drawningAirPlaneHeight">Высота прорисовки самолёта</param>
|
||||
|
||||
|
||||
protected DrawningPlane(int drawningPlaneWidth, int drawningPlaneHeight) : this()
|
||||
{
|
||||
_drawningAirPlaneWidth = drawningPlaneWidth;
|
||||
_drawningAirPlaneHeight = drawningPlaneHeight;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
@ -69,6 +108,7 @@ public class DrawningAirPlane
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
|
||||
if (_drawningAirPlaneWidth > width || _drawningAirPlaneHeight > height)
|
||||
{
|
||||
return false;
|
||||
@ -90,7 +130,6 @@ public class DrawningAirPlane
|
||||
else if (_startPosY < 0) _startPosY = 0;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -107,20 +146,15 @@ public class DrawningAirPlane
|
||||
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
|
||||
if (x + _drawningAirPlaneWidth > _pictureWidth)
|
||||
if (x + _drawningAirPlaneWidth >= _pictureWidth || y + _drawningAirPlaneHeight >= _pictureHeight)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningAirPlaneWidth;
|
||||
x = y = 10;
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
else if (x < 0) _startPosX = 0;
|
||||
else _startPosX = x;
|
||||
|
||||
if (x + _drawningAirPlaneHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningAirPlaneHeight;
|
||||
}
|
||||
else if (y < 0) _startPosX = 0;
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -130,7 +164,7 @@ public class DrawningAirPlane
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityAirPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -139,32 +173,32 @@ public class DrawningAirPlane
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityAirPlane.Step > 0)
|
||||
if (_startPosX.Value - EntityPlane.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityAirPlane.Step;
|
||||
_startPosX -= (int)EntityPlane.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityAirPlane.Step > 0)
|
||||
if (_startPosY.Value - EntityPlane.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityAirPlane.Step;
|
||||
_startPosY -= (int)EntityPlane.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
//TODO прописать логику сдвига вправо
|
||||
if (_startPosX + EntityAirPlane.Step + _drawningAirPlaneWidth < _pictureWidth)
|
||||
if (_startPosX + EntityPlane.Step + _drawningAirPlaneWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityAirPlane.Step;
|
||||
_startPosX += (int)EntityPlane.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
//TODO прописать логику сдвига ввниз
|
||||
if (_startPosY + EntityAirPlane.Step + _drawningAirPlaneHeight < _pictureHeight)
|
||||
if (_startPosY + EntityPlane.Step + _drawningAirPlaneHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityAirPlane.Step;
|
||||
_startPosY += (int)EntityPlane.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -176,18 +210,25 @@ public class DrawningAirPlane
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityAirPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Brush additionalBrush = new SolidBrush(EntityAirPlane.AdditionalColor);
|
||||
Brush additionalBrush = new SolidBrush(EntityPlane.BodyColor);
|
||||
|
||||
|
||||
//шасси
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 55, _startPosX.Value + 50, _startPosY.Value + 70);
|
||||
g.DrawLine(pen, _startPosX.Value + 150, _startPosY.Value + 55, _startPosX.Value + 150, _startPosY.Value + 70);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 40, _startPosY.Value + 65, 10, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 65, 10, 10);
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value + 145, _startPosY.Value + 65, 10, 10);
|
||||
// корпус
|
||||
Brush br = new SolidBrush(EntityAirPlane.BodyColor);
|
||||
Brush br = new SolidBrush(EntityPlane.BodyColor);
|
||||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 25, 170, 30);
|
||||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 25, 170, 30);
|
||||
// бак
|
||||
@ -209,45 +250,13 @@ public class DrawningAirPlane
|
||||
g.DrawPolygon(blackPen, curvePoints);
|
||||
g.DrawLine(blackPen, _startPosX.Value + 170, _startPosY.Value + 40, _startPosX.Value + 200, _startPosY.Value + 40);
|
||||
// хвост
|
||||
Brush bw = new SolidBrush(EntityAirPlane.BodyColor);
|
||||
Brush bw = new SolidBrush(EntityPlane.BodyColor);
|
||||
g.FillPolygon(bw, new Point[]
|
||||
{
|
||||
new Point((int) _startPosX, (int) _startPosY + 40 ), new Point((int) _startPosX + 80, (int) _startPosY + 30),
|
||||
new Point((int) _startPosX, (int) _startPosY), new Point((int) _startPosX , (int) _startPosY + 40),
|
||||
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
// шасси
|
||||
g.DrawLine(blackPen, _startPosX.Value + 50, _startPosY.Value + 55, _startPosX.Value + 50, _startPosY.Value + 70);
|
||||
g.DrawLine(blackPen, _startPosX.Value + 150, _startPosY.Value + 55, _startPosX.Value + 150, _startPosY.Value + 70);
|
||||
g.FillEllipse(blackBrush, _startPosX.Value + 40, _startPosY.Value + 65, 10, 10);
|
||||
g.FillEllipse(blackBrush, _startPosX.Value + 50, _startPosY.Value + 65, 10, 10);
|
||||
g.FillEllipse(blackBrush, _startPosX.Value + 145, _startPosY.Value + 65, 10, 10);
|
||||
if (EntityAirPlane.DopBak)
|
||||
{
|
||||
//бак
|
||||
g.FillEllipse(additionalBrush, _startPosX.Value, _startPosY.Value + 45, 40, 20);
|
||||
g.DrawEllipse(blackPen, _startPosX.Value, _startPosY.Value + 45, 40, 20);
|
||||
}
|
||||
if (EntityAirPlane.Radar)
|
||||
{
|
||||
//радар
|
||||
g.DrawLine(blackPen, _startPosX.Value + 60, _startPosY.Value + 25, _startPosX.Value + 60, _startPosY.Value + 15);
|
||||
g.DrawLine(blackPen, _startPosX.Value + 60, _startPosY.Value + 15, _startPosX.Value + 67, _startPosY.Value + 11);
|
||||
Point point7 = new Point(_startPosX.Value + 60, _startPosY.Value + 15);
|
||||
Point point8 = new Point(_startPosX.Value + 60, _startPosY.Value + 5);
|
||||
Point point9 = new Point(_startPosX.Value + 70, _startPosY.Value + 25);
|
||||
Point[] curvePoints3 =
|
||||
{
|
||||
point7,
|
||||
point8,
|
||||
point9,
|
||||
};
|
||||
g.FillPolygon(additionalBrush, curvePoints3);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
52
ProjectAirPlane/ProjectAirPlane/Entites/EntityAirPlane.cs
Normal file
52
ProjectAirPlane/ProjectAirPlane/Entites/EntityAirPlane.cs
Normal file
@ -0,0 +1,52 @@
|
||||
namespace ProjectAirPlane.Entites;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Спортивный самолёт"
|
||||
/// </summary>
|
||||
public class EntityAirPlane : EntityPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия обвеса
|
||||
/// </summary>
|
||||
public bool Radar { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия антикрыла
|
||||
/// </summary>
|
||||
public bool DopBak { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия гоночной полосы
|
||||
/// </summary>
|
||||
public bool Chassi { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения автомобиля
|
||||
/// </summary>
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация полей объекта-класса спортивного автомобиля
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес автомобиля</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="radar">Признак наличия обвеса</param>
|
||||
/// <param name="dopBak">Признак наличия антикрыла</param>
|
||||
/// <param name="chassi">Признак наличия гоночной полосы</param>
|
||||
public EntityAirPlane(int speed, double weight, Color bodyColor, Color additionalColor, bool radar, bool dopBak, bool chassi) : base(speed, weight, bodyColor)
|
||||
{
|
||||
|
||||
AdditionalColor = additionalColor;
|
||||
Radar = radar;
|
||||
DopBak = dopBak;
|
||||
Chassi = chassi;
|
||||
|
||||
}
|
||||
}
|
43
ProjectAirPlane/ProjectAirPlane/Entites/EntityPlane.cs
Normal file
43
ProjectAirPlane/ProjectAirPlane/Entites/EntityPlane.cs
Normal file
@ -0,0 +1,43 @@
|
||||
namespace ProjectAirPlane.Entites;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Обычный самолёт"
|
||||
/// </summary>
|
||||
public class EntityPlane
|
||||
{
|
||||
/// <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 EntityPlane(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
namespace ProjectAirPlane;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Самолёт"
|
||||
/// </summary>
|
||||
public class EntityAirPlane
|
||||
{
|
||||
/// <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 Color AdditionalColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия радара
|
||||
/// </summary>
|
||||
public bool Radar { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия доп бака
|
||||
/// </summary>
|
||||
public bool DopBak { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Признак (опция) наличия шасси
|
||||
/// </summary>
|
||||
public bool Chassi { 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="radar">Признак наличия радара</param>
|
||||
/// <param name="dopBak">Признак наличия доп бака</param>
|
||||
/// <param name="chassi">Признак наличия шасси</param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool radar, bool dopBak, bool chassi)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
Radar = radar;
|
||||
DopBak = dopBak;
|
||||
Chassi = chassi;
|
||||
|
||||
}
|
||||
}
|
@ -35,6 +35,9 @@
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
ButtonCreatePlane = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStepS = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxAirPlane).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -52,9 +55,9 @@
|
||||
buttonCreateAirPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateAirPlane.Location = new Point(12, 488);
|
||||
buttonCreateAirPlane.Name = "buttonCreateAirPlane";
|
||||
buttonCreateAirPlane.Size = new Size(75, 23);
|
||||
buttonCreateAirPlane.Size = new Size(180, 23);
|
||||
buttonCreateAirPlane.TabIndex = 1;
|
||||
buttonCreateAirPlane.Text = "Создать";
|
||||
buttonCreateAirPlane.Text = "Создать самолёт с радаром";
|
||||
buttonCreateAirPlane.UseVisualStyleBackColor = true;
|
||||
buttonCreateAirPlane.Click += ButtonCreateAirPlane_Click;
|
||||
//
|
||||
@ -106,11 +109,45 @@
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// ButtonCreatePlane
|
||||
//
|
||||
ButtonCreatePlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonCreatePlane.Location = new Point(198, 488);
|
||||
ButtonCreatePlane.Name = "ButtonCreatePlane";
|
||||
ButtonCreatePlane.Size = new Size(180, 23);
|
||||
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(628, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(121, 23);
|
||||
comboBoxStrategy.TabIndex = 7;
|
||||
//
|
||||
// buttonStrategyStepS
|
||||
//
|
||||
buttonStrategyStepS.Location = new Point(654, 41);
|
||||
buttonStrategyStepS.Name = "buttonStrategyStepS";
|
||||
buttonStrategyStepS.Size = new Size(75, 23);
|
||||
buttonStrategyStepS.TabIndex = 8;
|
||||
buttonStrategyStepS.Text = "Шаг";
|
||||
buttonStrategyStepS.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStepS.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// FormAirPlane
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(749, 523);
|
||||
Controls.Add(buttonStrategyStepS);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(ButtonCreatePlane);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
@ -131,5 +168,8 @@
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button ButtonCreatePlane;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStepS;
|
||||
}
|
||||
}
|
@ -1,14 +1,23 @@
|
||||
using ProjectAirPlane.Drawnings;
|
||||
using ProjectAirPlane.MovementStrategy;
|
||||
|
||||
|
||||
namespace ProjectAirPlane;
|
||||
|
||||
/// <summary>
|
||||
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Ñàìîë¸ò"
|
||||
/// Ôîðìà ðàáîòû ñ îáúåêòîì "Ñïîðòèâíûé àâòîìîáèëü"
|
||||
/// </summary>
|
||||
public partial class FormAirPlane : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Ïîëå-îáúåêò äëÿ ïğîğèñîâêè îáúåêòà
|
||||
/// </summary>
|
||||
private DrawningAirPlane? _drawningAirPlane;
|
||||
private DrawningPlane? _drawningPlane;
|
||||
|
||||
/// <summary>
|
||||
/// Ñòðàòåãèÿ ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
/// <summary>
|
||||
/// Êîíñòğóêòîğ ôîğìû
|
||||
@ -16,41 +25,70 @@ public partial class FormAirPlane : Form
|
||||
public FormAirPlane()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ìåòîä ïðîðèñîâêè ñàìîë¸òà
|
||||
/// Ìåòîä ïðîðèñîâêè ìàøèíû
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningAirPlane == null)
|
||||
if (_drawningPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxAirPlane.Width, pictureBoxAirPlane.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningAirPlane.DrawTransport(gr);
|
||||
_drawningPlane.DrawTransport(gr);
|
||||
pictureBoxAirPlane.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü"
|
||||
/// Ñîçäàíèå îáúåêòà êëàññà-ïåðåìåùåíèÿ
|
||||
/// </summary>
|
||||
/// <param name="type">Òèï ñîçäàâàåìîãî îáúåêòà</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningPlane):
|
||||
_drawningPlane = new DrawningPlane(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(DrawningAirPlane):
|
||||
_drawningPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawningPlane.SetPictureSize(pictureBoxAirPlane.Width, pictureBoxAirPlane.Height);
|
||||
_drawningPlane.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 ButtonCreateAirPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawningAirPlane = new DrawningAirPlane();
|
||||
_drawningAirPlane.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)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawningAirPlane.SetPictureSize(pictureBoxAirPlane.Width, pictureBoxAirPlane.Height);
|
||||
_drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
Draw();
|
||||
}
|
||||
private void ButtonCreateAirPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirPlane));
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü ñàìîë¸ò"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreatePlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Ïåğåìåùåíèå îáúåêòà ïî ôîğìå (íàæàòèå êíîïîê íàâèãàöèè)
|
||||
@ -59,7 +97,7 @@ public partial class FormAirPlane : Form
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningAirPlane == null)
|
||||
if (_drawningPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -69,16 +107,16 @@ public partial class FormAirPlane : Form
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningAirPlane.MoveTransport(DirectionType.Up);
|
||||
result = _drawningPlane.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningAirPlane.MoveTransport(DirectionType.Down);
|
||||
result = _drawningPlane.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningAirPlane.MoveTransport(DirectionType.Left);
|
||||
result = _drawningPlane.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningAirPlane.MoveTransport(DirectionType.Right);
|
||||
result = _drawningPlane.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -87,4 +125,46 @@ public partial class FormAirPlane : Form
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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), pictureBoxAirPlane.Width, pictureBoxAirPlane.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -121,7 +121,7 @@
|
||||
<data name="buttonLeft.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAP
|
||||
RQAAD0UBxeoB7wAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABSgSURBVHhe7d1N
|
||||
RAAAD0QBF63jCwAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABSgSURBVHhe7d1N
|
||||
yK95XQbwMxM1hINpJAjqSJb7IDB6A4NWtSlaWG1aFbSKZhMSFFQUmLqMWggVJRkSSdSmpIJIJSJJEsFX
|
||||
TI20RkNBGsPp+s95mf955jrnPC////2779/9ueCzON9n5jz3OXMP13Vm5jxz67nnngMAdqYeAYC51SMA
|
||||
MLd6BADmVo8AwNzqEQCYWz0CAHOrRwBgbvUIAMytHgGAudUjADC3egQA5laPAMDc6hEAmFs9AgBzq0cA
|
||||
@ -216,7 +216,7 @@
|
||||
<data name="buttonUp.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAP
|
||||
RQAAD0UBxeoB7wAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABrcSURBVHhe7d1N
|
||||
RAAAD0QBF63jCwAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABrcSURBVHhe7d1N
|
||||
6LbbdRbwnBQN0hDTUqGQ5hQ/OhcEpX5AhI50ojjwY+JIwZGYiRRBQUWhth2KDgoqKipFLKITG1QQWxGx
|
||||
WCyF2laqrdTaGEmh2Erj2p4ds3PO9Z73//GsZz/3ff8W/CbXICfw3HutKyfn4yNf+tKXgJOr+Zryu8pf
|
||||
KZ8rP1K+UH6h/Gj5Z+W7y2fK16T/DOBcYgicQ80nyl8oP1dG8BQ/X0ZR+Lr0nwmcQwyBY6t5p/zJ8j/K
|
||||
@ -337,7 +337,7 @@
|
||||
<data name="buttonDown.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAP
|
||||
RQAAD0UBxeoB7wAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABrPSURBVHhe7d1f
|
||||
RAAAD0QBF63jCwAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABrPSURBVHhe7d1f
|
||||
yLZrWhbwWSM1hMM0SoEwzpL+7QdBYSlM4FbtFG1Y7bRV0FY0OyFBQUWCqZthG4JFRYVEErWTQwWRSkSS
|
||||
JIKpYWmYNU0oSGM4nVdzTetaax3fn/d9n+e8nvu+fyf8dg5hRnju6zyPWbPmWx/50pe+BA+t5p3yjeU7
|
||||
yufKj5cvlPF/hN2+WH62/Ej5++VPlK9N3zI8khjCI6j56vLny8+XdeHCo/vV8k/K70rfNjyCGMJuNX+y
|
||||
@ -458,7 +458,7 @@
|
||||
<data name="buttonRight.BackgroundImage" type="System.Drawing.Bitmap, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAP
|
||||
RQAAD0UBxeoB7wAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABUVSURBVHhe7d1d
|
||||
RAAAD0QBF63jCwAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAABUVSURBVHhe7d1d
|
||||
yK15WQbwNRM1hMM0SoKgjvTheRAYfYFBR3VSdGB10lFBR9GchAQFFQXjx2HUgVBRUiGRRJ3UUEGkEZEU
|
||||
ieAnpkZa44SCpOF03+6le+3/vvfe78d67vU8/+d3wW+Yud72u9Z69rjva8rZHV566SUAYGfKEgCYW1kC
|
||||
AHMrSwBgbmUJAMytLAGAuZUlADC3sgQA5laWAMDcyhIAmFtZAgBzK0sAYG5lCQDMrSwBgLmVJQAwt7IE
|
||||
|
@ -0,0 +1,139 @@
|
||||
namespace ProjectAirPlane.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;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
namespace ProjectAirPlane.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
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);
|
||||
|
||||
protected void Move();
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
namespace ProjectAirPlane.MovementStrategy;
|
||||
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null) return false;
|
||||
|
||||
return objParams.RightBorder + GetStep() >= FieldWidth
|
||||
&& objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null) return;
|
||||
|
||||
int diffX = objParams.LeftBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
|
||||
int diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
|
||||
namespace ProjectAirPlane.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в центр экрана
|
||||
/// </summary>
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
using ProjectAirPlane.Drawnings;
|
||||
|
||||
namespace ProjectAirPlane.MovementStrategy;
|
||||
|
||||
public class MoveablePlane : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningPlane или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningPlane? _plane = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="plane">Объект класса DrawningPlane</param>
|
||||
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));
|
||||
}
|
||||
|
||||
/// <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,
|
||||
};
|
||||
}
|
||||
|
||||
void IMoveableObject.Move()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
@ -1,10 +1,11 @@
|
||||
namespace ProjectAirPlane;
|
||||
namespace ProjectAirPlane.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
public enum MovementDirection
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
@ -0,0 +1,71 @@
|
||||
namespace ProjectAirPlane.MovementStrategy;
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
namespace ProjectAirPlane.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Все готово к началу
|
||||
/// </summary>
|
||||
NotInit,
|
||||
|
||||
/// <summary>
|
||||
/// Выполняется
|
||||
/// </summary>
|
||||
InProgress,
|
||||
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
}
|
BIN
ProjectAirPlane/ProjectAirPlane/Resources/arrowDown.jpg
Normal file
BIN
ProjectAirPlane/ProjectAirPlane/Resources/arrowDown.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
BIN
ProjectAirPlane/ProjectAirPlane/Resources/arrowLeft.jpg
Normal file
BIN
ProjectAirPlane/ProjectAirPlane/Resources/arrowLeft.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 60 KiB |
BIN
ProjectAirPlane/ProjectAirPlane/Resources/arrowRight.jpg
Normal file
BIN
ProjectAirPlane/ProjectAirPlane/Resources/arrowRight.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 60 KiB |
BIN
ProjectAirPlane/ProjectAirPlane/Resources/arrowUp.jpg
Normal file
BIN
ProjectAirPlane/ProjectAirPlane/Resources/arrowUp.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 61 KiB |
Loading…
Reference in New Issue
Block a user