2024-03-01 19:55:24 +04:00
|
|
|
|
using System;
|
|
|
|
|
using ProjectAirplaneWithRadar.Entities;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace ProjectAirplaneWithRadar.Drawnings
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
2024-03-01 19:55:24 +04:00
|
|
|
|
public class DrawningAirplane
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
2024-03-01 19:55:24 +04:00
|
|
|
|
|
2024-02-10 18:11:15 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс-сущность
|
|
|
|
|
/// </summary>
|
2024-03-01 19:55:24 +04:00
|
|
|
|
public EntityAirplane? EntityAirplane { get; protected set; }
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureWidth;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureHeight;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Левая координата прорисовки
|
|
|
|
|
/// </summary>
|
2024-03-01 19:55:24 +04:00
|
|
|
|
protected int? _startPosX;
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Верхняя кооридната прорисовки
|
|
|
|
|
/// </summary>
|
2024-03-01 19:55:24 +04:00
|
|
|
|
protected int? _startPosY;
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-02-18 17:22:50 +04:00
|
|
|
|
/// Ширина прорисовки самолета
|
2024-02-10 18:11:15 +04:00
|
|
|
|
/// </summary>
|
2024-02-24 10:18:22 +04:00
|
|
|
|
public readonly int PlaneWidth = 150;
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-02-18 17:22:50 +04:00
|
|
|
|
/// Высота прорисовки самолета
|
2024-02-10 18:11:15 +04:00
|
|
|
|
/// </summary>
|
2024-03-01 19:55:24 +04:00
|
|
|
|
public readonly int PlaneHeight = 85;
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
2024-03-02 18:10:42 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Координата X объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int? GetPosX => _startPosX;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Координата Y объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int? GetPosY => _startPosY;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetWidth => PlaneWidth;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetHeight => PlaneHeight;
|
|
|
|
|
|
2024-02-10 18:11:15 +04:00
|
|
|
|
/// <summary>
|
2024-03-01 19:55:24 +04:00
|
|
|
|
/// Пустой конструктор
|
2024-02-10 18:11:15 +04:00
|
|
|
|
/// </summary>
|
2024-03-01 19:55:24 +04:00
|
|
|
|
private DrawningAirplane()
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
|
|
|
|
_pictureWidth = null;
|
|
|
|
|
_pictureHeight = null;
|
|
|
|
|
_startPosX = null;
|
|
|
|
|
_startPosY = null;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-01 19:55:24 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес</param>
|
|
|
|
|
/// <param name="bodyColor">Основной цвет</param>
|
|
|
|
|
public DrawningAirplane(int speed, double weight, Color bodyColor) : this()
|
|
|
|
|
{
|
|
|
|
|
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор для наследников
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="planeWidth">Ширина прорисовки самолета</param>
|
|
|
|
|
/// <param name="planeHeight">Высота прорисовки самолета</param>
|
|
|
|
|
protected DrawningAirplane(int planeWidth, int planeHeight) : this()
|
|
|
|
|
{
|
|
|
|
|
PlaneWidth = planeWidth;
|
|
|
|
|
PlaneHeight = planeHeight;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-10 18:11:15 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка границ поля
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="width">Ширина поля</param>
|
|
|
|
|
/// <param name="height">Высота поля</param>
|
|
|
|
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
|
|
|
|
public bool SetPictureSize(int width, int height)
|
|
|
|
|
{
|
2024-02-21 16:34:26 +04:00
|
|
|
|
if (PlaneWidth < width && PlaneHeight < height)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
2024-03-01 19:55:24 +04:00
|
|
|
|
if (_startPosX != null && _startPosY != null)
|
2024-02-21 16:34:26 +04:00
|
|
|
|
{
|
2024-03-01 19:55:24 +04:00
|
|
|
|
if (_startPosX.Value < 0)
|
2024-02-21 16:34:26 +04:00
|
|
|
|
{
|
|
|
|
|
_startPosX = 0;
|
|
|
|
|
}
|
2024-03-01 19:55:24 +04:00
|
|
|
|
if (_startPosY.Value < 0)
|
2024-02-21 16:34:26 +04:00
|
|
|
|
{
|
|
|
|
|
_startPosY = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-01 19:55:24 +04:00
|
|
|
|
if (_startPosX.Value + PlaneWidth > _pictureWidth)
|
2024-02-21 16:34:26 +04:00
|
|
|
|
{
|
|
|
|
|
_startPosX = _pictureWidth - PlaneWidth;
|
|
|
|
|
}
|
|
|
|
|
if (_startPosY.Value + PlaneHeight > _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY = _pictureHeight - PlaneHeight;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
2024-02-10 18:11:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка позиции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="x">Координата X</param>
|
|
|
|
|
/// <param name="y">Координата Y</param>
|
2024-02-18 17:22:50 +04:00
|
|
|
|
public void SetPosition(int x, int y)
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
|
|
|
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
|
|
|
{
|
2024-02-18 17:22:50 +04:00
|
|
|
|
return;
|
2024-02-10 18:11:15 +04:00
|
|
|
|
}
|
2024-02-21 16:34:26 +04:00
|
|
|
|
|
2024-02-18 17:22:50 +04:00
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
2024-02-21 16:34:26 +04:00
|
|
|
|
if (_startPosX.Value < 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosX = 0;
|
|
|
|
|
}
|
2024-03-01 19:55:24 +04:00
|
|
|
|
if (_startPosY.Value < 0)
|
2024-02-21 16:34:26 +04:00
|
|
|
|
{
|
|
|
|
|
_startPosY = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_startPosX.Value + PlaneWidth > _pictureWidth)
|
|
|
|
|
{
|
|
|
|
|
_startPosX = _pictureWidth - PlaneWidth;
|
|
|
|
|
}
|
|
|
|
|
if (_startPosY.Value + PlaneHeight > _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY = _pictureHeight - PlaneHeight;
|
|
|
|
|
}
|
2024-02-10 18:11:15 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение направления перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direction">Направление</param>
|
|
|
|
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
|
|
|
|
public bool MoveTransport(DirectionType direction)
|
|
|
|
|
{
|
2024-03-01 19:55:24 +04:00
|
|
|
|
if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-01 19:55:24 +04:00
|
|
|
|
int step = (int)EntityAirplane.Step;
|
2024-02-10 18:11:15 +04:00
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
//влево
|
|
|
|
|
case DirectionType.Left:
|
|
|
|
|
if (_startPosX.Value - step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosX -= step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
//вверх
|
|
|
|
|
case DirectionType.Up:
|
|
|
|
|
if (_startPosY.Value - step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosY -= step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// вправо
|
|
|
|
|
case DirectionType.Right:
|
2024-03-01 19:55:24 +04:00
|
|
|
|
if (_startPosX.Value + step < _pictureWidth - PlaneWidth)
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
|
|
|
|
_startPosX += step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
//вниз
|
|
|
|
|
case DirectionType.Down:
|
|
|
|
|
if (_startPosY.Value + step < _pictureHeight - PlaneHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY += step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
2024-03-01 19:55:24 +04:00
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
2024-03-01 19:55:24 +04:00
|
|
|
|
if (EntityAirplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pen pen = new(Color.Black);
|
2024-03-06 16:28:03 +04:00
|
|
|
|
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
|
|
|
|
//Корпус
|
2024-03-06 16:28:03 +04:00
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 100, 30);
|
2024-03-01 19:55:24 +04:00
|
|
|
|
|
2024-02-10 18:11:15 +04:00
|
|
|
|
//Хвост
|
|
|
|
|
Point[] points = {
|
2024-03-02 18:10:42 +04:00
|
|
|
|
new Point(_startPosX.Value + 10, _startPosY.Value),
|
2024-03-06 16:28:03 +04:00
|
|
|
|
new Point(_startPosX.Value + 10, _startPosY.Value + 40),
|
|
|
|
|
new Point(_startPosX.Value + 50, _startPosY.Value + 40)
|
2024-02-10 18:11:15 +04:00
|
|
|
|
};
|
|
|
|
|
g.DrawPolygon(pen, points);
|
|
|
|
|
|
|
|
|
|
//Кабина
|
|
|
|
|
Point[] points2 = {
|
2024-03-06 16:28:03 +04:00
|
|
|
|
new Point(_startPosX.Value + 110, _startPosY.Value + 35),
|
|
|
|
|
new Point(_startPosX.Value + 110, _startPosY.Value + 55),
|
|
|
|
|
new Point(_startPosX.Value + 150, _startPosY.Value + 55)
|
2024-02-10 18:11:15 +04:00
|
|
|
|
};
|
|
|
|
|
g.DrawPolygon(pen, points2);
|
|
|
|
|
Point[] points3 = {
|
2024-03-06 16:28:03 +04:00
|
|
|
|
new Point(_startPosX.Value + 110, _startPosY.Value + 55),
|
|
|
|
|
new Point(_startPosX.Value + 110, _startPosY.Value + 75),
|
|
|
|
|
new Point(_startPosX.Value + 150, _startPosY.Value + 55)
|
2024-02-10 18:11:15 +04:00
|
|
|
|
};
|
|
|
|
|
g.DrawPolygon(pen, points3);
|
|
|
|
|
|
|
|
|
|
//Крыло
|
2024-03-06 16:28:03 +04:00
|
|
|
|
Brush brBlack = new SolidBrush(EntityAirplane.BodyColor);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 50, 70, 10);
|
|
|
|
|
g.FillEllipse(brBlack, _startPosX.Value + 30, _startPosY.Value + 50, 70, 10);
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
|
|
|
|
//Хвостовой элерон
|
2024-03-06 16:28:03 +04:00
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 35, 30, 10);
|
|
|
|
|
g.FillEllipse(brBlack, _startPosX.Value, _startPosY.Value + 35, 30, 10);
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-01 19:55:24 +04:00
|
|
|
|
|