2023-03-17 19:30:05 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Sailboat
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
|
|
|
|
/// </summary>
|
2023-04-14 14:36:46 +04:00
|
|
|
|
public class DrawingBoat
|
2023-03-17 19:30:05 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс-сущность
|
|
|
|
|
/// </summary>
|
2023-03-18 02:05:18 +04:00
|
|
|
|
public Boat Boat{ protected set; get; }
|
2023-03-17 19:30:05 +04:00
|
|
|
|
/// <summary>`
|
|
|
|
|
/// Левая координата отрисовки автомобиля
|
|
|
|
|
/// </summary>
|
2023-03-18 02:05:18 +04:00
|
|
|
|
protected float _startPosX;
|
2023-03-17 19:30:05 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Верхняя кооридната отрисовки автомобиля
|
|
|
|
|
/// </summary>
|
2023-03-18 02:05:18 +04:00
|
|
|
|
protected float _startPosY;
|
2023-03-17 19:30:05 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина окна отрисовки
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureWidth = null;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота окна отрисовки
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureHeight = null;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина отрисовки автомобиля
|
|
|
|
|
/// </summary>
|
2023-04-13 16:43:46 +04:00
|
|
|
|
private readonly int _boatWidth = 125;
|
2023-03-17 19:30:05 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота отрисовки автомобиля
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly int _boatHeight = 40;
|
|
|
|
|
/// <summary>
|
2023-04-13 16:43:46 +04:00
|
|
|
|
/// Инициализация свойств
|
2023-03-17 19:30:05 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес автомобиля</param>
|
|
|
|
|
/// <param name="bodyColor">Цвет кузова</param>
|
2023-03-18 02:05:18 +04:00
|
|
|
|
public DrawingBoat(int speed, float weight, Color bodyColor)
|
2023-03-17 19:30:05 +04:00
|
|
|
|
{
|
2023-03-18 02:05:18 +04:00
|
|
|
|
Boat = new Boat(speed, weight, bodyColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DrawingBoat(int speed, float weight, Color bodyColor, int boatHeight, int boatWith):
|
|
|
|
|
this(speed, weight, bodyColor)
|
|
|
|
|
{
|
|
|
|
|
_boatHeight = boatHeight;
|
|
|
|
|
_boatWidth = boatWith;
|
2023-03-17 19:30:05 +04:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка позиции автомобиля
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="x">Координата X</param>
|
|
|
|
|
/// <param name="y">Координата Y</param>
|
|
|
|
|
/// <param name="width">Ширина картинки</param>
|
|
|
|
|
/// <param name="height">Высота картинки</param>
|
|
|
|
|
public void SetPosition(int x, int y, int width, int height)
|
|
|
|
|
{
|
2023-04-13 16:43:46 +04:00
|
|
|
|
if (x >= 0 && y >= 0 && x < width - _boatWidth && y < height - _boatHeight)
|
2023-03-17 19:30:05 +04:00
|
|
|
|
{
|
|
|
|
|
_startPosX = x;
|
|
|
|
|
_startPosY = y;
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение направления перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direction">Направление</param>
|
|
|
|
|
public void MoveTransport(Direction direction)
|
|
|
|
|
{
|
|
|
|
|
if (!_pictureWidth.HasValue || !_pictureHeight.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
// вправо
|
|
|
|
|
case Direction.Right:
|
|
|
|
|
if (_startPosX + _boatWidth + ((int)Boat.Step) < _pictureWidth)
|
|
|
|
|
{
|
|
|
|
|
_startPosX += ((int)Boat.Step);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
//влево
|
|
|
|
|
case Direction.Left:
|
|
|
|
|
if (_startPosX > ((int)Boat.Step))
|
|
|
|
|
{
|
|
|
|
|
_startPosX -= ((int)Boat.Step);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
//вверх
|
|
|
|
|
case Direction.Up:
|
|
|
|
|
if (_startPosY > ((int)Boat.Step))
|
|
|
|
|
{
|
|
|
|
|
_startPosY -= ((int)Boat.Step);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
//вниз
|
|
|
|
|
case Direction.Down:
|
|
|
|
|
if (_startPosY + _boatHeight + ((int)Boat.Step) < _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY += ((int)Boat.Step);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
2023-04-13 16:43:46 +04:00
|
|
|
|
/// Отрисовка лодки
|
2023-03-17 19:30:05 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
2023-03-18 02:05:18 +04:00
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
2023-03-17 19:30:05 +04:00
|
|
|
|
{
|
|
|
|
|
if (_startPosX < 0 || _startPosY < 0
|
|
|
|
|
|| !_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Pen pen = new(Color.Black);
|
|
|
|
|
//корма
|
|
|
|
|
g.DrawLine(pen, _startPosX, _startPosY, _startPosX + 70, _startPosY);
|
|
|
|
|
g.DrawLine(pen, _startPosX, _startPosY, _startPosX, _startPosY+40);
|
|
|
|
|
g.DrawLine(pen, _startPosX, _startPosY + 40, _startPosX + 70, _startPosY+40);
|
|
|
|
|
//нос
|
|
|
|
|
g.DrawLine(pen, _startPosX + 70, _startPosY + 40, _startPosX + 120, _startPosY+20);
|
|
|
|
|
g.DrawLine(pen, _startPosX + 70, _startPosY, _startPosX + 120, _startPosY+20);
|
|
|
|
|
//внутренность
|
|
|
|
|
Rectangle rect = new Rectangle((int)_startPosX + 5, (int)_startPosY + 5, 60, 30);
|
|
|
|
|
g.DrawRectangle(pen, rect);
|
|
|
|
|
Brush br = new SolidBrush(Boat.BodyColor);
|
|
|
|
|
g.FillRectangle(br, rect);
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Смена границ формы отрисовки
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="width">Ширина картинки</param>
|
|
|
|
|
/// <param name="height">Высота картинки</param>
|
|
|
|
|
public void ChangeBorders(int width, int height)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
|
|
|
|
if (_pictureWidth <= _boatWidth || _pictureHeight <= _boatHeight)
|
|
|
|
|
{
|
|
|
|
|
_pictureWidth = null;
|
|
|
|
|
_pictureHeight = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (_startPosX + _boatWidth > _pictureWidth)
|
|
|
|
|
{
|
|
|
|
|
_startPosX = _pictureWidth.Value - _boatWidth;
|
|
|
|
|
}
|
|
|
|
|
if (_startPosY + _boatHeight > _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY = _pictureHeight.Value - _boatHeight;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-18 02:49:20 +04:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение текущей позиции объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public (float Left, float Right, float Top, float Bottom) GetCurrentPosition()
|
|
|
|
|
{
|
|
|
|
|
return (_startPosX, _startPosY, _startPosX + _boatWidth, _startPosY + _boatHeight);
|
|
|
|
|
}
|
2023-03-17 19:30:05 +04:00
|
|
|
|
}
|
|
|
|
|
}
|