2024-02-18 17:22:50 +04:00
|
|
|
|
namespace ProjectAirplaneWithRadar
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class DrawingAirplaneWithRadar
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс-сущность
|
|
|
|
|
/// </summary>
|
|
|
|
|
public EntityAirplaneWithRadar? EntityAirplaneWithRadar { get; private set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureWidth;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureHeight;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Левая координата прорисовки
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _startPosX;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Верхняя кооридната прорисовки
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _startPosY;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-02-18 17:22:50 +04:00
|
|
|
|
/// Ширина прорисовки самолета
|
2024-02-10 18:11:15 +04:00
|
|
|
|
/// </summary>
|
2024-02-18 17:22:50 +04:00
|
|
|
|
public readonly int PlaneWidth = 260;
|
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-18 17:22:50 +04:00
|
|
|
|
public readonly int PlaneHeight = 95;
|
|
|
|
|
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Инициализация свойств
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес</param>
|
|
|
|
|
/// <param name="bodyColor">Основной цвет</param>
|
|
|
|
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
2024-02-18 17:22:50 +04:00
|
|
|
|
/// <param name="wheels">Шасси</param>
|
|
|
|
|
/// <param name="rocket">Ракета</param>
|
|
|
|
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool wheels, bool rocket)
|
2024-02-10 18:11:15 +04:00
|
|
|
|
{
|
|
|
|
|
EntityAirplaneWithRadar = new EntityAirplaneWithRadar();
|
2024-02-18 17:22:50 +04:00
|
|
|
|
EntityAirplaneWithRadar.Init(speed, weight, bodyColor, additionalColor, wheels, rocket);
|
2024-02-10 18:11:15 +04:00
|
|
|
|
_pictureWidth = null;
|
|
|
|
|
_pictureHeight = null;
|
|
|
|
|
_startPosX = null;
|
|
|
|
|
_startPosY = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка границ поля
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="width">Ширина поля</param>
|
|
|
|
|
/// <param name="height">Высота поля</param>
|
|
|
|
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
|
|
|
|
public bool SetPictureSize(int width, int height)
|
|
|
|
|
{
|
|
|
|
|
// TODO проверка, что объект "влезает" в размеры поля
|
|
|
|
|
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
2024-02-18 17:22:50 +04:00
|
|
|
|
//if (PlaneWidth < _pictureWidth || PlaneHeight < _pictureHeight)
|
|
|
|
|
//{
|
|
|
|
|
// return false;
|
|
|
|
|
//}
|
|
|
|
|
//if ((_startPosX + PlaneWidth) < _pictureWidth)
|
|
|
|
|
//{
|
|
|
|
|
// _startPosX -= PlaneWidth + _pictureWidth;
|
|
|
|
|
//}
|
|
|
|
|
//if ((_startPosY + PlaneHeight) < _pictureHeight)
|
|
|
|
|
//{
|
|
|
|
|
// _startPosY -= PlaneHeight + _pictureHeight;
|
|
|
|
|
//}
|
|
|
|
|
return true;
|
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-18 17:22:50 +04:00
|
|
|
|
//TODO (10:52)
|
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
|
|
|
|
//if (PlaneWidth < _pictureWidth || PlaneHeight < _pictureHeight)
|
|
|
|
|
//{
|
|
|
|
|
// return;
|
|
|
|
|
//}
|
|
|
|
|
//if ((_startPosX + PlaneWidth) < _pictureWidth)
|
|
|
|
|
//{
|
|
|
|
|
// _startPosX -= PlaneWidth + _pictureWidth;
|
|
|
|
|
//}
|
|
|
|
|
//if ((_startPosY + PlaneHeight) < _pictureHeight)
|
|
|
|
|
//{
|
|
|
|
|
// _startPosY -= PlaneHeight + _pictureHeight;
|
|
|
|
|
//}
|
2024-02-10 18:11:15 +04:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение направления перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direction">Направление</param>
|
|
|
|
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
|
|
|
|
public bool MoveTransport(DirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityAirplaneWithRadar == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int step = (int)EntityAirplaneWithRadar.Step;
|
|
|
|
|
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-02-18 17:22:50 +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>
|
|
|
|
|
public void DrawTransport(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
if (EntityAirplaneWithRadar == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Pen pen = new(Color.Black);
|
|
|
|
|
Brush additionalBrush = new SolidBrush(EntityAirplaneWithRadar.AdditionalColor);
|
|
|
|
|
|
|
|
|
|
//Шасси
|
|
|
|
|
if (EntityAirplaneWithRadar.Wheels)
|
|
|
|
|
{
|
|
|
|
|
//Задняя стойка
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 70, _startPosY.Value + 90, 5, 10);
|
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 90, 5, 10);
|
|
|
|
|
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 100, 10, 10);
|
|
|
|
|
g.FillEllipse(additionalBrush, _startPosX.Value + 60, _startPosY.Value + 100, 10, 10);
|
|
|
|
|
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 100, 10, 10);
|
|
|
|
|
g.FillEllipse(additionalBrush, _startPosX.Value + 75, _startPosY.Value + 100, 10, 10);
|
|
|
|
|
|
|
|
|
|
//Передняя стойка
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 180, _startPosY.Value + 90, 5, 10);
|
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX.Value + 180, _startPosY.Value + 90, 5, 10);
|
|
|
|
|
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 177, _startPosY.Value + 100, 10, 10);
|
|
|
|
|
g.FillEllipse(additionalBrush, _startPosX.Value + 177, _startPosY.Value + 100, 10, 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Ракета воздух-воздух
|
|
|
|
|
if (EntityAirplaneWithRadar.Rocket)
|
|
|
|
|
{
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + 80, 2, 5);
|
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX.Value + 100, _startPosY.Value + 80, 2, 5);
|
|
|
|
|
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 140, _startPosY.Value + 80, 2, 5);
|
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX.Value + 140, _startPosY.Value + 80, 2, 5);
|
|
|
|
|
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 85, 80, 5);
|
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 85, 80, 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//Корпус
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 60,200,30);
|
|
|
|
|
|
|
|
|
|
//Хвост
|
|
|
|
|
Point[] points = {
|
|
|
|
|
new Point(_startPosX.Value + 10, _startPosY.Value + 10),
|
|
|
|
|
new Point(_startPosX.Value + 10, _startPosY.Value + 60),
|
|
|
|
|
new Point(_startPosX.Value + 60, _startPosY.Value + 60)
|
|
|
|
|
};
|
|
|
|
|
g.DrawPolygon(pen, points);
|
|
|
|
|
|
|
|
|
|
//Кабина
|
|
|
|
|
Point[] points2 = {
|
|
|
|
|
new Point(_startPosX.Value + 210, _startPosY.Value + 55),
|
|
|
|
|
new Point(_startPosX.Value + 210, _startPosY.Value + 75),
|
|
|
|
|
new Point(_startPosX.Value + 260, _startPosY.Value + 75)
|
|
|
|
|
};
|
|
|
|
|
g.DrawPolygon(pen, points2);
|
|
|
|
|
Point[] points3 = {
|
|
|
|
|
new Point(_startPosX.Value + 210, _startPosY.Value + 75),
|
|
|
|
|
new Point(_startPosX.Value + 210, _startPosY.Value + 95),
|
|
|
|
|
new Point(_startPosX.Value + 260, _startPosY.Value + 75)
|
|
|
|
|
};
|
|
|
|
|
g.DrawPolygon(pen, points3);
|
|
|
|
|
|
|
|
|
|
//Крыло
|
|
|
|
|
Brush brBlack = new SolidBrush(Color.Black);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 70, 100, 10);
|
|
|
|
|
g.FillEllipse(brBlack, _startPosX.Value + 70, _startPosY.Value + 70, 100, 10);
|
|
|
|
|
|
|
|
|
|
//Хвостовой элерон
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 55, 40, 10);
|
|
|
|
|
g.FillEllipse(brBlack, _startPosX.Value, _startPosY.Value + 55, 40, 10);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|