2024-03-03 11:38:17 +04:00
|
|
|
|
using AntiAircraftGun.Entities;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AntiAircraftGun.Drawnings;
|
|
|
|
|
|
|
|
|
|
public class DrawningAircraftGun
|
2024-02-21 17:00:14 +04:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2024-03-03 11:38:17 +04:00
|
|
|
|
/// Класс-сущность
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// </summary>
|
2024-03-03 11:38:17 +04:00
|
|
|
|
public EntityAircraftGun? EntityAircraftGun { get; protected set; }
|
|
|
|
|
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// <summary>
|
2024-03-03 11:38:17 +04:00
|
|
|
|
/// Ширина
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureWidth;
|
2024-03-03 11:38:17 +04:00
|
|
|
|
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// <summary>
|
2024-03-03 11:38:17 +04:00
|
|
|
|
/// Высота
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// </summary>
|
|
|
|
|
private int? _pictureHeight;
|
2024-03-03 11:38:17 +04:00
|
|
|
|
|
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>
|
2024-03-03 11:38:17 +04:00
|
|
|
|
protected int? _startPosX;
|
|
|
|
|
|
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>
|
2024-03-03 11:38:17 +04:00
|
|
|
|
protected int? _startPosY;
|
|
|
|
|
|
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>
|
2024-03-03 11:38:17 +04:00
|
|
|
|
private readonly int _drawningGunWidth = 129;
|
|
|
|
|
|
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>
|
2024-03-03 11:38:17 +04:00
|
|
|
|
private readonly int _drawningGunHeight = 105;
|
|
|
|
|
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// <summary>
|
2024-03-03 11:38:17 +04:00
|
|
|
|
/// Координата Х объекта
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// </summary>
|
2024-03-03 11:38:17 +04:00
|
|
|
|
public int? GetPosX => _startPosX;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Координата Y объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int? GetPosY => _startPosY;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Ширина объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetWidth => _drawningGunWidth;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Высота объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
public int GetHeight => _drawningGunHeight;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Пустой конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
private DrawningAircraftGun()
|
2024-02-21 17:00:14 +04:00
|
|
|
|
{
|
|
|
|
|
_pictureWidth = null;
|
|
|
|
|
_pictureHeight = null;
|
|
|
|
|
_startPosX = null;
|
|
|
|
|
_startPosY = null;
|
|
|
|
|
}
|
2024-03-03 11:38:17 +04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="speed">Скорость</param>
|
|
|
|
|
/// <param name="weight">Вес</param>
|
|
|
|
|
/// <param name="bodyColor">Основной цвет</param>
|
|
|
|
|
public DrawningAircraftGun(int speed, double weight, Color bodyColor) : this()
|
|
|
|
|
{
|
|
|
|
|
EntityAircraftGun = new EntityAircraftGun(speed, weight, bodyColor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Конструктор для наследников
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="drawningGunWidth">Ширина прорисовки зенитной установки</param>
|
|
|
|
|
/// <param name="drawningGunHeight">Высота прорисовки зенитной установки</param>
|
|
|
|
|
protected DrawningAircraftGun(int drawningGunWidth, int drawningGunHeight) : this()
|
|
|
|
|
{
|
|
|
|
|
_drawningGunWidth = drawningGunWidth;
|
|
|
|
|
_drawningGunHeight = drawningGunHeight;
|
|
|
|
|
}
|
2024-02-21 17:00:14 +04:00
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2024-03-03 11:38:17 +04:00
|
|
|
|
if (EntityAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
2024-02-21 17:00:14 +04:00
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case DirectionType.Left:
|
2024-03-03 11:38:17 +04:00
|
|
|
|
if (_startPosX.Value - EntityAircraftGun.Step > 0)
|
2024-02-21 17:00:14 +04:00
|
|
|
|
{
|
2024-03-03 11:38:17 +04:00
|
|
|
|
_startPosX -= (int)EntityAircraftGun.Step;
|
2024-02-21 17:00:14 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
case DirectionType.Right:
|
2024-03-03 11:38:17 +04:00
|
|
|
|
if (_startPosX.Value + _drawningGunWidth + EntityAircraftGun.Step < _pictureWidth)
|
2024-02-21 17:00:14 +04:00
|
|
|
|
{
|
2024-03-03 11:38:17 +04:00
|
|
|
|
_startPosX += (int)EntityAircraftGun.Step;
|
2024-02-21 17:00:14 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
case DirectionType.Down:
|
2024-03-03 11:38:17 +04:00
|
|
|
|
if (_startPosY.Value + _drawningGunHeight + EntityAircraftGun.Step < _pictureHeight)
|
2024-02-21 17:00:14 +04:00
|
|
|
|
{
|
2024-03-03 11:38:17 +04:00
|
|
|
|
_startPosY += (int)EntityAircraftGun.Step;
|
2024-02-21 17:00:14 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
case DirectionType.Up: //вверх
|
2024-03-03 11:38:17 +04:00
|
|
|
|
if (_startPosY - EntityAircraftGun.Step > 0)
|
2024-02-21 17:00:14 +04:00
|
|
|
|
{
|
2024-03-03 11:38:17 +04:00
|
|
|
|
_startPosY -= (int)EntityAircraftGun.Step;
|
2024-02-21 17:00:14 +04:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Прорисовка объекта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="g"></param>
|
2024-03-03 11:38:17 +04:00
|
|
|
|
public virtual void DrawTransport(Graphics g)
|
2024-02-21 17:00:14 +04:00
|
|
|
|
{
|
2024-03-03 11:38:17 +04:00
|
|
|
|
if (EntityAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
2024-02-21 17:00:14 +04:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Pen pen = new(Color.Black);
|
2024-02-27 23:16:07 +04:00
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
//границы ЦВЕТ
|
2024-03-03 11:38:17 +04:00
|
|
|
|
Brush brDarkSlateGray = new SolidBrush(EntityAircraftGun.BodyColor);
|
2024-02-27 23:16:07 +04:00
|
|
|
|
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
|
|
|
|
|
2024-03-03 11:38:17 +04:00
|
|
|
|
|
2024-02-21 17:00:14 +04:00
|
|
|
|
|
2024-02-23 18:36:51 +04:00
|
|
|
|
|
2024-02-21 17:00:14 +04:00
|
|
|
|
}
|
2024-03-03 11:38:17 +04:00
|
|
|
|
}
|