239 lines
8.7 KiB
C#
239 lines
8.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing.Drawing2D;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CruiserMech
|
|
{
|
|
internal class DrawingCruiser
|
|
{
|
|
/// Инициализация свойств (все параметры класса (сущности))
|
|
public Class_CruiserEntity? CruiserEntity { get; private set; }
|
|
|
|
|
|
/// Передача размеров поля для прорисовки (размеры поля - 2 параметра)
|
|
private int? _pictureWidth;
|
|
private int? _pictureHeight;
|
|
|
|
|
|
public readonly int _CruiserMaxW = 302; // 262
|
|
public readonly int _CruiserMaxH = 72; // 92
|
|
|
|
|
|
/// Установка начальной позиции (координаты - 2 параметра:
|
|
/// левая верхняя точка, от которой рисуется объект)
|
|
private int? _startPosX;
|
|
private int? _startPosY;
|
|
|
|
|
|
public void Init(Class_CruiserEntity CruiserEntity)
|
|
{
|
|
CruiserEntity = new Class_CruiserEntity();
|
|
}
|
|
|
|
|
|
public bool SetPicSize(int w, int h)
|
|
{
|
|
if (w > _pictureWidth || h > _pictureHeight)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
_pictureWidth = w;
|
|
_pictureHeight = h;
|
|
|
|
if (_startPosX != null || _startPosY != null)
|
|
{
|
|
SetPos(_startPosX.Value, _startPosY.Value);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void SetPos(int x, int y)
|
|
{
|
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (x > _pictureWidth - _CruiserMaxW) _startPosX = _pictureWidth - _CruiserMaxW;
|
|
else if (x < 0) _startPosX = 0;
|
|
else _startPosX = x;
|
|
|
|
if (y > _pictureHeight - _CruiserMaxH) _startPosY = _pictureHeight.Value - _CruiserMaxH;
|
|
else if (y < 0) _startPosY = 0;
|
|
else _startPosY = y;
|
|
}
|
|
|
|
public bool MoveTransport(DirectionType direction)
|
|
{
|
|
if (CruiserEntity == null || !_startPosX.HasValue ||
|
|
!_startPosY.HasValue)
|
|
{
|
|
return false;
|
|
}
|
|
switch (direction)
|
|
{
|
|
//влево
|
|
case DirectionType.Left:
|
|
if (_startPosX.Value - CruiserEntity.Step > 0)
|
|
{
|
|
_startPosX -= (int)CruiserEntity.Step;
|
|
}
|
|
return true;
|
|
//вверх
|
|
case DirectionType.Up:
|
|
if (_startPosY.Value - CruiserEntity.Step > 0)
|
|
{
|
|
_startPosY -= (int)CruiserEntity.Step;
|
|
}
|
|
return true;
|
|
// вправо
|
|
case DirectionType.Right:
|
|
if (_startPosX.Value + _CruiserMaxW + CruiserEntity.Step < _pictureWidth.Value)
|
|
{
|
|
_startPosX += (int)CruiserEntity.Step;
|
|
}
|
|
return true;
|
|
//вниз
|
|
case DirectionType.Down:
|
|
if (_startPosY.Value + _CruiserMaxH + CruiserEntity.Step < _pictureHeight.Value)
|
|
{
|
|
_startPosY += (int)CruiserEntity.Step;
|
|
}
|
|
return true;
|
|
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// Перемещение объекта (удалось перемещение - true \ false)
|
|
|
|
public void DrawTransport(Graphics g)
|
|
{
|
|
if (CruiserEntity == 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(CruiserEntity.AdditionalC);
|
|
Brush mainBrush = new SolidBrush(CruiserEntity.MainC);
|
|
|
|
Random random = new();
|
|
|
|
//границы cruiser
|
|
|
|
//Point point0 = new Point(_startPosX.Value + 2, _startPosY.Value + 22);
|
|
//Point point1 = new Point(_startPosX.Value + 5, _startPosY.Value + 66);
|
|
//Point point2 = new Point(_startPosX.Value + 184, _startPosY.Value + 90); // max y : 92
|
|
//Point point3 = new Point(_startPosX.Value + 184, _startPosY.Value + 70); // max x : 262
|
|
//Point point4 = new Point(_startPosX.Value + 260, _startPosY.Value + 62);
|
|
//Point point5 = new Point(_startPosX.Value + 260, _startPosY.Value + 32);
|
|
//Point point6 = new Point(_startPosX.Value + 172, _startPosY.Value + 18);
|
|
//Point point7 = new Point(_startPosX.Value + 160, _startPosY.Value + 2);
|
|
//Point point8 = new Point(_startPosX.Value + 2, _startPosY.Value + 22);
|
|
|
|
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 point7 = new Point(_startPosX.Value + 2, _startPosY.Value + 36);
|
|
|
|
Point[] boarders = {
|
|
point0,
|
|
point1,
|
|
point2,
|
|
point3,
|
|
point4,
|
|
point5,
|
|
point6,
|
|
//point7,
|
|
//point8
|
|
};
|
|
|
|
g.DrawPolygon(pen, boarders);
|
|
g.FillPolygon(mainBrush, boarders);
|
|
|
|
// вертолетная площадка (3)
|
|
//if (CruiserEntity.HelicopterPads)
|
|
//{
|
|
// random number of pads : from 1 to 3
|
|
// int n = CruiserEntity.values[0];
|
|
// int w = 15;
|
|
// int h = 41;
|
|
|
|
// for (int i = 1; i <= n; i++)
|
|
// {
|
|
// g.DrawEllipse(pen, _startPosX.Value + w, _startPosY.Value + h, 20, 20);
|
|
// g.FillEllipse(PadBrush, _startPosX.Value + w, _startPosY.Value + h, 20, 20);
|
|
// w += 28;
|
|
// h += 3;
|
|
// }
|
|
//}
|
|
|
|
|
|
if (CruiserEntity.HelicopterPads)
|
|
{
|
|
g.DrawEllipse(pen, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
|
g.FillEllipse(PadBrush, _startPosX.Value + 170, _startPosY.Value + 11, 20, 20);
|
|
}
|
|
|
|
|
|
// салон на верхней палубе
|
|
if (CruiserEntity.Deckhouse)
|
|
{
|
|
// random location
|
|
int y_h = CruiserEntity.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);
|
|
}
|
|
|
|
// ангар (2)
|
|
//if (CruiserEntity.Hangar)
|
|
//{
|
|
// int n = CruiserEntity.values[2];
|
|
|
|
// if (n == 1)
|
|
// {
|
|
// g.FillRectangle(additionalBrush, _startPosX.Value + 105, _startPosY.Value + 18, 14, 7);
|
|
// }
|
|
|
|
// else
|
|
// {
|
|
// g.FillRectangle(additionalBrush, _startPosX.Value + 146, _startPosY.Value + 52, 10, 26);
|
|
// g.FillRectangle(additionalBrush, _startPosX.Value + 160, _startPosY.Value + 58, 8, 12);
|
|
// }
|
|
//}
|
|
|
|
if (CruiserEntity.Hangar)
|
|
{
|
|
int n = CruiserEntity.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);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|