2024-02-21 16:56:08 +04:00
|
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
|
|
|
|
|
|
namespace ProjectCruiser;
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
public class DrawningCruiser
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Класс-сущность
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
public EntityCruiser? EntityCruiser { get; private set; }
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Ширина окна
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureWidth;
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Высота окна
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureHeight;
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Левая координата прорисовки автомобиля
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _startPosX;
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Верхняя кооридната прорисовки автомобиля
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _startPosY;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Ширина прорисовки крейсера
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
private readonly int _drawningCruiserWidth = 150;
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Высота прорисовки крейсера
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
private readonly int _drawningCruiserHeight = 50;
|
|
|
|
|
private readonly int _drawningEnginesWidth = 3;
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Инициализация свойств
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес</param>
|
|
|
|
|
/// <param name="bodyColor">Основной цвет</param>
|
|
|
|
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
|
|
|
/// <param name="helicopterArea">Признак наличия вертолетной площадки</param>
|
|
|
|
|
/// <param name="boat">Признак наличия шлюпок</param>
|
|
|
|
|
/// <param name="wepon">Признак наличия пушки</param>
|
2024-02-21 16:56:08 +04:00
|
|
|
|
public void Init(int speed, double weight, Color bodyColor, Color
|
|
|
|
|
additionalColor, bool helicopterArea, bool boat, bool wepon)
|
|
|
|
|
{
|
|
|
|
|
EntityCruiser = new EntityCruiser();
|
|
|
|
|
EntityCruiser.Init(speed, weight, bodyColor, additionalColor,
|
|
|
|
|
helicopterArea, boat, wepon);
|
|
|
|
|
_pictureWidth = null;
|
|
|
|
|
_pictureHeight = null;
|
|
|
|
|
_startPosX = null;
|
|
|
|
|
_startPosY = null;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Установка границ поля
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// <param name="width">Ширина поля</param>
|
|
|
|
|
/// <param name="height">Высота поля</param>
|
|
|
|
|
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
2024-02-21 16:56:08 +04:00
|
|
|
|
public bool SetPictureSize(int width, int height)
|
|
|
|
|
{
|
2024-02-29 13:53:31 +04:00
|
|
|
|
// TODO проверка, что объект "влезает" в размеры поля
|
|
|
|
|
// если влезает, сохраняем границы и корректируем позицию объекта,если она была уже установлена
|
2024-02-21 16:56:08 +04:00
|
|
|
|
|
2024-02-29 13:53:31 +04:00
|
|
|
|
if (_drawningCruiserHeight > height || _drawningCruiserWidth > width)
|
2024-02-21 16:56:08 +04:00
|
|
|
|
{
|
2024-02-29 13:53:31 +04:00
|
|
|
|
return false;
|
|
|
|
|
|
2024-02-21 16:56:08 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
2024-02-29 13:53:31 +04:00
|
|
|
|
|
|
|
|
|
if (_startPosX.HasValue && _startPosY.HasValue)
|
|
|
|
|
{
|
|
|
|
|
SetPosition(_startPosX.Value, _startPosY.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-21 16:56:08 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Установка позиции
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// <param name="x">Координата X</param>
|
|
|
|
|
/// <param name="y">Координата Y</param>
|
2024-02-21 16:56:08 +04:00
|
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-29 13:53:31 +04:00
|
|
|
|
if (x < 0 || x + _drawningCruiserWidth > _pictureWidth || y < 0 || y + _drawningCruiserHeight > _pictureHeight)
|
2024-02-21 16:56:08 +04:00
|
|
|
|
{
|
2024-02-29 13:53:31 +04:00
|
|
|
|
_startPosX = _pictureWidth - _drawningCruiserWidth;
|
|
|
|
|
_startPosY = _pictureHeight - _drawningCruiserHeight;
|
2024-02-21 16:56:08 +04:00
|
|
|
|
}
|
2024-02-29 13:53:31 +04:00
|
|
|
|
else
|
2024-02-21 16:56:08 +04:00
|
|
|
|
{
|
2024-02-29 13:53:31 +04:00
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
2024-02-21 16:56:08 +04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Изменение направления перемещения
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// <param name="direction">Направление</param>
|
|
|
|
|
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
2024-02-21 16:56:08 +04:00
|
|
|
|
public bool MoveTransport(DirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityCruiser == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
2024-02-29 13:53:31 +04:00
|
|
|
|
//влево
|
2024-02-21 16:56:08 +04:00
|
|
|
|
case DirectionType.Left:
|
2024-02-29 13:53:31 +04:00
|
|
|
|
if (_startPosX.Value - EntityCruiser.Step - _drawningEnginesWidth > 0)
|
2024-02-21 16:56:08 +04:00
|
|
|
|
{
|
|
|
|
|
_startPosX -= (int)EntityCruiser.Step;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2024-02-29 13:53:31 +04:00
|
|
|
|
//вверх
|
2024-02-21 16:56:08 +04:00
|
|
|
|
case DirectionType.Up:
|
|
|
|
|
if (_startPosY.Value - EntityCruiser.Step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosY -= (int)EntityCruiser.Step;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2024-02-29 13:53:31 +04:00
|
|
|
|
// вправо
|
2024-02-21 16:56:08 +04:00
|
|
|
|
case DirectionType.Right:
|
2024-02-29 13:53:31 +04:00
|
|
|
|
//TODO прописать логику сдвига в право
|
|
|
|
|
if (_startPosX.Value + EntityCruiser.Step + _drawningCruiserWidth < _pictureWidth)
|
2024-02-21 16:56:08 +04:00
|
|
|
|
{
|
|
|
|
|
_startPosX += (int)EntityCruiser.Step;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2024-02-29 13:53:31 +04:00
|
|
|
|
//вниз
|
2024-02-21 16:56:08 +04:00
|
|
|
|
case DirectionType.Down:
|
2024-02-29 13:53:31 +04:00
|
|
|
|
if (_startPosY.Value + EntityCruiser.Step + _drawningCruiserHeight < _pictureHeight)
|
2024-02-21 16:56:08 +04:00
|
|
|
|
{
|
|
|
|
|
_startPosY += (int)EntityCruiser.Step;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Прорисовка объекта
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
|
|
|
|
public void DrawTransport(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
if (EntityCruiser == null || !_startPosX.HasValue ||
|
|
|
|
|
!_startPosY.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-02-29 13:53:31 +04:00
|
|
|
|
Pen pen = new(EntityCruiser.BodyColor, 2);
|
2024-02-21 16:56:08 +04:00
|
|
|
|
Brush additionalBrush = new SolidBrush(Color.Black);
|
|
|
|
|
Brush weaponBrush = new SolidBrush(Color.Black);
|
|
|
|
|
Brush weaponBrush2 = new SolidBrush(EntityCruiser.AdditionalColor);
|
|
|
|
|
Brush helicopterAreaBrush = new HatchBrush(HatchStyle.ZigZag, EntityCruiser.AdditionalColor, Color.FromArgb(163, 163, 163));
|
|
|
|
|
Brush boatBrush = new SolidBrush(EntityCruiser.AdditionalColor);
|
|
|
|
|
|
2024-02-29 13:53:31 +04:00
|
|
|
|
//границы круисера
|
2024-02-21 16:56:08 +04:00
|
|
|
|
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value + 105, _startPosY.Value);
|
|
|
|
|
g.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value, _startPosX.Value + 147, _startPosY.Value + 24);
|
|
|
|
|
|
|
|
|
|
g.DrawLine(pen, _startPosX.Value, _startPosY.Value + 49, _startPosX.Value + 105, _startPosY.Value + 49);
|
|
|
|
|
g.DrawLine(pen, _startPosX.Value + 105, _startPosY.Value + 49, _startPosX.Value + 147, _startPosY.Value + 24);
|
|
|
|
|
|
|
|
|
|
g.DrawLine(pen, _startPosX.Value, _startPosY.Value, _startPosX.Value, _startPosY.Value + 49);
|
|
|
|
|
|
2024-02-29 13:53:31 +04:00
|
|
|
|
//внутренности круисера
|
2024-02-21 16:56:08 +04:00
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 94, _startPosY.Value + 14, 19, 19);
|
|
|
|
|
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 63, _startPosY.Value + 11, 21, 28);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 17, 28, 14);
|
|
|
|
|
|
2024-02-29 13:53:31 +04:00
|
|
|
|
//зад
|
2024-02-21 16:56:08 +04:00
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 7, 3, 14);
|
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX.Value - 3, _startPosY.Value + 26, 3, 14);
|
|
|
|
|
|
|
|
|
|
if (EntityCruiser.HelicopterArea)
|
|
|
|
|
{
|
|
|
|
|
g.FillEllipse(helicopterAreaBrush, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 9, 25, 30);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (EntityCruiser.Boat)
|
|
|
|
|
{
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
|
|
|
|
|
g.FillEllipse(boatBrush, _startPosX.Value + 34, _startPosY.Value + 2, 30, 7);
|
|
|
|
|
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
|
|
|
|
|
g.FillEllipse(boatBrush, _startPosX.Value + 34, _startPosY.Value + 39, 30, 7);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (EntityCruiser.Weapon)
|
|
|
|
|
{
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
|
|
|
|
|
g.FillEllipse(weaponBrush2, _startPosX.Value + 97, _startPosY.Value + 36, 10, 10);
|
|
|
|
|
|
|
|
|
|
g.FillRectangle(weaponBrush, _startPosX.Value + 107, _startPosY.Value + 40, 15, 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|