237 lines
9.5 KiB
C#
237 lines
9.5 KiB
C#
using ProjectCatamaran;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace ProjectCatamaran
|
||
{
|
||
/// <summary>
|
||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||
/// </summary>
|
||
public class DrawningCatamaran
|
||
{
|
||
/// <summary>
|
||
/// Класс-сущность
|
||
/// </summary>
|
||
public EntityCatamaran? EntityCatamaran { 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 int _CatamaranWidth = 200;
|
||
/// <summary>
|
||
/// Высота прорисовки автомобиля
|
||
/// </summary>
|
||
private int _CatamaranHeight = 120;
|
||
/// <summary>
|
||
/// Инициализация свойств
|
||
/// </summary>
|
||
/// <param name="speed">Скорость</param>
|
||
/// <param name="weight">Вес</param>
|
||
/// <param name="bodyColor">Цвет кузова</param>
|
||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||
/// /// <param name="boat">Лодка</param>
|
||
/// /// <param name="floater">Дополнительный цвет</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 boat, bool leftfloater, bool rightfloater, int width, int height)*/
|
||
public bool Init(int speed, double weight, Color bodyColor, Color
|
||
additionalColor, bool boat, bool leftfloater, bool rightfloater, int width, int height)
|
||
{
|
||
if (width < _pictureWidth || height < _pictureHeight)
|
||
{
|
||
return false;
|
||
}
|
||
if (!leftfloater && !rightfloater)
|
||
{
|
||
_CatamaranHeight = 90;
|
||
}
|
||
else
|
||
{
|
||
_CatamaranHeight = 110;
|
||
}
|
||
_pictureWidth = width;
|
||
_pictureHeight = height;
|
||
EntityCatamaran = new EntityCatamaran();
|
||
EntityCatamaran.Init(speed, weight, bodyColor, additionalColor, boat, leftfloater, rightfloater);
|
||
|
||
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 + _CatamaranWidth > _pictureWidth)
|
||
{
|
||
x = 20;
|
||
}
|
||
if (y < 0 || y + _CatamaranHeight > _pictureHeight)
|
||
{
|
||
y = 20;
|
||
}
|
||
_startPosX = x;
|
||
_startPosY = y;
|
||
|
||
}
|
||
/// <summary>
|
||
/// Изменение направления перемещения
|
||
/// </summary>
|
||
/// <param name="direction">Направление</param>
|
||
public void MoveTransport(DirectionType direction)
|
||
{
|
||
if (EntityCatamaran == null)
|
||
{
|
||
return;
|
||
}
|
||
switch (direction)
|
||
{
|
||
//влево
|
||
case DirectionType.Left:
|
||
if (_startPosX - EntityCatamaran.Step > 0)
|
||
{
|
||
_startPosX -= (int)EntityCatamaran.Step;
|
||
}
|
||
else
|
||
{
|
||
_startPosX = 0;
|
||
}
|
||
break;
|
||
//вверх
|
||
case DirectionType.Up:
|
||
if (_startPosY - EntityCatamaran.Step > 0)
|
||
{
|
||
_startPosY -= (int)EntityCatamaran.Step;
|
||
}
|
||
else
|
||
{
|
||
_startPosY = 0;
|
||
}
|
||
break;
|
||
// вправо
|
||
case DirectionType.Right:
|
||
if (_startPosX + _CatamaranWidth + EntityCatamaran.Step <= _pictureWidth)
|
||
{
|
||
_startPosX += (int)EntityCatamaran.Step;
|
||
}
|
||
else
|
||
{
|
||
_startPosX = _pictureWidth - _CatamaranWidth;
|
||
}
|
||
break;
|
||
//вниз
|
||
case DirectionType.Down:
|
||
if (_startPosY + _CatamaranHeight + EntityCatamaran.Step <= _pictureHeight)
|
||
{
|
||
_startPosY += (int)EntityCatamaran.Step;
|
||
}
|
||
else
|
||
{
|
||
_startPosY = _pictureHeight - _CatamaranHeight;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Прорисовка объекта
|
||
/// </summary>
|
||
/// <param name="g"></param>
|
||
public void DrawTransport(Graphics g)
|
||
{
|
||
if (EntityCatamaran == null)
|
||
{
|
||
return;
|
||
}
|
||
|
||
Pen pen = new(Color.Black);
|
||
Brush additionalBrush = new SolidBrush(EntityCatamaran.AdditionalColor);
|
||
|
||
// катамаран
|
||
|
||
// границы катамарана
|
||
g.DrawLine(pen, _startPosX + 10, _startPosY + 30, _startPosX + 150, _startPosY + 30);
|
||
g.DrawLine(pen, _startPosX + 150, _startPosY + 30, _startPosX + 150, _startPosY + 80);
|
||
g.DrawLine(pen, _startPosX + 10, _startPosY + 80, _startPosX + 150, _startPosY + 80);
|
||
g.DrawLine(pen, _startPosX + 150, _startPosY + 30, _startPosX + 200, _startPosY + 55);
|
||
g.DrawLine(pen, _startPosX + 200, _startPosY + 55, _startPosX + 150, _startPosY + 55);
|
||
g.DrawLine(pen, _startPosX + 200, _startPosY + 55, _startPosX + 150, _startPosY + 80);
|
||
g.DrawLine(pen, _startPosX + 10, _startPosY + 30, _startPosX + 10, _startPosY + 80);
|
||
|
||
Brush brGray = new SolidBrush(Color.Brown);
|
||
Point point1 = new Point(_startPosX + 10, _startPosY + 30);
|
||
Point point2 = new Point(_startPosX + 150, _startPosY + 30);
|
||
Point point3 = new Point(_startPosX + 150, _startPosY + 80);
|
||
Point point4 = new Point(_startPosX + 10, _startPosY + 80);
|
||
Point[] nos0 = { point1, point2, point3, point4 };
|
||
g.FillPolygon(brGray, nos0);
|
||
g.DrawLine(pen, _startPosX + 40, _startPosY + 40, _startPosX + 120, _startPosY + 40);
|
||
g.DrawLine(pen, _startPosX + 40, _startPosY + 70, _startPosX + 120, _startPosY + 70);
|
||
g.DrawPie(pen, _startPosX + 30, _startPosY + 40, 20, 30, 90, 180);
|
||
g.DrawPie(pen, _startPosX + 111, _startPosY + 40, 20, 30, 270, 180);
|
||
|
||
|
||
Brush mainBrush = new SolidBrush(EntityCatamaran.BodyColor);
|
||
|
||
point1 = new Point(_startPosX + 150, _startPosY + 30);
|
||
point2 = new Point(_startPosX + 200, _startPosY + 55);
|
||
point3 = new Point(_startPosX + 150, _startPosY + 55);
|
||
Point[] nos1 = { point1, point2, point3, point1 };
|
||
g.FillPolygon(brGray, nos1);
|
||
point4 = new Point(_startPosX + 150, _startPosY + 55);
|
||
Point point5 = new Point(_startPosX + 200, _startPosY + 55);
|
||
Point point6 = new Point(_startPosX + 150, _startPosY + 80);
|
||
Point[] nos2 = { point4, point5, point6, point4 };
|
||
g.FillPolygon(brGray, nos2);
|
||
|
||
//поплавки
|
||
if (EntityCatamaran.LeftFloater)
|
||
{
|
||
g.DrawEllipse(pen, _startPosX + 10, _startPosY + 10, 135, 20);
|
||
g.FillEllipse(additionalBrush, _startPosX + 10, _startPosY + 10, 135, 20);
|
||
}
|
||
|
||
if (EntityCatamaran.RightFloater)
|
||
{
|
||
g.DrawEllipse(pen, _startPosX + 10, _startPosY + 80, 135, 20);
|
||
g.FillEllipse(additionalBrush,_startPosX + 10, _startPosY + 80, 135, 20);
|
||
}
|
||
|
||
if (EntityCatamaran.Boat)
|
||
{
|
||
g.DrawLine(pen, _startPosX + 80, _startPosY + 55, _startPosX + 80, _startPosY + 0);
|
||
g.DrawLine(pen, _startPosX + 80, _startPosY + 0, _startPosX + 65, _startPosY + 50);
|
||
g.DrawLine(pen, _startPosX + 65, _startPosY + 50, _startPosX + 80, _startPosY + 50);
|
||
Point[] nos3 = { new Point(_startPosX + 80, _startPosY + 50), new Point(_startPosX + 80, _startPosY + 0), new Point(_startPosX + 65, _startPosY + 50) };
|
||
Brush brWhite = new SolidBrush(Color.White);
|
||
g.FillPolygon(brWhite, nos3);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
}
|
||
}
|