2023-09-25 14:09:42 +04:00
|
|
|
|
using Cruiser.Entities;
|
|
|
|
|
using System;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2023-09-25 14:09:42 +04:00
|
|
|
|
namespace Cruiser.Drawing
|
2023-09-25 11:15:05 +04:00
|
|
|
|
{
|
|
|
|
|
public class DrawingCruiser
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс-сущность
|
|
|
|
|
/// </summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
public EntityCruiser? EntityCruiser { get; set; }
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int _pictureWidth;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int _pictureHeight;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Левая координата прорисовки Крейсера
|
|
|
|
|
/// </summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
protected static int _startPosX;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Верхняя кооридната прорисовки Крейсера
|
|
|
|
|
/// </summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
protected static int _startPosY;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина прорисовки Крейсера
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly int _cruiserWidth = 150;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота прорисовки Крейсера
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly int _cruiserHeight = 60;
|
|
|
|
|
/// <summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
/// Координата X объекта
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// </summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
public int GetPosX => _startPosX;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// <summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
/// Координата Y объекта
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// </summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
public int GetPosY => _startPosY;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// <summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
/// Ширина объекта
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// </summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
public int GetWidth => _cruiserWidth;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// <summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
/// Высота объекта
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// </summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
public int GetHeight => _cruiserHeight;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// <summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
/// Конструктор
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес автомобиля</param>
|
|
|
|
|
/// <param name="bodyColor">Основной цвет</param>
|
|
|
|
|
/// <param name="secColor">Элементов цвет</param>
|
|
|
|
|
/// <param name="width">Ширина картинки</param>
|
|
|
|
|
/// <param name="height">Высота картинки</param>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
public DrawingCruiser(int speed, double weight, Color bodyColor, Color secColor, int width, int height)
|
2023-09-25 11:15:05 +04:00
|
|
|
|
{
|
2023-09-25 14:09:42 +04:00
|
|
|
|
if (width < _cruiserWidth || height < _cruiserHeight)
|
2023-09-25 11:15:05 +04:00
|
|
|
|
{
|
|
|
|
|
_pictureHeight = _cruiserHeight + 100;
|
|
|
|
|
_pictureWidth = _cruiserWidth + 100;
|
|
|
|
|
}
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
2023-09-25 14:09:42 +04:00
|
|
|
|
EntityCruiser = new EntityCruiser(speed, weight, bodyColor, secColor);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес автомобиля</param>
|
|
|
|
|
/// <param name="bodyColor">Основной цвет</param>
|
|
|
|
|
/// <param name="secColor">Элементов цвет</param>
|
|
|
|
|
/// <param name="width">Ширина картинки</param>
|
|
|
|
|
/// <param name="height">Высота картинки</param>
|
|
|
|
|
/// <param name="cruiserWidth">Ширина прорисовки крейсера</param>
|
|
|
|
|
/// <param name="cruiserHeight">Высота прорисовки крейсера</param>
|
|
|
|
|
public DrawingCruiser(int speed, double weight, Color bodyColor, Color secColor, int width, int height, int cruiserWidth, int cruiserHeight)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
|
|
|
|
_cruiserHeight = cruiserHeight;
|
|
|
|
|
_cruiserWidth = cruiserWidth;
|
|
|
|
|
EntityCruiser = new EntityCruiser(speed, weight, bodyColor, secColor);
|
2023-09-25 11:15:05 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка позиции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="x">Координата X</param>
|
|
|
|
|
/// <param name="y">Координата Y</param>
|
|
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
|
{
|
2023-09-25 14:09:42 +04:00
|
|
|
|
if (x < 0 || y < 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (x > _pictureWidth || y > _pictureHeight)
|
2023-09-25 11:15:05 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
/// Проверка, что объект может переместится по указанному направлению
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direction">Направление</param>
|
|
|
|
|
/// <returns>true - можно переместится по указанному направлению</returns>
|
|
|
|
|
public bool CanMove(Direction direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityCruiser == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return direction switch
|
|
|
|
|
{
|
|
|
|
|
//влево
|
|
|
|
|
Direction.Left => _startPosX - EntityCruiser.Step > 0,
|
|
|
|
|
//вверх
|
|
|
|
|
Direction.Up => _startPosY - EntityCruiser.Step > 0,
|
|
|
|
|
// вправо
|
|
|
|
|
Direction.Right => _startPosX + EntityCruiser.Step + _cruiserWidth < _pictureWidth,
|
|
|
|
|
//вниз
|
|
|
|
|
Direction.Down => _startPosY + EntityCruiser.Step + _cruiserHeight < _pictureHeight,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// Изменение направления перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direction">Направление</param>
|
|
|
|
|
public void MoveTransport(Direction direction)
|
|
|
|
|
{
|
2023-09-25 14:09:42 +04:00
|
|
|
|
if (!CanMove(direction) || EntityCruiser == null)
|
2023-09-25 11:15:05 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
//влево
|
|
|
|
|
case Direction.Left:
|
2023-09-25 14:09:42 +04:00
|
|
|
|
_startPosX -= (int)EntityCruiser.Step;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
break;
|
|
|
|
|
//вверх
|
|
|
|
|
case Direction.Up:
|
2023-09-25 14:09:42 +04:00
|
|
|
|
_startPosY -= (int)EntityCruiser.Step;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
break;
|
|
|
|
|
// вправо
|
|
|
|
|
case Direction.Right:
|
2023-09-25 14:09:42 +04:00
|
|
|
|
_startPosX += (int)EntityCruiser.Step;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
break;
|
|
|
|
|
//вниз
|
|
|
|
|
case Direction.Down:
|
2023-09-25 14:09:42 +04:00
|
|
|
|
_startPosY += (int)EntityCruiser.Step;
|
2023-09-25 11:15:05 +04:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-25 14:09:42 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-25 11:15:05 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
2023-09-25 14:09:42 +04:00
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
2023-09-25 11:15:05 +04:00
|
|
|
|
{
|
|
|
|
|
if (EntityCruiser == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// палуба
|
|
|
|
|
Point[] Paluba = new Point[5]
|
|
|
|
|
{
|
|
|
|
|
new Point(_startPosX + 10,_startPosY),
|
|
|
|
|
new Point(_startPosX + 110,_startPosY),
|
|
|
|
|
new Point(_startPosX + 160,_startPosY + 30),
|
|
|
|
|
new Point(_startPosX + 110,_startPosY + 60),
|
|
|
|
|
new Point(_startPosX + 10,_startPosY + 60)
|
|
|
|
|
};
|
2023-09-25 14:09:42 +04:00
|
|
|
|
Brush brush = new SolidBrush(EntityCruiser.BodyColor);
|
2023-09-25 11:15:05 +04:00
|
|
|
|
g.FillPolygon(brush, Paluba);
|
|
|
|
|
// элементы
|
2023-09-25 14:09:42 +04:00
|
|
|
|
Point[] Elements = new Point[8]
|
2023-09-25 11:15:05 +04:00
|
|
|
|
{
|
|
|
|
|
new Point(_startPosX + 50,_startPosY + 20),
|
|
|
|
|
new Point(_startPosX + 70,_startPosY + 20),
|
|
|
|
|
new Point(_startPosX + 70,_startPosY + 10),
|
|
|
|
|
new Point(_startPosX + 90,_startPosY + 10),
|
|
|
|
|
new Point(_startPosX + 90,_startPosY + 50),
|
|
|
|
|
new Point(_startPosX + 70,_startPosY + 50),
|
|
|
|
|
new Point(_startPosX + 70,_startPosY + 40),
|
|
|
|
|
new Point(_startPosX + 50,_startPosY + 40),
|
|
|
|
|
};
|
2023-09-25 14:09:42 +04:00
|
|
|
|
Brush brushElem = new SolidBrush(EntityCruiser.SecondColor);
|
2023-09-25 11:15:05 +04:00
|
|
|
|
g.FillPolygon(brushElem, Elements);
|
|
|
|
|
g.FillEllipse(brushElem, _startPosX + 100, _startPosY + 20, 20, 20);
|
|
|
|
|
// турбины
|
|
|
|
|
Brush Turbins = new SolidBrush(Color.Black);
|
|
|
|
|
g.FillRectangle(Turbins, _startPosX, _startPosY + 10, 10, 20);
|
|
|
|
|
g.FillRectangle(Turbins, _startPosX, _startPosY + 35, 10, 20);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|