271 lines
8.8 KiB
C#
271 lines
8.8 KiB
C#
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
|
||
{
|
||
/// <summary>
|
||
/// Класс-сущность
|
||
/// </summary>
|
||
public EntityAircraftGun? EntityAircraftGun { get; protected set; }
|
||
|
||
/// <summary>
|
||
/// Ширина
|
||
/// </summary>
|
||
private int? _pictureWidth;
|
||
|
||
/// <summary>
|
||
/// Высота
|
||
/// </summary>
|
||
private int? _pictureHeight;
|
||
|
||
/// <summary>
|
||
/// Левая координата прорисовки зенитной установки
|
||
/// </summary>
|
||
protected int? _startPosX;
|
||
|
||
/// <summary>
|
||
/// Верхняя координата прорисовки зенитной установки
|
||
/// </summary>
|
||
protected int? _startPosY;
|
||
|
||
/// <summary>
|
||
/// Ширина прорисовки зенитной установки
|
||
/// </summary>
|
||
private readonly int _drawningGunWidth = 129;
|
||
|
||
/// <summary>
|
||
/// Высота прорисовки зенитной установки
|
||
/// </summary>
|
||
private readonly int _drawningGunHeight = 105;
|
||
|
||
/// <summary>
|
||
/// Координата Х объекта
|
||
/// </summary>
|
||
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()
|
||
{
|
||
_pictureWidth = null;
|
||
_pictureHeight = null;
|
||
_startPosX = null;
|
||
_startPosY = null;
|
||
}
|
||
|
||
/// <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;
|
||
}
|
||
/// <summary>
|
||
/// Установка границ поля
|
||
/// </summary>
|
||
/// <param name="width"></param>
|
||
/// <param name="height"></param>
|
||
/// <returns></returns>
|
||
public bool SetPictureSize(int width, int height)
|
||
{
|
||
|
||
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)
|
||
{
|
||
|
||
|
||
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 (EntityAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||
{
|
||
return false;
|
||
}
|
||
switch (direction)
|
||
{
|
||
case DirectionType.Left:
|
||
if (_startPosX.Value - EntityAircraftGun.Step > 0)
|
||
{
|
||
_startPosX -= (int)EntityAircraftGun.Step;
|
||
}
|
||
return true;
|
||
case DirectionType.Right:
|
||
if (_startPosX.Value + _drawningGunWidth + EntityAircraftGun.Step < _pictureWidth)
|
||
{
|
||
_startPosX += (int)EntityAircraftGun.Step;
|
||
}
|
||
return true;
|
||
case DirectionType.Down:
|
||
if (_startPosY.Value + _drawningGunHeight + EntityAircraftGun.Step < _pictureHeight)
|
||
{
|
||
_startPosY += (int)EntityAircraftGun.Step;
|
||
}
|
||
return true;
|
||
case DirectionType.Up: //вверх
|
||
if (_startPosY - EntityAircraftGun.Step > 0)
|
||
{
|
||
_startPosY -= (int)EntityAircraftGun.Step;
|
||
}
|
||
return true;
|
||
default:
|
||
return false;
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// Прорисовка объекта
|
||
/// </summary>
|
||
/// <param name="g"></param>
|
||
public virtual void DrawTransport(Graphics g)
|
||
{
|
||
if (EntityAircraftGun == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||
{
|
||
return;
|
||
}
|
||
|
||
Pen pen = new(Color.Black);
|
||
|
||
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(EntityAircraftGun.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);
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
}
|