2023-10-08 21:06:26 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2023-10-11 09:42:48 +04:00
|
|
|
|
using Hydroplane.Entities;
|
2023-10-08 21:06:26 +04:00
|
|
|
|
|
2023-10-11 09:42:48 +04:00
|
|
|
|
namespace Hydroplane.DrawningObjects
|
2023-10-08 21:06:26 +04:00
|
|
|
|
{
|
|
|
|
|
public class DrawningPlane
|
|
|
|
|
{
|
|
|
|
|
public EntityPlane? EntityPlane { get; protected set; }
|
|
|
|
|
private int _pictureWidth;
|
|
|
|
|
private int _pictureHeight;
|
|
|
|
|
protected int _startPosX;
|
|
|
|
|
protected int _startPosY;
|
2023-10-11 09:42:48 +04:00
|
|
|
|
private readonly int _planeWidth = 175;
|
|
|
|
|
private readonly int _planeHeight = 80;
|
|
|
|
|
public int GetPosX => _startPosX;
|
|
|
|
|
public int GetPosY => _startPosY;
|
|
|
|
|
public int GetWidth => _planeWidth;
|
|
|
|
|
public int GetHeight => _planeHeight;
|
2023-10-08 21:06:26 +04:00
|
|
|
|
public DrawningPlane(int speed, double weight, Color bodyColor, int width, int height)
|
|
|
|
|
{
|
2023-10-11 09:42:48 +04:00
|
|
|
|
|
2023-10-08 21:06:26 +04:00
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
2023-10-11 09:42:48 +04:00
|
|
|
|
if (width < _pictureWidth || height < _pictureHeight)
|
2023-10-08 21:06:26 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 09:42:48 +04:00
|
|
|
|
protected DrawningPlane(int speed, double weight, Color bodyColor, int width, int height, int planeWidth, int planeHeight)
|
2023-10-08 21:06:26 +04:00
|
|
|
|
{
|
2023-10-11 09:42:48 +04:00
|
|
|
|
|
2023-10-08 21:06:26 +04:00
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
2023-10-11 09:42:48 +04:00
|
|
|
|
_pictureWidth = planeWidth;
|
|
|
|
|
_pictureHeight = planeHeight;
|
|
|
|
|
if (width < _pictureWidth || height < _pictureHeight)
|
2023-10-08 21:06:26 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
|
|
|
|
}
|
|
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
_startPosX = Math.Min(x, _pictureWidth - _planeWidth);
|
|
|
|
|
_startPosY = Math.Min(y, _pictureHeight - _planeHeight);
|
|
|
|
|
}
|
2023-10-08 21:22:30 +04:00
|
|
|
|
public bool CanMove(DirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityPlane == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return direction switch
|
|
|
|
|
{
|
|
|
|
|
//влево
|
|
|
|
|
DirectionType.Left => _startPosX - EntityPlane.Step > 0,
|
|
|
|
|
//вверх
|
|
|
|
|
DirectionType.Up => _startPosY - EntityPlane.Step > 0,
|
2023-10-11 09:42:48 +04:00
|
|
|
|
// вправо
|
2023-10-08 21:22:30 +04:00
|
|
|
|
DirectionType.Right => _startPosX + EntityPlane.Step < _pictureWidth,
|
|
|
|
|
//вниз
|
|
|
|
|
DirectionType.Down => _startPosY + EntityPlane.Step < _pictureHeight,
|
2023-10-11 09:42:48 +04:00
|
|
|
|
_ => false
|
2023-10-08 21:22:30 +04:00
|
|
|
|
};
|
|
|
|
|
}
|
2023-10-08 21:06:26 +04:00
|
|
|
|
public void MoveTransport(DirectionType direction)
|
|
|
|
|
{
|
2023-10-08 21:22:30 +04:00
|
|
|
|
if (!CanMove(direction) || EntityPlane == null)
|
2023-10-08 21:06:26 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
2023-10-11 09:42:48 +04:00
|
|
|
|
//влево
|
2023-10-08 21:06:26 +04:00
|
|
|
|
case DirectionType.Left:
|
|
|
|
|
if (_startPosX - EntityPlane.Step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosX -= (int)EntityPlane.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2023-10-11 09:42:48 +04:00
|
|
|
|
//вверх
|
2023-10-08 21:06:26 +04:00
|
|
|
|
case DirectionType.Up:
|
|
|
|
|
if (_startPosY - EntityPlane.Step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosY -= (int)EntityPlane.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2023-10-11 09:42:48 +04:00
|
|
|
|
// вправо
|
2023-10-08 21:06:26 +04:00
|
|
|
|
case DirectionType.Right:
|
2023-10-11 09:42:48 +04:00
|
|
|
|
if (_startPosX + EntityPlane.Step + _planeWidth < _pictureWidth)
|
2023-10-08 21:06:26 +04:00
|
|
|
|
{
|
|
|
|
|
_startPosX += (int)EntityPlane.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2023-10-11 09:42:48 +04:00
|
|
|
|
//вниз
|
2023-10-08 21:06:26 +04:00
|
|
|
|
case DirectionType.Down:
|
2023-10-11 09:42:48 +04:00
|
|
|
|
if (_startPosY + EntityPlane.Step + _planeHeight < _pictureHeight)
|
2023-10-08 21:06:26 +04:00
|
|
|
|
{
|
|
|
|
|
_startPosY += (int)EntityPlane.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
if (EntityPlane == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Pen pen = new(Color.Black);
|
|
|
|
|
Brush bodyBrush = new SolidBrush(EntityPlane.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) });
|
|
|
|
|
|
2023-10-11 09:42:48 +04:00
|
|
|
|
|
2023-10-08 21:06:26 +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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|