197 lines
8.6 KiB
C#
197 lines
8.6 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms.Design.Behavior;
|
|||
|
|
|||
|
namespace WarmlyShip
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
|||
|
/// </summary>
|
|||
|
internal class DrawningWarmlyShip
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// Класс-сущность
|
|||
|
/// </summary>
|
|||
|
public EntityWarmlyShip? EntityWarmlyShip { get; private 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 _shipWidth = 140;
|
|||
|
/// <summary>
|
|||
|
/// Высота прорисовки корабля
|
|||
|
/// </summary>
|
|||
|
private readonly int _shipHeight = 60;
|
|||
|
/// <summary>
|
|||
|
/// Инициализация свойств
|
|||
|
/// </summary>
|
|||
|
/// <param name="speed">Скорость</param>
|
|||
|
/// <param name="weight">Вес</param>
|
|||
|
/// <param name="bodyColor">Цвет корпуса</param>
|
|||
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
|||
|
/// <param name="pipe">Признак наличия труб</param>
|
|||
|
/// <param name="fuelCompartment">Признак наличия отсека для топлива</param>
|
|||
|
/// <param name="width">Ширина картинки</param>
|
|||
|
/// <param name="height">Высота картинки</param>
|
|||
|
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
|||
|
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;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Установка позиции
|
|||
|
/// </summary>
|
|||
|
/// <param name="x">Координата X</param>
|
|||
|
/// <param name="y">Координата Y</param>
|
|||
|
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;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Изменение направления перемещения
|
|||
|
/// </summary>
|
|||
|
/// <param name="direction">Направление</param>
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// Прорисовка объекта
|
|||
|
/// </summary>
|
|||
|
/// <param name="g"></param>
|
|||
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|