190 lines
6.4 KiB
C#
190 lines
6.4 KiB
C#
using System.Drawing.Drawing2D;
|
|
|
|
namespace ProjectCruiser;
|
|
public class DrawningBase
|
|
{
|
|
// Класс-сущность
|
|
public EntityBase? EntityB { get; private set; }
|
|
private int? _pictureWidth; // Ширина окна
|
|
private int? _pictureHeight; // Высота окна
|
|
private int? _startPosX; // Левая координата прорисовки автомобиля
|
|
private int? _startPosY; // Верхняя кооридната прорисовки автомобиля
|
|
|
|
private readonly int _drawningWidth = 300; // Ширина прорисовки автомобиля
|
|
private readonly int _drawningHeight = 42; // Высота прорисовки автомобиля
|
|
|
|
// Инициализация свойств
|
|
public void Init(int speed, double weight,
|
|
Color bodyColor, Color additionalColor, bool pad,
|
|
bool hangar, bool deckhouse)
|
|
{
|
|
EntityB = new EntityBase();
|
|
EntityB.Init(speed, weight, bodyColor,
|
|
additionalColor, pad, hangar, deckhouse);
|
|
|
|
_pictureWidth = null;
|
|
_pictureHeight = null;
|
|
_startPosX = null;
|
|
_startPosY = null;
|
|
}
|
|
|
|
public int getHeight() // для создания объекта в нижнем левом углу (*)
|
|
{
|
|
return _drawningHeight;
|
|
}
|
|
|
|
// Установка границ поля
|
|
public bool SetPictureSize(int w, int h)
|
|
{
|
|
if (w > _pictureWidth || h > _pictureHeight)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
_pictureWidth = w;
|
|
_pictureHeight = h;
|
|
|
|
if (_startPosX != null || _startPosY != null)
|
|
{
|
|
SetPosition(_startPosX.Value, _startPosY.Value);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void SetPosition(int x, int y)
|
|
{
|
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (x > _pictureWidth - _drawningWidth) _startPosX =
|
|
_pictureWidth - _drawningWidth;
|
|
else if (x < 0) _startPosX = 0;
|
|
else _startPosX = x;
|
|
|
|
if (y > _pictureHeight - _drawningHeight) _startPosY =
|
|
_pictureHeight.Value - _drawningHeight;
|
|
else if (y < 0) _startPosY = 0;
|
|
else _startPosY = y;
|
|
}
|
|
|
|
public bool MoveTransport(DirectionType direction)
|
|
{
|
|
if (EntityB == null || !_startPosX.HasValue ||
|
|
!_startPosY.HasValue)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
switch (direction)
|
|
{
|
|
//влево
|
|
case DirectionType.Left:
|
|
if (_startPosX.Value - EntityB.Step > 0)
|
|
{
|
|
_startPosX -= (int)EntityB.Step;
|
|
}
|
|
return true;
|
|
//вверх
|
|
case DirectionType.Up:
|
|
if (_startPosY.Value - EntityB.Step > 0)
|
|
{
|
|
_startPosY -= (int)EntityB.Step;
|
|
}
|
|
return true;
|
|
// вправо
|
|
case DirectionType.Right:
|
|
if (_startPosX.Value + _drawningWidth + EntityB.Step
|
|
< _pictureWidth.Value)
|
|
{
|
|
_startPosX += (int)EntityB.Step;
|
|
}
|
|
return true;
|
|
//вниз
|
|
case DirectionType.Down:
|
|
if (_startPosY.Value + _drawningHeight + EntityB.Step
|
|
< _pictureHeight.Value)
|
|
{
|
|
_startPosY += (int)EntityB.Step;
|
|
}
|
|
return true;
|
|
|
|
default:
|
|
return false;
|
|
// Перемещение объекта (удалось перемещение - true \ false)
|
|
}
|
|
}
|
|
|
|
public void DrawTransport(Graphics g)
|
|
{
|
|
if (EntityB == null || !_startPosX.HasValue ||
|
|
!_startPosY.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Pen pen = new(Color.Black, 2);
|
|
Brush PadBrush = new HatchBrush(HatchStyle.DottedDiamond, Color.LightGray, Color.Black);
|
|
Brush additionalBrush = new SolidBrush(EntityB.AdditionalColor);
|
|
Brush mainBrush = new SolidBrush(EntityB.MainColor);
|
|
|
|
//границы cruiser
|
|
Point point0 = new Point(_startPosX.Value + 2, _startPosY.Value + 7);
|
|
Point point1 = new Point(_startPosX.Value + 2, _startPosY.Value + 30);
|
|
Point point2 = new Point(_startPosX.Value + 184, _startPosY.Value + 42);
|
|
Point point3 = new Point(_startPosX.Value + 260, _startPosY.Value + 34);
|
|
Point point4 = new Point(_startPosX.Value + 300, _startPosY.Value + 22);
|
|
Point point5 = new Point(_startPosX.Value + 260, _startPosY.Value + 10);
|
|
Point point6 = new Point(_startPosX.Value + 184, _startPosY.Value + 2);
|
|
|
|
Point[] boarders = {
|
|
point0,
|
|
point1,
|
|
point2,
|
|
point3,
|
|
point4,
|
|
point5,
|
|
point6
|
|
};
|
|
|
|
g.DrawPolygon(pen, boarders);
|
|
g.FillPolygon(mainBrush, boarders);
|
|
|
|
// вертолетная площадка
|
|
if (EntityB.HelicopterPads)
|
|
{
|
|
g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
|
g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
|
}
|
|
|
|
// салон на верхней палубе
|
|
if (EntityB.Deckhouse)
|
|
{
|
|
// random location
|
|
int y_h = EntityB.values[1];
|
|
g.DrawRectangle(pen, _startPosX.Value + 100, _startPosY.Value + y_h, 38, 24); // 40, 26
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
|
|
g.FillRectangle(additionalBrush, _startPosX.Value + 110, _startPosY.Value + y_h + 6, 20, 12);
|
|
g.DrawRectangle(pen, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
|
|
g.FillRectangle(additionalBrush, _startPosX.Value + 117, _startPosY.Value + y_h + 18, 6, 20);
|
|
}
|
|
|
|
// ангар
|
|
if (EntityB.Hangar)
|
|
{
|
|
int n = EntityB.values[2];
|
|
if (n == 1) g.FillRectangle(additionalBrush, _startPosX.Value + 250, _startPosY.Value + 20, 14, 7);
|
|
|
|
else
|
|
{
|
|
g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 10, 10, 20);
|
|
g.FillRectangle(additionalBrush, _startPosX.Value + 70, _startPosY.Value + 12, 8, 12);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|