using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms.Design.Behavior;
namespace WarmlyShip
{
///
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
///
internal class DrawningWarmlyShip
{
///
/// Класс-сущность
///
public EntityWarmlyShip? EntityWarmlyShip { get; private set; }
///
/// Ширина окна
///
private int _pictureWidth;
///
/// Высота окна
///
private int _pictureHeight;
///
/// Левая координата прорисовки корабля
///
private int _startPosX;
///
/// Верхняя кооридната прорисовки корабля
///
private int _startPosY;
///
/// Ширина прорисовки корабля
///
private readonly int _shipWidth = 140;
///
/// Высота прорисовки корабля
///
private readonly int _shipHeight = 60;
///
/// Инициализация свойств
///
/// Скорость
/// Вес
/// Цвет корпуса
/// Дополнительный цвет
/// Признак наличия труб
/// Признак наличия отсека для топлива
/// Ширина картинки
/// Высота картинки
/// true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах
public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool pipe, bool fuelCompartment, int width, int height)
{
if (width < _shipWidth || height < _shipHeight)
{
return false;
}
_pictureWidth = width;
_pictureHeight = height;
EntityWarmlyShip = new EntityWarmlyShip();
EntityWarmlyShip.Init(speed, weight, bodyColor, additionalColor, pipe, fuelCompartment);
return true;
}
///
/// Установка позиции
///
/// Координата X
/// Координата Y
public void SetPosition(int x, int y)
{
if (x < 0 || x + _shipWidth > _pictureWidth)
{
x = Math.Max(0, _pictureWidth - _shipWidth);
}
if (y < 0 || y + _shipHeight > _pictureHeight)
{
y = Math.Max(0, _pictureHeight - _shipHeight);
}
_startPosX = x;
_startPosY = y;
}
///
/// Изменение направления перемещения
///
/// Направление
public void MoveTransport(DirectionType direction)
{
if (EntityWarmlyShip == null)
{
return;
}
switch (direction)
{
//влево
case DirectionType.Left:
if (_startPosX - EntityWarmlyShip.Step > 0)
{
_startPosX -= (int)EntityWarmlyShip.Step;
}
break;
//вверх
case DirectionType.Up:
if (_startPosY - EntityWarmlyShip.Step > 0)
{
_startPosY -= (int)EntityWarmlyShip.Step;
}
break;
// вправо
case DirectionType.Right:
if (_startPosX + _shipWidth + EntityWarmlyShip.Step < _pictureWidth)
{
_startPosX += (int)EntityWarmlyShip.Step;
}
break;
//вниз
case DirectionType.Down:
if (_startPosY + _shipHeight + EntityWarmlyShip.Step < _pictureHeight)
{
_startPosY += (int)EntityWarmlyShip.Step;
}
break;
}
}
///
/// Прорисовка объекта
///
///
public void DrawTransport(Graphics g)
{
if (EntityWarmlyShip == null)
{
return;
}
Pen pen = new(Color.Black);
Brush BodyBrush = new SolidBrush(EntityWarmlyShip.BodyColor);
Brush additionalBrush = new SolidBrush(EntityWarmlyShip.AdditionalColor);
// корпус
Point point1 = new Point(_startPosX, _startPosY + 30);
Point point2 = new Point(_startPosX + 140, _startPosY + 30);
Point point3 = new Point(_startPosX + 120, _startPosY + 60);
Point point4 = new Point(_startPosX + 20, _startPosY + 60);
Point[] curvePoints = { point1, point2, point3, point4 };
g.FillPolygon(BodyBrush, curvePoints);
g.DrawPolygon(pen, curvePoints);
// палуба
Brush brBeige = new SolidBrush(Color.Beige);
g.FillRectangle(brBeige, _startPosX + 10, _startPosY + 20, 110, 10);
g.DrawRectangle(pen, _startPosX + 10, _startPosY + 20, 110, 10);
// якорь
Point point_1 = new Point(_startPosX + 130, _startPosY + 40);
Point point_2 = new Point(_startPosX + 130, _startPosY + 33);
g.DrawLine(pen, point_1, point_2);
Point point_3 = new Point(_startPosX + 130, _startPosY + 40);
Point point_4 = new Point(_startPosX + 127, _startPosY + 37);
g.DrawLine(pen, point_3, point_4);
Point point_5 = new Point(_startPosX + 130, _startPosY + 40);
Point point_6 = new Point(_startPosX + 133, _startPosY + 37);
g.DrawLine(pen, point_5, point_6);
Point point_7 = new Point(_startPosX + 129, _startPosY + 35);
Point point_8 = new Point(_startPosX + 131, _startPosY + 35);
g.DrawLine(pen, point_7, point_8);
if (EntityWarmlyShip.Pipe)
{
//трубы
g.FillRectangle(additionalBrush, _startPosX + 20, _startPosY + 5, 10, 15);
g.DrawRectangle(pen, _startPosX + 20, _startPosY + 5, 10, 15);
g.FillRectangle(additionalBrush, _startPosX + 60, _startPosY + 5, 10, 15);
g.DrawRectangle(pen, _startPosX + 60, _startPosY + 5, 10, 15);
g.FillRectangle(additionalBrush, _startPosX + 100, _startPosY + 5, 10, 15);
g.DrawRectangle(pen, _startPosX + 100, _startPosY + 5, 10, 15);
Brush brBlack = new SolidBrush(Color.Black);
g.FillRectangle(brBlack, _startPosX + 20, _startPosY, 10, 5);
g.DrawRectangle(pen, _startPosX + 20, _startPosY, 10, 5);
g.FillRectangle(brBlack, _startPosX + 60, _startPosY, 10, 5);
g.DrawRectangle(pen, _startPosX + 60, _startPosY, 10, 5);
g.FillRectangle(brBlack, _startPosX + 100, _startPosY, 10, 5);
g.DrawRectangle(pen, _startPosX + 100, _startPosY, 10, 5);
}
if (EntityWarmlyShip.FuelCompartment)
{
// отсек под топливо
g.FillRectangle(additionalBrush, _startPosX + 30, _startPosY + 45, 20, 15);
g.DrawRectangle(pen, _startPosX + 30, _startPosY + 45, 20, 15);
g.FillRectangle(additionalBrush, _startPosX + 50, _startPosY + 45, 20, 15);
g.DrawRectangle(pen, _startPosX + 50, _startPosY + 45, 20, 15);
g.FillRectangle(additionalBrush, _startPosX + 70, _startPosY + 45, 20, 15);
g.DrawRectangle(pen, _startPosX + 70, _startPosY + 45, 20, 15);
}
}
}
}