2024-02-21 17:00:14 +04:00
|
|
|
|
namespace AntiAircraftGun;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс отвечающий за прорисовку и перемещение объекта - сущности
|
|
|
|
|
/// </summary>
|
2024-02-22 15:22:05 +04:00
|
|
|
|
public class DrawningAntiAircraftGun
|
2024-02-21 17:00:14 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Класс - сущность
|
|
|
|
|
/// </summary>
|
|
|
|
|
public EntityAntiAircraftGun? EntityAntiAircraftGun { get; set; }
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureWidth;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота окна
|
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureHeight;
|
|
|
|
|
/// <summary>
|
2024-03-03 09:52:46 +04:00
|
|
|
|
/// Левая координата прорисовки зенитной установки
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _startPosX;
|
|
|
|
|
/// <summary>
|
2024-03-03 09:52:46 +04:00
|
|
|
|
/// Верхняя координата прорисовки зенитной установки
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _startPosY;
|
|
|
|
|
/// <summary>
|
2024-03-03 09:52:46 +04:00
|
|
|
|
/// Ширина прорисовки зенитной установки
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly int _drawningGunWidth = 130;
|
|
|
|
|
/// <summary>
|
2024-03-03 09:52:46 +04:00
|
|
|
|
/// Высота прорисовки зенитной установки
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// </summary>
|
2024-03-03 09:52:46 +04:00
|
|
|
|
private readonly int _drawningGunHeight = 100;
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// <summary>
|
2024-03-03 09:52:46 +04:00
|
|
|
|
/// Инициализация полей объекта-класса зенитной установки
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес</param>
|
|
|
|
|
/// <param name="bodyColor">Основной цвет</param>
|
|
|
|
|
/// <param name="additionalColor">Дополнительный цвет</param>
|
|
|
|
|
/// <param name="bodyKit">Наличие обвеса</param>
|
|
|
|
|
/// <param name="tower">Наличие башни</param>
|
|
|
|
|
/// <param name="radar">Наличие радара</param>
|
|
|
|
|
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bodyKit, bool tower, bool radar)
|
|
|
|
|
{
|
|
|
|
|
EntityAntiAircraftGun = new EntityAntiAircraftGun();
|
|
|
|
|
EntityAntiAircraftGun.Init(speed, weight, bodyColor, additionalColor, bodyKit, tower, radar);
|
|
|
|
|
_pictureWidth = null;
|
|
|
|
|
_pictureHeight = null;
|
|
|
|
|
_startPosX = null;
|
|
|
|
|
_startPosY = null;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка границ поля
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="width"></param>
|
|
|
|
|
/// <param name="height"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool SetPictureSize(int width, int height)
|
|
|
|
|
{
|
|
|
|
|
// TODO проверка, что объект "влезает" в размеры поля
|
|
|
|
|
// если влезает, сохраняем границы и корректируем позицию объекта,если она была уже установлена
|
|
|
|
|
if (width < _drawningGunWidth || height < _drawningGunHeight) { return false; };
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
|
|
|
|
if (_startPosX != null || _startPosY != null)
|
|
|
|
|
{
|
|
|
|
|
if (_startPosX + _drawningGunWidth > _pictureWidth)
|
|
|
|
|
{
|
|
|
|
|
_startPosX = -_drawningGunWidth + _pictureWidth;
|
|
|
|
|
}
|
|
|
|
|
else if (_startPosX < 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosX = 0;
|
|
|
|
|
}
|
|
|
|
|
if (_startPosY + _drawningGunHeight > _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY = -_drawningGunHeight + _pictureHeight;
|
|
|
|
|
}
|
|
|
|
|
else if (_startPosY < 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosY = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Установка позиций
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="x"></param>
|
|
|
|
|
/// <param name="y"></param>
|
|
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
|
|
|
|
// то надо изменить координаты, чтобы он оставался в этих границах
|
|
|
|
|
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (x + _drawningGunWidth > _pictureWidth)
|
|
|
|
|
{
|
|
|
|
|
_startPosX = _pictureWidth - _drawningGunWidth;
|
|
|
|
|
}
|
|
|
|
|
else if (x < 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosX = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_startPosX = x;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (y + _drawningGunHeight > _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY = _pictureHeight - _drawningGunHeight;
|
|
|
|
|
}
|
|
|
|
|
else if (y < 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosY = 0;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_startPosY = y;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменение направления перемещения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="direction">Направление</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool MoveTransport(DirectionType direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityAntiAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case DirectionType.Left:
|
|
|
|
|
if (_startPosX.Value - EntityAntiAircraftGun.Step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosX -= (int)EntityAntiAircraftGun.Step;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
case DirectionType.Right:
|
|
|
|
|
if (_startPosX.Value + _drawningGunWidth + EntityAntiAircraftGun.Step < _pictureWidth)
|
|
|
|
|
{
|
|
|
|
|
_startPosX += (int)EntityAntiAircraftGun.Step;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
case DirectionType.Down:
|
|
|
|
|
if (_startPosY.Value + _drawningGunHeight + EntityAntiAircraftGun.Step < _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY += (int)EntityAntiAircraftGun.Step;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
case DirectionType.Up: //вверх
|
|
|
|
|
if (_startPosY - EntityAntiAircraftGun.Step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosY -= (int)EntityAntiAircraftGun.Step;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
|
|
|
|
public void DrawTransport(Graphics g)
|
|
|
|
|
{
|
|
|
|
|
if (EntityAntiAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Pen pen = new(Color.Black);
|
2024-02-27 23:16:07 +04:00
|
|
|
|
Brush additionalBrush = new SolidBrush(EntityAntiAircraftGun.AdditionalColor);
|
|
|
|
|
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 10, _startPosY.Value + 75, 30, 30);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 75, 30, 30);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 75, 90, 30);
|
|
|
|
|
|
|
|
|
|
//границы ЦВЕТ
|
|
|
|
|
Brush brDarkSlateGray = new SolidBrush(EntityAntiAircraftGun.BodyColor);
|
|
|
|
|
g.FillRectangle(brDarkSlateGray, _startPosX.Value + 35, _startPosY.Value + 40, 35, 30);
|
|
|
|
|
g.FillEllipse(brDarkSlateGray, _startPosX.Value + 10, _startPosY.Value + 75, 30, 30);
|
|
|
|
|
g.FillEllipse(brDarkSlateGray, _startPosX.Value + 100, _startPosY.Value + 75, 30, 30);
|
|
|
|
|
g.FillRectangle(brDarkSlateGray, _startPosX.Value + 25, _startPosY.Value + 75, 90, 30);
|
|
|
|
|
|
|
|
|
|
// границы арт. установки
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 40, 35, 30);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 65, 120, 13);
|
|
|
|
|
|
|
|
|
|
//нижние катки ЦВЕТ
|
|
|
|
|
Brush brDimGray = new SolidBrush(Color.SlateGray);
|
|
|
|
|
g.FillEllipse(brDimGray, _startPosX.Value + 40, _startPosY.Value + 90, 15, 15);
|
|
|
|
|
g.FillEllipse(brDimGray, _startPosX.Value + 55, _startPosY.Value + 90, 15, 15);
|
|
|
|
|
g.FillEllipse(brDimGray, _startPosX.Value + 70, _startPosY.Value + 90, 15, 15);
|
|
|
|
|
g.FillEllipse(brDimGray, _startPosX.Value + 85, _startPosY.Value + 90, 15, 15);
|
|
|
|
|
|
|
|
|
|
//нижние катки ОТРИСОВКА
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 40, _startPosY.Value + 90, 15, 15);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 55, _startPosY.Value + 90, 15, 15);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 70, _startPosY.Value + 90, 15, 15);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 85, _startPosY.Value + 90, 15, 15);
|
|
|
|
|
|
|
|
|
|
//Большие катки ЦВЕТ
|
|
|
|
|
Brush brSlateGray = new SolidBrush(Color.SlateGray);
|
|
|
|
|
g.FillEllipse(brSlateGray, _startPosX.Value + 13, _startPosY.Value + 78, 24, 24);
|
|
|
|
|
g.FillEllipse(brSlateGray, _startPosX.Value + 103, _startPosY.Value + 78, 24, 24);
|
|
|
|
|
|
|
|
|
|
//Большие катки ОТРИСОВКА
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 13, _startPosY.Value + 78, 24, 24);
|
|
|
|
|
g.DrawEllipse(pen, _startPosX.Value + 103, _startPosY.Value + 78, 24, 24);
|
|
|
|
|
|
|
|
|
|
g.FillRectangle(brDarkSlateGray, _startPosX.Value + 10, _startPosY.Value + 65, 120, 13);
|
2024-02-21 17:00:14 +04:00
|
|
|
|
|
|
|
|
|
if (EntityAntiAircraftGun.Tower)
|
|
|
|
|
{
|
2024-03-03 09:52:46 +04:00
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 50, 35, 15);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 50, 35, 15);
|
2024-02-28 14:04:19 +04:00
|
|
|
|
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 50, _startPosX.Value + 90, _startPosY.Value + 20);
|
|
|
|
|
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 50, _startPosX.Value + 95, _startPosY.Value + 27);
|
|
|
|
|
g.DrawLine(pen, _startPosX.Value + 45, _startPosY.Value + 50, _startPosX.Value + 60, _startPosY.Value + 50);
|
2024-03-03 09:52:46 +04:00
|
|
|
|
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 20, _startPosX.Value + 95, _startPosY.Value + 27);
|
|
|
|
|
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 20, _startPosX.Value + 100, _startPosY.Value + 20);
|
|
|
|
|
g.DrawLine(pen, _startPosX.Value + 100, _startPosY.Value + 20, _startPosX.Value + 95, _startPosY.Value + 27);
|
|
|
|
|
|
2024-02-23 18:36:51 +04:00
|
|
|
|
}
|
2024-02-27 23:16:07 +04:00
|
|
|
|
|
2024-02-21 17:00:14 +04:00
|
|
|
|
if (EntityAntiAircraftGun.Radar)
|
|
|
|
|
{
|
2024-02-28 14:04:19 +04:00
|
|
|
|
g.DrawLine(pen, _startPosX.Value + 20, _startPosY.Value + 65, _startPosX.Value + 20, _startPosY.Value + 40);
|
|
|
|
|
g.FillRectangle(additionalBrush, _startPosX.Value + 10, _startPosY.Value + 40, 20, 20);
|
|
|
|
|
g.DrawRectangle(pen, _startPosX.Value + 10, _startPosY.Value + 40, 20, 20);
|
2024-02-21 17:00:14 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-02-23 18:36:51 +04:00
|
|
|
|
|
2024-02-21 17:00:14 +04:00
|
|
|
|
}
|
|
|
|
|
}
|