259 lines
9.7 KiB
C#
259 lines
9.7 KiB
C#
using ProjectStormTrooper.Entities;
|
|
using ProjectStormTrooper.Drawnings;
|
|
|
|
namespace ProjectStormTrooper.Drawnings
|
|
{
|
|
public class DrawningWarPlane
|
|
{
|
|
/// <summary>
|
|
/// Класс-сущность
|
|
/// </summary>
|
|
public EntityWarPlane? EntityWarPlane { get; protected set; }
|
|
/// <summary>
|
|
/// Ширина окна
|
|
/// </summary>
|
|
|
|
private int? _pictureWidth;
|
|
/// <summary>
|
|
/// Высота окна
|
|
/// </summary>
|
|
|
|
|
|
private int? _pictureHeight;
|
|
|
|
/// <summary>
|
|
/// Левая координата прорисовки самолета
|
|
/// </summary>
|
|
|
|
protected int? _startPosX;
|
|
/// <summary>
|
|
/// Верхняя кооридната прорисовки самолета
|
|
/// </summary>
|
|
|
|
protected int? _startPosY;
|
|
|
|
/// <summary>
|
|
/// Ширина прорисовки самолета
|
|
/// </summary>
|
|
|
|
private readonly int _drawningWarPlaneWidth = 140;
|
|
/// <summary>
|
|
/// Высота прорисовки самолета
|
|
/// </summary>
|
|
|
|
private readonly int _drawningWarPlaneHeight = 95;
|
|
/// <summary>
|
|
/// Координата X объекта
|
|
/// </summary>
|
|
public int? GetPosX => _startPosX;
|
|
|
|
/// <summary>
|
|
/// Координата Y объекта
|
|
/// </summary>
|
|
public int? GetPosY => _startPosY;
|
|
|
|
/// <summary>
|
|
/// Ширина объекта
|
|
/// </summary>
|
|
public int GetWidth => _drawningWarPlaneWidth;
|
|
|
|
/// <summary>
|
|
/// Высота объекта
|
|
/// </summary>
|
|
public int GetHeight => _drawningWarPlaneHeight;
|
|
/// <summary>
|
|
/// Пустой конструктор
|
|
/// </summary>
|
|
public DrawningWarPlane()
|
|
{
|
|
_pictureWidth = null;
|
|
_pictureHeight = null;
|
|
_startPosX = null;
|
|
_startPosY = null;
|
|
}
|
|
public DrawningWarPlane(int speed, double weight, Color bodyColor, Color colorOfHead)
|
|
{
|
|
EntityWarPlane = new EntityWarPlane(speed, weight, bodyColor, colorOfHead);
|
|
}
|
|
/// <summary>
|
|
/// Установка границ поля
|
|
/// </summary>
|
|
/// <param name="width">Ширина поля</param>
|
|
/// <param name="height">Высота поля</param>
|
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
|
|
|
|
|
public bool SetPictureSize(int width, int height)
|
|
{
|
|
|
|
if (width <= _drawningWarPlaneWidth || height <= _drawningWarPlaneHeight)
|
|
{
|
|
return false;
|
|
};
|
|
_pictureWidth = width;
|
|
_pictureHeight = height;
|
|
if (_startPosX.HasValue && _startPosY.HasValue)
|
|
{
|
|
if (_startPosX + _drawningWarPlaneWidth > _pictureWidth)
|
|
{
|
|
_startPosX = _pictureWidth.Value - _drawningWarPlaneWidth;
|
|
}
|
|
if (_startPosY + _drawningWarPlaneHeight > _pictureHeight)
|
|
{
|
|
_startPosY = _pictureHeight.Value - _drawningWarPlaneHeight;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Установка позиции
|
|
/// </summary>
|
|
/// <param name="x">Координата X</param>
|
|
/// <param name="y">Координата Y</param>
|
|
|
|
public void SetPosition(int x, int y)
|
|
{
|
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_startPosX = x;
|
|
_startPosY = y;
|
|
|
|
if (_drawningWarPlaneHeight + y > _pictureHeight || y < 0)
|
|
{
|
|
_startPosY = 0;
|
|
}
|
|
if (_drawningWarPlaneWidth + x > _pictureWidth || x < 0)
|
|
{
|
|
_startPosX = 0;
|
|
}
|
|
return;
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Изменение направления перемещения
|
|
/// </summary>
|
|
/// <param name="direction">Направление</param>
|
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
|
|
|
public bool MoveTransport(DirectionType direction)
|
|
{
|
|
if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
switch (direction)
|
|
{
|
|
//влево
|
|
case DirectionType.Left:
|
|
if (_startPosX.Value - EntityWarPlane.Step > 0)
|
|
{
|
|
_startPosX -= (int)EntityWarPlane.Step;
|
|
}
|
|
return true;
|
|
//вверх
|
|
case DirectionType.Up:
|
|
|
|
if (_startPosY.Value - EntityWarPlane.Step > 0)
|
|
{
|
|
_startPosY -= (int)EntityWarPlane.Step;
|
|
}
|
|
|
|
return true;
|
|
// вправо
|
|
case DirectionType.Right:
|
|
|
|
if (_startPosX.Value + EntityWarPlane.Step + _drawningWarPlaneWidth < _pictureWidth)
|
|
{
|
|
_startPosX += (int)EntityWarPlane.Step;
|
|
}
|
|
|
|
|
|
return true;
|
|
//вниз
|
|
case DirectionType.Down:
|
|
|
|
if (_startPosY.Value + EntityWarPlane.Step + _drawningWarPlaneHeight < _pictureHeight)
|
|
{
|
|
_startPosY += (int)EntityWarPlane.Step;
|
|
}
|
|
|
|
|
|
return true;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
public virtual void DrawTransport(Graphics g)
|
|
{
|
|
if (EntityWarPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Pen pen = new(Color.Black);
|
|
Brush mainBrush = new SolidBrush(EntityWarPlane.BodyColor);
|
|
Brush headBrush = new SolidBrush(EntityWarPlane.ColorOfHead);
|
|
// флюзеляж
|
|
Rectangle bodyOfFighter = new Rectangle(_startPosX.Value, _startPosY.Value + 40, 120, 20);
|
|
|
|
g.DrawRectangle(pen, bodyOfFighter);
|
|
g.FillRectangle(mainBrush, bodyOfFighter);
|
|
Point topOfNose = new Point(bodyOfFighter.Right, bodyOfFighter.Top);
|
|
Point bottomOfNose = new Point(bodyOfFighter.Right, bodyOfFighter.Bottom);
|
|
Point edgeOfNose = new Point(bodyOfFighter.Right + 20, (bodyOfFighter.Top + bodyOfFighter.Bottom) / 2);
|
|
Point[] nose = new Point[] { topOfNose, bottomOfNose, edgeOfNose };
|
|
g.DrawPolygon(pen, nose);
|
|
g.FillPolygon(headBrush, nose);
|
|
// крылья штурмовика
|
|
int middleOfBody = (bodyOfFighter.X + bodyOfFighter.Right) / 2;
|
|
// верхнее крыло
|
|
|
|
Point topWingRightBottom = new Point(middleOfBody + 30, bodyOfFighter.Top);
|
|
Point topWingRightTop = new Point(middleOfBody, bodyOfFighter.Top - 40);
|
|
Point topWingLeftTop = new Point(middleOfBody - 10, bodyOfFighter.Top - 40);
|
|
Point topWingLeftBottom = new Point(middleOfBody - 10, bodyOfFighter.Top);
|
|
Point[] topWing = new Point[] { topWingRightBottom, topWingRightTop, topWingLeftTop, topWingLeftBottom };
|
|
g.DrawPolygon(pen, topWing);
|
|
g.FillPolygon(mainBrush, topWing);
|
|
//нижнее крыло
|
|
Point bottomWingRightTop = new Point(middleOfBody + 30, bodyOfFighter.Bottom);
|
|
Point bottomWingRightBottom = new Point(middleOfBody, bodyOfFighter.Bottom + 40);
|
|
Point bottomWingLeftBottom = new Point(middleOfBody - 10, bodyOfFighter.Bottom + 40);
|
|
Point bottomWingLeftTop = new Point(middleOfBody - 10, bodyOfFighter.Bottom);
|
|
Point[] bottomWing = new Point[] { bottomWingRightTop, bottomWingRightBottom, bottomWingLeftBottom, bottomWingLeftTop };
|
|
g.DrawPolygon(pen, bottomWing);
|
|
g.FillPolygon(mainBrush, bottomWing);
|
|
//задние стабилизаторы
|
|
//верхний
|
|
Point topStabRightBottom = new Point(bodyOfFighter.X + 30, bodyOfFighter.Top);
|
|
Point topStabRightTop = new Point(bodyOfFighter.X + 10, bodyOfFighter.Top - 20);
|
|
Point topStabLeftTop = new Point(bodyOfFighter.X, bodyOfFighter.Top - 20);
|
|
Point topStabLeftBottom = new Point(bodyOfFighter.X, bodyOfFighter.Top);
|
|
Point[] topStable = new Point[] { topStabRightBottom, topStabRightTop, topStabLeftTop, topStabLeftBottom };
|
|
g.DrawPolygon(pen, topStable);
|
|
g.FillPolygon(mainBrush, topStable);
|
|
//нижний
|
|
Point bottomStabRightBottom = new Point(bodyOfFighter.X + 30, bodyOfFighter.Bottom);
|
|
Point bottomStabRightTop = new Point(bodyOfFighter.X + 10, bodyOfFighter.Bottom + 20);
|
|
Point bottomStabLeftTop = new Point(bodyOfFighter.X, bodyOfFighter.Bottom + 20);
|
|
Point bottomStabLeftBottom = new Point(bodyOfFighter.X, bodyOfFighter.Bottom);
|
|
Point[] bottomStable = new Point[] { bottomStabRightBottom, bottomStabRightTop, bottomStabLeftTop, bottomStabLeftBottom };
|
|
g.DrawPolygon(pen, bottomStable);
|
|
g.FillPolygon(mainBrush, bottomStable);
|
|
}
|
|
|
|
}
|
|
}
|