236 lines
8.6 KiB
C#
236 lines
8.6 KiB
C#
namespace AntiAircraftGun;
|
||
/// <summary>
|
||
/// Класс отвечающий за прорисовку и перемещение объекта - сущности
|
||
/// </summary>
|
||
public class DrawningAntiAircraftGun
|
||
{
|
||
/// <summary>
|
||
/// Класс - сущность
|
||
/// </summary>
|
||
public EntityAntiAircraftGun? EntityAntiAircraftGun { get; set; }
|
||
/// <summary>
|
||
/// Ширина окна
|
||
/// </summary>
|
||
private int? _pictureWidth;
|
||
/// <summary>
|
||
/// Высота окна
|
||
/// </summary>
|
||
private int? _pictureHeight;
|
||
/// <summary>
|
||
/// Левая координата прорисовки гидросамолета
|
||
/// </summary>
|
||
private int? _startPosX;
|
||
/// <summary>
|
||
/// Верхняя координата прорисовки гидросамолета
|
||
/// </summary>
|
||
private int? _startPosY;
|
||
/// <summary>
|
||
/// Ширина прорисовки гидросамолета
|
||
/// </summary>
|
||
private readonly int _drawningGunWidth = 130;
|
||
/// <summary>
|
||
/// Высота прорисовки гидросамолета
|
||
/// </summary>
|
||
private readonly int _drawningGunHeight = 50;
|
||
/// <summary>
|
||
/// Инициализация полей объекта-класса гидросамолета
|
||
/// </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);
|
||
Brush MainBrush = new SolidBrush(EntityAntiAircraftGun.BodyColor);
|
||
|
||
//основание
|
||
g.DrawEllipse(pen, _startPosX.Value, _startPosY.Value + 45, 20, 20);
|
||
g.DrawEllipse(pen, _startPosX.Value + 95, _startPosY.Value + 45, 20, 20);
|
||
|
||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 45, 100, 20);
|
||
g.FillRectangle(MainBrush, _startPosX.Value + 5, _startPosY.Value + 45, 100, 20);
|
||
|
||
g.FillEllipse(MainBrush, _startPosX.Value, _startPosY.Value + 45, 20, 20);
|
||
g.FillEllipse(MainBrush, _startPosX.Value + 95, _startPosY.Value + 45, 20, 20);
|
||
|
||
g.DrawRectangle(pen, _startPosX.Value + 5, _startPosY.Value + 35, 80, 10);
|
||
g.FillRectangle(MainBrush, _startPosX.Value + 5, _startPosY.Value + 35, 80, 10);
|
||
|
||
//катки
|
||
|
||
g.DrawEllipse(pen, _startPosX.Value + 5, _startPosY.Value + 45, 20, 20);
|
||
g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 45, 20, 20);
|
||
|
||
|
||
|
||
g.FillEllipse(MainBrush, _startPosX.Value + 5, _startPosY.Value + 45, 20, 20);
|
||
g.FillEllipse(MainBrush, _startPosX.Value, _startPosY.Value + 45, 20, 20);
|
||
|
||
g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 55, 10, 10);
|
||
g.FillEllipse(MainBrush, _startPosX.Value + 30, _startPosY.Value + 55, 10, 10);
|
||
|
||
g.DrawEllipse(pen, _startPosX.Value + 45, _startPosY.Value + 55, 10, 10);
|
||
g.FillEllipse(MainBrush, _startPosX.Value, _startPosY.Value + 55, 10, 10);
|
||
|
||
g.DrawEllipse(pen, _startPosX.Value + 60, _startPosY.Value + 55, 10, 10);
|
||
g.FillEllipse(MainBrush, _startPosX.Value, _startPosY.Value + 55, 10, 10);
|
||
|
||
g.DrawEllipse(pen, _startPosX.Value + 75, _startPosY.Value + 55, 10, 10);
|
||
g.FillEllipse(MainBrush, _startPosX.Value, _startPosY.Value + 55, 10, 10);
|
||
|
||
//tower_gin
|
||
if (EntityAntiAircraftGun.Tower)
|
||
{
|
||
g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 20, 50, 5);
|
||
g.FillRectangle(MainBrush, _startPosX.Value + 50, _startPosY.Value + 20, 50, 5);
|
||
|
||
g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 15, 30, 20);
|
||
g.FillRectangle(MainBrush, _startPosX.Value + 25, _startPosY.Value + 15, 30, 20);
|
||
}
|
||
//зенитка
|
||
if (EntityAntiAircraftGun.Radar)
|
||
{
|
||
|
||
}
|
||
|
||
|
||
}
|
||
} |