using Airbus_Base.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Airbus_Base.DrawningObjects
{
///
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
///
public class DrawningAirplane
{
///
/// Класс-сущность
///
public EntityAirplane? EntityAirplane { get; protected set; }
///
/// Ширина окна
///
private int _pictureWidth;
///
/// Высота окна
///
private int _pictureHeight;
///
/// Левая координата прорисовки самолёта
///
protected int _startPosX;
///
/// Верхняя кооридната прорисовки самолёта
///
protected int _startPosY;
///
/// Ширина прорисовки самолёта
///
protected readonly int _airplaneWidth = 159;
///
/// Высота прорисовки самолёта
///
protected readonly int _airplaneHeight = 103;
///
/// Координата X объекта
///
public int GetPosX => _startPosX;
///
/// Координата Y объекта
///
public int GetPosY => _startPosY;
///
/// Ширина объекта
///
public int GetWidth => _airplaneWidth;
///
/// Высота объекта
///
public int GetHeight => _airplaneHeight;
///
/// Конструктор
///
/// Скорость
/// Вес
/// Основной цвет
/// Ширина картинки
/// Высота картинки
public DrawningAirplane(int speed, double weight, Color bodyColor, int
width, int height)
{
if (width < _airplaneHeight || height < _airplaneWidth)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
}
///
/// Конструктор
///
/// Скорость
/// Вес
/// Основной цвет
/// Ширина картинки
/// Высота картинки
/// Ширина прорисовки cамолёта
/// Высота прорисовки cамолёта
protected DrawningAirplane(int speed, double weight, Color bodyColor, int
width, int height, int airWidth, int airHeight)
{
if (width < _airplaneHeight || height < _airplaneWidth)
{
return;
}
_pictureWidth = width;
_pictureHeight = height;
_airplaneWidth = airWidth;
_airplaneHeight = airHeight;
EntityAirplane = new EntityAirplane(speed, weight, bodyColor);
}
///
/// Установка позиции
///
/// Координата X
/// Координата Y
public void SetPosition(int x, int y)
{
if (x < 0 || x + _airplaneWidth > _pictureWidth)
{
x = Math.Max(0, _pictureWidth - _airplaneWidth);
}
if (y < 0 || y + _airplaneHeight > _pictureHeight)
{
y = Math.Max(0, _pictureHeight - _airplaneHeight);
}
_startPosX = x;
_startPosY = y;
}
///
/// Проверка, что объект может переместится по указанному направлению
///
/// Направление
/// true - можно переместится по указанному направлению
public bool CanMove(DirectionType direction)
{
if (EntityAirplane == null)
{
return false;
}
return direction switch
{
//влево
DirectionType.Left => _startPosX - EntityAirplane.Step > 0,
//вверх
DirectionType.Up => _startPosY - EntityAirplane.Step > 0,
//вправо
DirectionType.Right => _startPosX + _airplaneWidth + EntityAirplane.Step < _pictureWidth,
//вниз
DirectionType.Down => _startPosY + _airplaneHeight + EntityAirplane.Step < _pictureHeight,
_ => false,
};
}
///
/// Изменение направления перемещения
///
/// Направление
public void MoveTransport(DirectionType direction)
{
if (!CanMove(direction) || EntityAirplane == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
_startPosX -= (int)EntityAirplane.Step;
break;
//вверх
case DirectionType.Up:
_startPosY -= (int)EntityAirplane.Step;
break;
// вправо
case DirectionType.Right:
_startPosX += (int)EntityAirplane.Step;
break;
//вниз
case DirectionType.Down:
_startPosY += (int)EntityAirplane.Step;
break;
}
}
///
/// Прорисовка объекта
///
///
public virtual void DrawTransport(Graphics g)
{
if (EntityAirplane == null)
{
return;
}
Pen pen = new(Color.Black);
Brush brBlack = new SolidBrush(Color.Black);
Brush bodybrush = new SolidBrush(EntityAirplane.BodyColor);
//передняя часть
Point[] k = { new Point(_startPosX + 140, _startPosY + 30),
new Point(_startPosX + 160, _startPosY + 56), new Point(_startPosX + 140, _startPosY + 81)};
g.FillPolygon(brBlack, k);
//корпус
g.FillRectangle(bodybrush, _startPosX + 20, _startPosY + 30, 120, 50);
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 30, 120, 50);
//колеса
g.DrawLine(pen, _startPosX + 45, _startPosY + 81, _startPosX + 45, _startPosY + 90);
g.DrawLine(pen, _startPosX + 110, _startPosY + 81, _startPosX + 110, _startPosY + 90);
g.FillEllipse(brBlack, _startPosX + 45, _startPosY + 85, 10, 10);
g.FillEllipse(brBlack, _startPosX + 35, _startPosY + 85, 10, 10);
g.FillEllipse(brBlack, _startPosX + 100, _startPosY + 85, 10, 10);
g.FillEllipse(brBlack, _startPosX + 110, _startPosY + 85, 10, 10);
//хвост
Point[] points1 = { new Point(_startPosX + 20, _startPosY + 30),
new Point(_startPosX + 20, _startPosY + 0), new Point(_startPosX + 50, _startPosY + 30)};
g.FillPolygon(bodybrush, points1);
g.DrawLine(pen, _startPosX + 20, _startPosY + 30, _startPosX + 20, _startPosY + 0);
g.DrawLine(pen, _startPosX + 20, _startPosY + 0, _startPosX + 50, _startPosY + 30);
//крылья
Point[] points2 = { new Point(_startPosX + 65, _startPosY + 30),
new Point(_startPosX + 45, _startPosY + 10), new Point(_startPosX + 88, _startPosY + 30)};
g.FillPolygon(bodybrush, points2);
g.DrawLine(pen, _startPosX + 65, _startPosY + 30, _startPosX + 45, _startPosY + 10);
g.DrawLine(pen, _startPosX + 45, _startPosY + 10, _startPosX + 88, _startPosY + 30);
Point[] points3 = { new Point(_startPosX + 65, _startPosY + 60),
new Point(_startPosX + 45, _startPosY + 100), new Point(_startPosX + 100, _startPosY + 60)};
g.FillPolygon(bodybrush, points3);
g.DrawLine(pen, _startPosX + 65, _startPosY + 60, _startPosX + 45, _startPosY + 100);
g.DrawLine(pen, _startPosX + 45, _startPosY + 100, _startPosX + 100, _startPosY + 60);
g.FillEllipse(brBlack, _startPosX + 16, _startPosY + 27, 30, 6);
}
}
}