2024-03-07 09:46:27 +04:00
|
|
|
|
using ProjectCruiser.Entities;
|
2024-02-21 16:56:08 +04:00
|
|
|
|
|
2024-03-07 09:46:27 +04:00
|
|
|
|
namespace ProjectCruiser.Drawnings;
|
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>
|
|
|
|
|
public class DrawningCruiser
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2024-02-29 13:53:31 +04:00
|
|
|
|
/// Класс-сущность
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
2024-03-07 09:46:27 +04:00
|
|
|
|
public EntityCruiser? EntityCruiser { get; protected set; }
|
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>
|
|
|
|
|
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-05-13 12:59:51 +04:00
|
|
|
|
/// Левая координата прорисовки крейсера
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
2024-03-07 09:46:27 +04:00
|
|
|
|
protected int? _startPosX;
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// <summary>
|
2024-05-13 12:59:51 +04:00
|
|
|
|
/// Верхняя кооридната прорисовки крейсера
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
2024-03-07 09:46:27 +04:00
|
|
|
|
protected int? _startPosY;
|
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 _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-03-07 09:46:27 +04:00
|
|
|
|
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// <summary>
|
2024-03-07 09:46:27 +04:00
|
|
|
|
/// Координата X объекта
|
2024-02-21 16:56:08 +04:00
|
|
|
|
/// </summary>
|
2024-03-07 09:46:27 +04:00
|
|
|
|
public int? GetPosX => _startPosX;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Координата Y объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int? GetPosY => _startPosY;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetWidth => _drawningCruiserWidth;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetHeight => _drawningCruiserHeight;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Пустой онструктор
|
|
|
|
|
/// </summary>
|
2024-05-13 12:59:51 +04:00
|
|
|
|
public DrawningCruiser()
|
2024-02-21 16:56:08 +04:00
|
|
|
|
{
|
|
|
|
|
_pictureWidth = null;
|
|
|
|
|
_pictureHeight = null;
|
|
|
|
|
_startPosX = null;
|
|
|
|
|
_startPosY = null;
|
|
|
|
|
}
|
2024-03-07 09:46:27 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес</param>
|
|
|
|
|
/// <param name="bodyColor">Основной цвет</param>
|
|
|
|
|
public DrawningCruiser(int speed, double weight, Color bodyColor) : this()
|
|
|
|
|
{
|
|
|
|
|
EntityCruiser = new EntityCruiser(speed, weight, bodyColor);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор для наследников
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="drawningCarWidth">Ширина прорисовки автомобиля</param>
|
|
|
|
|
/// <param name="drawningCarHeight">Высота прорисовки автомобиля</param>
|
|
|
|
|
protected DrawningCruiser(int drawningCarWidth, int drawningCarHeight) : this()
|
|
|
|
|
{
|
|
|
|
|
_drawningCruiserWidth = drawningCarWidth;
|
|
|
|
|
_pictureHeight = drawningCarHeight;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-13 12:59:51 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="entityCruiser"></param>
|
|
|
|
|
public DrawningCruiser(EntityCruiser entityCruiser)
|
|
|
|
|
{
|
|
|
|
|
EntityCruiser = entityCruiser;
|
|
|
|
|
}
|
|
|
|
|
|
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="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-03-07 09:46:27 +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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-13 12:59:51 +04:00
|
|
|
|
|
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>
|
|
|
|
|
/// <param name="g"></param>
|
2024-03-07 09:46:27 +04:00
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
2024-02-21 16:56:08 +04:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|