2023-09-22 21:05:01 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Hydroplane
|
|
|
|
|
{
|
|
|
|
|
public class DrawningHydroplane
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс-сущность
|
|
|
|
|
/// </summary>
|
2023-09-22 23:38:10 +04:00
|
|
|
|
public EntityHydroplane? EntityHydroplane { get; private set; }
|
2023-09-22 21:05:01 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int _pictureWidth;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int _pictureHeight;
|
|
|
|
|
/// <summary>
|
2023-09-23 12:02:28 +04:00
|
|
|
|
/// Левая координата прорисовки гидроплана
|
2023-09-22 21:05:01 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private int _startPosX;
|
|
|
|
|
/// <summary>
|
2023-09-23 12:02:28 +04:00
|
|
|
|
/// Верхняя кооридната прорисовки гидроплана
|
2023-09-22 21:05:01 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private int _startPosY;
|
|
|
|
|
/// <summary>
|
2023-09-23 12:02:28 +04:00
|
|
|
|
/// Ширина прорисовки гидроплана
|
2023-09-22 21:05:01 +04:00
|
|
|
|
/// </summary>
|
2023-09-22 23:38:10 +04:00
|
|
|
|
private readonly int _planeWidth = 175;
|
2023-09-22 21:05:01 +04:00
|
|
|
|
/// <summary>
|
2023-09-23 12:02:28 +04:00
|
|
|
|
/// Высота прорисовки гидроплана
|
2023-09-22 21:05:01 +04:00
|
|
|
|
/// </summary>
|
2023-09-27 08:56:01 +04:00
|
|
|
|
private readonly int _planeHeight = 80;
|
2023-09-22 21:05:01 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Инициализация свойств
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес</param>
|
|
|
|
|
/// <param name="bodyColor">Цвет кузова</param>
|
|
|
|
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
2023-09-23 12:02:28 +04:00
|
|
|
|
/// <param name="boat">Признак наличия надувной лодки</param>
|
|
|
|
|
/// <param name="bobber">Признак наличия поплавков</param>
|
2023-09-22 21:05:01 +04:00
|
|
|
|
/// <param name="width">Ширина картинки</param>
|
|
|
|
|
/// <param name="height">Высота картинки</param>
|
|
|
|
|
/// <returns>true - объект создан, false - проверка не пройдена, нельзя создать объект в этих размерах</returns>
|
2023-09-22 23:38:10 +04:00
|
|
|
|
public bool Init(int speed, double weight, Color bodyColor, Color
|
|
|
|
|
additionalColor, bool boat, bool bobber, int width, int height)
|
2023-09-22 21:05:01 +04:00
|
|
|
|
{
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
2023-09-27 08:56:01 +04:00
|
|
|
|
if (_pictureWidth < _planeWidth || _pictureHeight < _planeHeight)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2023-09-22 23:38:10 +04:00
|
|
|
|
EntityHydroplane = new EntityHydroplane();
|
|
|
|
|
EntityHydroplane.Init(speed, weight, bodyColor, additionalColor,
|
|
|
|
|
boat, bobber);
|
2023-09-22 21:05:01 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-09-22 23:38:10 +04:00
|
|
|
|
|
2023-09-22 21:05:01 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка позиции
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="x">Координата X</param>
|
|
|
|
|
/// <param name="y">Координата Y</param>
|
|
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
|
{
|
2023-09-27 08:56:01 +04:00
|
|
|
|
_startPosX = Math.Min(x, _pictureWidth - _planeWidth);
|
|
|
|
|
_startPosY = Math.Min(y, _pictureHeight - _planeHeight);
|
2023-09-22 21:05:01 +04:00
|
|
|
|
}
|
2023-09-22 23:38:10 +04:00
|
|
|
|
|
2023-09-22 21:05:01 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение направления перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direction">Направление</param>
|
|
|
|
|
public void MoveTransport(DirectionType direction)
|
|
|
|
|
{
|
2023-09-22 23:38:10 +04:00
|
|
|
|
if (EntityHydroplane == null)
|
2023-09-22 21:05:01 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
//влево
|
|
|
|
|
case DirectionType.Left:
|
2023-09-22 23:38:10 +04:00
|
|
|
|
if (_startPosX - EntityHydroplane.Step > 0)
|
2023-09-22 21:05:01 +04:00
|
|
|
|
{
|
2023-09-22 23:38:10 +04:00
|
|
|
|
_startPosX -= (int)EntityHydroplane.Step;
|
2023-09-22 21:05:01 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
//вверх
|
|
|
|
|
case DirectionType.Up:
|
2023-09-22 23:38:10 +04:00
|
|
|
|
if (_startPosY - EntityHydroplane.Step > 0)
|
2023-09-22 21:05:01 +04:00
|
|
|
|
{
|
2023-09-22 23:38:10 +04:00
|
|
|
|
_startPosY -= (int)EntityHydroplane.Step;
|
2023-09-22 21:05:01 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
// вправо
|
|
|
|
|
case DirectionType.Right:
|
2023-09-22 23:38:10 +04:00
|
|
|
|
if (_startPosX + EntityHydroplane.Step + _planeWidth < _pictureWidth)
|
2023-09-22 21:05:01 +04:00
|
|
|
|
{
|
2023-09-22 23:38:10 +04:00
|
|
|
|
_startPosX += (int)EntityHydroplane.Step;
|
2023-09-22 21:05:01 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
//вниз
|
|
|
|
|
case DirectionType.Down:
|
2023-09-22 23:38:10 +04:00
|
|
|
|
if (_startPosY + EntityHydroplane.Step + _planeHeight < _pictureHeight)
|
2023-09-22 21:05:01 +04:00
|
|
|
|
{
|
2023-09-22 23:38:10 +04:00
|
|
|
|
_startPosY += (int)EntityHydroplane.Step;
|
2023-09-22 21:05:01 +04:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-09-22 23:38:10 +04:00
|
|
|
|
|
2023-09-22 21:05:01 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
|
|
|
|
public void DrawTransport(Graphics g)
|
|
|
|
|
{
|
2023-09-22 23:38:10 +04:00
|
|
|
|
if (EntityHydroplane == null)
|
2023-09-22 21:05:01 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Pen pen = new(Color.Black);
|
2023-09-23 12:02:28 +04:00
|
|
|
|
Brush additionalBrush = new SolidBrush(EntityHydroplane.AdditionalColor);
|
|
|
|
|
Brush bodyBrush = new SolidBrush(EntityHydroplane.BodyColor);
|
|
|
|
|
|
|
|
|
|
//раскраска основы
|
|
|
|
|
g.FillPolygon(bodyBrush, new[] {
|
|
|
|
|
new Point(_startPosX + 5, _startPosY),
|
|
|
|
|
new Point(_startPosX + 5, _startPosY + 55),
|
|
|
|
|
new Point(_startPosX + 130, _startPosY + 55),
|
|
|
|
|
new Point(_startPosX + 160, _startPosY + 40),
|
|
|
|
|
new Point(_startPosX + 130, _startPosY + 40),
|
|
|
|
|
new Point(_startPosX + 130, _startPosY + 25),
|
|
|
|
|
new Point(_startPosX + 55, _startPosY + 25) });
|
|
|
|
|
|
|
|
|
|
//раскраска ножек
|
|
|
|
|
g.FillRectangle(bodyBrush, _startPosX + 65, _startPosY + 55, 5, 15);
|
|
|
|
|
g.FillRectangle(bodyBrush, _startPosX + 125, _startPosY + 55, 5, 15);
|
|
|
|
|
|
|
|
|
|
//раскраска иллюминаторов
|
|
|
|
|
g.FillEllipse(additionalBrush, _startPosX + 40, _startPosY + 30, 10, 10);
|
|
|
|
|
g.FillEllipse(additionalBrush, _startPosX + 60, _startPosY + 30, 10, 10);
|
|
|
|
|
g.FillEllipse(additionalBrush, _startPosX + 80, _startPosY + 30, 10, 10);
|
|
|
|
|
|
|
|
|
|
//раскраска окна
|
|
|
|
|
g.FillPolygon(additionalBrush, new[]
|
2023-09-22 21:05:01 +04:00
|
|
|
|
{
|
2023-09-23 12:02:28 +04:00
|
|
|
|
new Point(_startPosX + 160, _startPosY + 40),
|
|
|
|
|
new Point(_startPosX + 130, _startPosY + 40),
|
|
|
|
|
new Point(_startPosX + 130, _startPosY + 25) });
|
|
|
|
|
|
2023-09-22 23:38:10 +04:00
|
|
|
|
//основа
|
|
|
|
|
g.DrawRectangle(pen, _startPosX + 5, _startPosY + 25, 125, 30);
|
|
|
|
|
|
|
|
|
|
//хвост
|
|
|
|
|
g.DrawLine(pen, _startPosX + 5, _startPosY + 25, _startPosX + 5, _startPosY);
|
|
|
|
|
g.DrawLine(pen, _startPosX + 55, _startPosY + 25, _startPosX + 5, _startPosY);
|
|
|
|
|
|
|
|
|
|
//нос
|
|
|
|
|
g.DrawLine(pen, _startPosX + 130, _startPosY + 25, _startPosX + 160, _startPosY + 40);
|
|
|
|
|
g.DrawLine(pen, _startPosX + 130, _startPosY + 55, _startPosX + 160, _startPosY + 40);
|
|
|
|
|
g.DrawLine(pen, _startPosX + 130, _startPosY + 40, _startPosX + 160, _startPosY + 40);
|
|
|
|
|
|
|
|
|
|
//иллюминаторы
|
|
|
|
|
g.DrawEllipse(pen, _startPosX + 40, _startPosY + 30, 10, 10);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX + 60, _startPosY + 30, 10, 10);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX + 80, _startPosY + 30, 10, 10);
|
|
|
|
|
|
|
|
|
|
//крыло сбоку
|
|
|
|
|
g.DrawEllipse(pen, _startPosX + 35, _startPosY + 43, 80, 7);
|
|
|
|
|
|
|
|
|
|
//ножки снизу
|
|
|
|
|
g.DrawLine(pen, _startPosX + 65, _startPosY + 55, _startPosX + 65, _startPosY + 70);
|
|
|
|
|
g.DrawLine(pen, _startPosX + 70, _startPosY + 55, _startPosX + 70, _startPosY + 70);
|
|
|
|
|
g.DrawLine(pen, _startPosX + 125, _startPosY + 55, _startPosX + 125, _startPosY + 70);
|
|
|
|
|
g.DrawLine(pen, _startPosX + 130, _startPosY + 55, _startPosX + 130, _startPosY + 70);
|
|
|
|
|
|
2023-09-23 12:02:28 +04:00
|
|
|
|
//поплавки(лыжи) или колеса
|
|
|
|
|
if (EntityHydroplane.Bobber)
|
2023-09-22 23:38:10 +04:00
|
|
|
|
{
|
2023-09-23 12:02:28 +04:00
|
|
|
|
g.FillPolygon(additionalBrush, new[]
|
|
|
|
|
{
|
|
|
|
|
new Point(_startPosX + 55, _startPosY + 70),
|
|
|
|
|
new Point(_startPosX + 55, _startPosY + 80),
|
|
|
|
|
new Point(_startPosX + 155, _startPosY + 80),
|
|
|
|
|
new Point(_startPosX + 175, _startPosY + 70) });
|
|
|
|
|
|
|
|
|
|
g.DrawPolygon(pen, new[]
|
|
|
|
|
{
|
|
|
|
|
new Point(_startPosX + 55, _startPosY + 70),
|
|
|
|
|
new Point(_startPosX + 55, _startPosY + 80),
|
|
|
|
|
new Point(_startPosX + 155, _startPosY + 80),
|
|
|
|
|
new Point(_startPosX + 175, _startPosY + 70) });
|
2023-09-22 23:38:10 +04:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-09-23 12:02:28 +04:00
|
|
|
|
g.FillEllipse(additionalBrush, _startPosX + 60, _startPosY + 70, 15, 15);
|
|
|
|
|
g.FillEllipse(additionalBrush, _startPosX + 120, _startPosY + 70, 15, 15);
|
|
|
|
|
|
2023-09-22 23:38:10 +04:00
|
|
|
|
g.DrawEllipse(pen, _startPosX + 60, _startPosY + 70, 15, 15);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX + 120, _startPosY + 70, 15, 15);
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-23 12:02:28 +04:00
|
|
|
|
//надувная лодка
|
|
|
|
|
if (EntityHydroplane.Boat)
|
2023-09-22 23:38:10 +04:00
|
|
|
|
{
|
2023-09-23 12:02:28 +04:00
|
|
|
|
g.FillEllipse(additionalBrush, _startPosX, _startPosY + 21, 32, 8);
|
2023-09-22 23:38:10 +04:00
|
|
|
|
g.DrawEllipse(pen, _startPosX, _startPosY + 21, 32, 8);
|
|
|
|
|
}
|
2023-09-22 21:05:01 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|