2024-03-05 09:00:55 +04:00
|
|
|
|
using ProjectStormtrooper.Entities;
|
|
|
|
|
|
|
|
|
|
namespace ProjectStormtrooper.Drawnings;
|
|
|
|
|
|
2024-03-09 20:45:03 +04:00
|
|
|
|
public class DrawningStormtrooperBase
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс-сущность
|
|
|
|
|
/// </summary>
|
2024-03-05 09:00:55 +04:00
|
|
|
|
public EntityStormtrooperBase? EntityStormtrooperBase { get; protected set; }
|
2024-02-18 18:45:41 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureWidth;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
private int? _pictureHeight;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Левая координата начала прорисовки
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
2024-03-05 09:00:55 +04:00
|
|
|
|
protected int? _startPosX;
|
2024-02-18 18:45:41 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Верхняя координата начала прорисовки
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
2024-03-05 09:00:55 +04:00
|
|
|
|
protected int? _startPosY;
|
2024-02-18 18:45:41 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина прорисовки
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
private readonly int _drawningStormtrooperWidth = 140;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота прорисовки
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
|
|
private readonly int _drawningStormtooperHeight = 140;
|
2024-03-09 20:45:03 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Координата Х объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int? GetPosX => _startPosX;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Координата У объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
|
|
public int? GetPosY => _startPosY;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int GetWidth => _drawningStormtrooperWidth;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public int GetHeight => _drawningStormtooperHeight;
|
2024-02-18 18:45:41 +04:00
|
|
|
|
/// <summary>
|
2024-03-05 09:00:55 +04:00
|
|
|
|
/// Пустой конструктор
|
2024-02-18 18:45:41 +04:00
|
|
|
|
/// </summary>
|
2024-03-09 20:45:03 +04:00
|
|
|
|
private DrawningStormtrooperBase()
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
|
|
|
|
_pictureHeight = null;
|
|
|
|
|
_pictureWidth = null;
|
|
|
|
|
_startPosX = null;
|
|
|
|
|
_startPosY = null;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2024-03-05 09:00:55 +04:00
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">скорость</param>
|
|
|
|
|
/// <param name="weight">вес</param>
|
|
|
|
|
/// <param name="bodyColor">основной цвет</param>
|
|
|
|
|
|
|
|
|
|
|
2024-03-09 20:45:03 +04:00
|
|
|
|
public DrawningStormtrooperBase(int speed, double weight, Color bodyColor):this()
|
2024-03-05 09:00:55 +04:00
|
|
|
|
{
|
|
|
|
|
EntityStormtrooperBase = new EntityStormtrooperBase(speed, weight, bodyColor);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор для наследников
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="drawningStormtrooperWidth"> Ширина прорисовки</param>
|
|
|
|
|
/// <param name="drawningStormtooperHeight">Высота прорисовки</param>
|
|
|
|
|
|
2024-03-09 20:45:03 +04:00
|
|
|
|
protected DrawningStormtrooperBase(int drawningStormtrooperWidth, int drawningStormtooperHeight) : this()
|
2024-03-05 09:00:55 +04:00
|
|
|
|
{
|
|
|
|
|
_drawningStormtrooperWidth = drawningStormtrooperWidth;
|
|
|
|
|
_drawningStormtooperHeight = drawningStormtooperHeight;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2024-02-18 18:45:41 +04:00
|
|
|
|
/// Установка границ поля
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="width">Ширина поля</param>
|
|
|
|
|
/// <param name="height">Высота поля</param>
|
|
|
|
|
/// <returns>true - граница задана, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
2024-03-05 09:00:55 +04:00
|
|
|
|
public bool SetPictureSize(int width, int height)
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
|
|
|
|
if (width >= _drawningStormtrooperWidth || height >= _drawningStormtooperHeight)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
2024-03-05 09:00:55 +04:00
|
|
|
|
if (_startPosX != null && _startPosY != null)
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
|
|
|
|
SetPosition(_startPosX.Value, _startPosY.Value);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка позиции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="x">Координата Х</param>
|
|
|
|
|
/// <param name="y">Координата У</param>
|
|
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
|
|
|
|
// то надо изменить координаты, чтобы он оставался в этих границах
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (x < 0)
|
|
|
|
|
{
|
|
|
|
|
x = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (x > _pictureWidth - _drawningStormtrooperWidth)
|
|
|
|
|
{
|
|
|
|
|
x = _pictureWidth.Value - _drawningStormtrooperWidth;
|
|
|
|
|
}
|
|
|
|
|
if (y < 0)
|
|
|
|
|
{
|
|
|
|
|
y = 0;
|
|
|
|
|
}
|
|
|
|
|
else if (y > _pictureHeight - _drawningStormtooperHeight)
|
|
|
|
|
{
|
|
|
|
|
y = _pictureHeight.Value - _drawningStormtooperHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение направления перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direction">направление</param>
|
|
|
|
|
/// <returns>true - перемещение выполнено, false - перемещение невозможно</returns>
|
|
|
|
|
public bool MoveTransport(DirectionType direction)
|
|
|
|
|
{
|
2024-03-05 09:00:55 +04:00
|
|
|
|
if (EntityStormtrooperBase == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
//влево
|
|
|
|
|
case DirectionType.Left:
|
2024-03-05 09:00:55 +04:00
|
|
|
|
if (_startPosX.Value - EntityStormtrooperBase.Step > 0)
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
2024-03-05 09:00:55 +04:00
|
|
|
|
_startPosX -= (int)EntityStormtrooperBase.Step;
|
2024-02-18 18:45:41 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
//Вверх
|
|
|
|
|
case DirectionType.Up:
|
2024-03-05 09:00:55 +04:00
|
|
|
|
if (_startPosY.Value - EntityStormtrooperBase.Step > 0)
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
2024-03-05 09:00:55 +04:00
|
|
|
|
_startPosY -= (int)EntityStormtrooperBase.Step;
|
2024-02-18 18:45:41 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
//Вправо
|
|
|
|
|
case DirectionType.Right:
|
2024-03-05 09:00:55 +04:00
|
|
|
|
if (_startPosX.Value + EntityStormtrooperBase.Step + _drawningStormtrooperWidth < _pictureWidth)
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
2024-03-05 09:00:55 +04:00
|
|
|
|
_startPosX += (int)EntityStormtrooperBase.Step;
|
2024-02-18 18:45:41 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
//Вниз
|
|
|
|
|
case DirectionType.Down:
|
2024-03-05 09:00:55 +04:00
|
|
|
|
if (_startPosY.Value + EntityStormtrooperBase.Step + _drawningStormtooperHeight < _pictureHeight)
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
2024-03-05 09:00:55 +04:00
|
|
|
|
_startPosY += (int)EntityStormtrooperBase.Step;
|
2024-02-18 18:45:41 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="q"></param>
|
2024-03-05 09:00:55 +04:00
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
2024-03-05 09:00:55 +04:00
|
|
|
|
if (EntityStormtrooperBase == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
2024-02-18 18:45:41 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-05 09:00:55 +04:00
|
|
|
|
Pen pen = new(Color.Black);
|
|
|
|
|
Brush bodyColorBrush = new SolidBrush(EntityStormtrooperBase.BodyColor);
|
|
|
|
|
|
2024-02-18 18:45:41 +04:00
|
|
|
|
|
|
|
|
|
//нос штурмовика
|
2024-03-05 09:00:55 +04:00
|
|
|
|
Brush brBlack = new SolidBrush(Color.Black);
|
|
|
|
|
|
2024-02-18 18:45:41 +04:00
|
|
|
|
Point[] Nose = new Point[3];
|
2024-03-05 09:00:55 +04:00
|
|
|
|
Nose[0].X = _startPosX.Value + 20; Nose[0].Y = _startPosY.Value + 85;
|
|
|
|
|
Nose[1].X = _startPosX.Value + 20; Nose[1].Y = _startPosY.Value + 65;
|
|
|
|
|
Nose[2].X = _startPosX.Value; Nose[2].Y = _startPosY.Value + 75;
|
2024-02-19 19:18:37 +04:00
|
|
|
|
g.FillPolygon(brBlack, Nose);
|
|
|
|
|
g.DrawPolygon(pen, Nose);
|
|
|
|
|
//Заднии крылья штурмовика
|
2024-02-18 18:45:41 +04:00
|
|
|
|
|
2024-02-19 19:18:37 +04:00
|
|
|
|
Point[] pflybtwings = new Point[6];
|
2024-03-05 09:00:55 +04:00
|
|
|
|
pflybtwings[0].X = _startPosX.Value + 120; pflybtwings[0].Y = _startPosY.Value + 65;
|
|
|
|
|
pflybtwings[1].X = _startPosX.Value + 120; pflybtwings[1].Y = _startPosY.Value + 55;
|
|
|
|
|
pflybtwings[2].X = _startPosX.Value + 140; pflybtwings[2].Y = _startPosY.Value + 35;
|
|
|
|
|
pflybtwings[3].X = _startPosX.Value + 140; pflybtwings[3].Y = _startPosY.Value + 115;
|
|
|
|
|
pflybtwings[4].X = _startPosX.Value + 120; pflybtwings[4].Y = _startPosY.Value + 95;
|
|
|
|
|
pflybtwings[5].X = _startPosX.Value + 120; pflybtwings[5].Y = _startPosY.Value + 85;
|
2024-02-19 19:18:37 +04:00
|
|
|
|
g.FillPolygon(bodyColorBrush, pflybtwings);
|
|
|
|
|
g.DrawPolygon(pen, pflybtwings);
|
2024-02-18 18:45:41 +04:00
|
|
|
|
//Тело штурмовика
|
2024-02-19 19:18:37 +04:00
|
|
|
|
|
2024-03-05 09:00:55 +04:00
|
|
|
|
g.FillRectangle(bodyColorBrush, _startPosX.Value + 20, _startPosY.Value + 65, 120, 20);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 65, 120, 20);
|
2024-02-18 18:45:41 +04:00
|
|
|
|
//Крылья штурмовика
|
|
|
|
|
|
2024-02-19 19:18:37 +04:00
|
|
|
|
Point[] frontwings = new Point[4];
|
2024-03-05 09:00:55 +04:00
|
|
|
|
frontwings[0].X = _startPosX.Value + 60; frontwings[0].Y = _startPosY.Value + 65;
|
|
|
|
|
frontwings[1].X = _startPosX.Value + 60; frontwings[1].Y = _startPosY.Value + 5;
|
|
|
|
|
frontwings[2].X = _startPosX.Value + 70; frontwings[2].Y = _startPosY.Value + 5;
|
|
|
|
|
frontwings[3].X = _startPosX.Value + 80; frontwings[3].Y = _startPosY.Value + 65;
|
2024-02-19 19:18:37 +04:00
|
|
|
|
g.FillPolygon(bodyColorBrush, frontwings);
|
|
|
|
|
g.DrawPolygon(pen, frontwings);
|
|
|
|
|
|
|
|
|
|
Point[] frontwings2 = new Point[4];
|
2024-03-05 09:00:55 +04:00
|
|
|
|
frontwings2[0].X = _startPosX.Value + 60; frontwings2[0].Y = _startPosY.Value + 85;
|
|
|
|
|
frontwings2[1].X = _startPosX.Value + 60; frontwings2[1].Y = _startPosY.Value + 145;
|
|
|
|
|
frontwings2[2].X = _startPosX.Value + 70; frontwings2[2].Y = _startPosY.Value + 145;
|
|
|
|
|
frontwings2[3].X = _startPosX.Value + 80; frontwings2[3].Y = _startPosY.Value + 85;
|
2024-02-19 19:18:37 +04:00
|
|
|
|
g.FillPolygon(bodyColorBrush, frontwings2);
|
|
|
|
|
g.DrawPolygon(pen, frontwings2);
|
|
|
|
|
|
2024-02-18 18:45:41 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|