212 lines
8.3 KiB
C#
212 lines
8.3 KiB
C#
namespace Seaplane;
|
||
/// <summary>
|
||
/// Класс отвечающий за прорисовку и перемещение объекта - сущности
|
||
/// </summary>
|
||
public class DrawingSeaplane
|
||
{
|
||
/// <summary>
|
||
/// Класс - сущность
|
||
/// </summary>
|
||
public EntitySeaplane? EntitySeaplane { get; set; }
|
||
/// <summary>
|
||
/// Ширина окна
|
||
/// </summary>
|
||
private int? _pictureWidth;
|
||
/// <summary>
|
||
/// Высота окна
|
||
/// </summary>
|
||
private int? _pictureHeight;
|
||
/// <summary>
|
||
/// Левая координата прорисовки гидросамолета
|
||
/// </summary>
|
||
private int? _startPosX;
|
||
/// <summary>
|
||
/// Верхняя координата прорисовки гидросамолета
|
||
/// </summary>
|
||
private int? _startPosY;
|
||
/// <summary>
|
||
/// Ширина прорисовки гидросамолета
|
||
/// </summary>
|
||
private readonly int _drawningPlaneWidth = 0;
|
||
/// <summary>
|
||
/// Высота прорисовки гидросамолета
|
||
/// </summary>
|
||
private readonly int _drawningPlaneHeight = 0;
|
||
/// <summary>
|
||
/// Инициализация полей объекта-класса гидросамолета
|
||
/// </summary>
|
||
/// <param name="speed">Скорость</param>
|
||
/// <param name="weight">Вес</param>
|
||
/// <param name="bodyColor">Основной цвет</param>
|
||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||
/// <param name="bodyKit">Наличие обвеса</param>
|
||
/// <param name="floats">Наличие поплавков</param>
|
||
/// <param name="inflatableBoat">Наличие надувной лодки</param>
|
||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool wing, bool sportLine)
|
||
{
|
||
EntitySeaplane = new EntitySeaplane();
|
||
EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, bodyKit, wing, sportLine);
|
||
_pictureWidth = null;
|
||
_pictureHeight = null;
|
||
_startPosX = null;
|
||
_startPosY = null;
|
||
}
|
||
public bool SetPictureSize(int width, int height)
|
||
{
|
||
// TODO проверка, что объект "влезает" в размеры поля
|
||
// если влезает, сохраняем границы и корректируем позицию объекта,если она была уже установлена
|
||
if (width < _drawningPlaneWidth || height < _drawningPlaneHeight) return false;
|
||
_pictureWidth = width;
|
||
_pictureHeight = height;
|
||
if (_startPosX != null || _startPosY != null)
|
||
{
|
||
if (_startPosX + _drawningPlaneWidth > _pictureWidth)
|
||
{
|
||
_startPosX = _startPosX - (_startPosX + _drawningPlaneWidth - _pictureWidth);
|
||
}
|
||
else if (_startPosX < 0) _startPosX = 0;
|
||
if (_startPosY + _drawningPlaneHeight > _pictureHeight)
|
||
{
|
||
_startPosY = _startPosY - (_startPosY + _drawningPlaneHeight - _pictureHeight);
|
||
}
|
||
else if (_startPosY < 0) _startPosY = 0;
|
||
}
|
||
return true;
|
||
}
|
||
/// <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 + _drawningPlaneWidth > _pictureWidth)
|
||
{
|
||
_startPosX = x - (x + _drawningPlaneWidth - _pictureWidth);
|
||
}
|
||
else if (x < 0) _startPosX = 0;
|
||
else _startPosX = x;
|
||
if (y + _drawningPlaneHeight > _pictureHeight)
|
||
{
|
||
_startPosY = y - (y + _drawningPlaneHeight - _pictureHeight);
|
||
}
|
||
else if (y < 0) _startPosY = 0;
|
||
else _startPosY = y;
|
||
}
|
||
/// <summary>
|
||
/// Изменение направления перемещения
|
||
/// </summary>
|
||
/// <param name="direction"></param>
|
||
/// <returns></returns>
|
||
public bool MoveTransport(DirectionType direction)
|
||
{
|
||
if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||
{
|
||
return false;
|
||
}
|
||
switch (direction)
|
||
{
|
||
//влево
|
||
case DirectionType.Left:
|
||
if (_startPosX.Value - EntitySeaplane.Step > 0)
|
||
{
|
||
_startPosX -= (int)EntitySeaplane.Step;
|
||
}
|
||
return true;
|
||
//вверх
|
||
case DirectionType.Up:
|
||
if (_startPosY.Value - EntitySeaplane.Step > 0)
|
||
{
|
||
_startPosY -= (int)EntitySeaplane.Step;
|
||
}
|
||
return true;
|
||
// вправо
|
||
case DirectionType.Right:
|
||
if (_startPosX.Value + _drawningPlaneWidth + EntitySeaplane.Step < _pictureWidth)
|
||
{
|
||
_startPosX += (int)EntitySeaplane.Step;
|
||
}
|
||
return true;
|
||
//вниз
|
||
case DirectionType.Down:
|
||
if (_startPosY.Value + _drawningPlaneHeight + EntitySeaplane.Step < _pictureHeight)
|
||
{
|
||
_startPosY += (int)EntitySeaplane.Step;
|
||
}
|
||
return true;
|
||
default:
|
||
return false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Прорисовка объекта
|
||
/// </summary>
|
||
/// <param name="g"></param>
|
||
public void DrawTransport(Graphics g)
|
||
{
|
||
if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||
{
|
||
return;
|
||
}
|
||
|
||
Pen pen = new(Color.Black);
|
||
Pen additionalpen = new(EntitySeaplane.AdditionalColor);
|
||
|
||
|
||
|
||
//корпус гидросамолета
|
||
Brush br = new SolidBrush(EntitySeaplane.BodyColor);
|
||
g.FillRectangle(br, _startPosX.Value, _startPosY.Value + 20, 100, 20);
|
||
g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 20, 100, 20);
|
||
|
||
//крыло
|
||
Brush darkBrush = new SolidBrush(Color.Black);
|
||
g.FillRectangle(darkBrush, _startPosX.Value + 27, _startPosY.Value + 29, 40, 3);
|
||
|
||
//хвостовое крыло
|
||
g.DrawLine(pen, _startPosX.Value, _startPosY.Value + 20, _startPosX.Value, _startPosY.Value);
|
||
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value + 20, _startPosY.Value + 20);
|
||
|
||
//заднее поперечное крыло
|
||
Brush additionalBrush = new SolidBrush(EntitySeaplane.AdditionalColor);
|
||
g.FillEllipse(darkBrush, _startPosX.Value - 7, _startPosY.Value + 15, 20, 5);
|
||
|
||
//нос самолёта
|
||
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 130, _startPosY.Value + 30);
|
||
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 40, _startPosX.Value + 130, _startPosY.Value + 30);
|
||
g.DrawLine(pen, _startPosX.Value + 130, _startPosY.Value + 30, _startPosX.Value + 100, _startPosY.Value + 30);
|
||
|
||
//задние шасси
|
||
g.DrawLine(pen, _startPosX.Value + 21, _startPosY.Value + 40, _startPosX.Value + 21, _startPosY.Value + 45);
|
||
g.FillEllipse(darkBrush, _startPosX.Value + 15, _startPosY.Value + 45, 6, 6);
|
||
g.FillEllipse(darkBrush, _startPosX.Value + 21, _startPosY.Value + 45, 6, 6);
|
||
|
||
//переднее шасси
|
||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 40, _startPosX.Value + 90, _startPosY.Value + 45);
|
||
g.FillEllipse(darkBrush, _startPosX.Value + 87, _startPosY.Value + 45, 6, 6);
|
||
|
||
// поплавки
|
||
if (EntitySeaplane.Floats)
|
||
{
|
||
Brush br2 = new SolidBrush(Color.Red);
|
||
g.FillRectangle(br2, _startPosX.Value + 10, _startPosY.Value + 48, 90, 5);
|
||
}
|
||
|
||
// надувная лодка
|
||
if (EntitySeaplane.InflatableBoat)
|
||
{
|
||
g.FillRectangle(additionalBrush, _startPosX.Value + 38, _startPosY.Value + 38, 22, 8);
|
||
|
||
|
||
|
||
}
|
||
}
|
||
}
|
||
|