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 { /// /// Класс-сущность /// public EntityAircraftGun? EntityAircraftGun { get; protected set; } /// /// Ширина /// private int? _pictureWidth; /// /// Высота /// private int? _pictureHeight; /// /// Левая координата прорисовки зенитной установки /// protected int? _startPosX; /// /// Верхняя координата прорисовки зенитной установки /// protected int? _startPosY; /// /// Ширина прорисовки зенитной установки /// private readonly int _drawningGunWidth = 129; /// /// Высота прорисовки зенитной установки /// private readonly int _drawningGunHeight = 105; /// /// Координата Х объекта /// public int? GetPosX => _startPosX; /// /// Координата Y объекта /// public int? GetPosY => _startPosY; /// /// Ширина объекта /// public int GetWidth => _drawningGunWidth; /// /// Высота объекта /// public int GetHeight => _drawningGunHeight; /// /// Пустой конструктор /// private DrawningAircraftGun() { _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } /// /// Конструктор /// /// Скорость /// Вес /// Основной цвет public DrawningAircraftGun(int speed, double weight, Color bodyColor) : this() { EntityAircraftGun = new EntityAircraftGun(speed, weight, bodyColor); } /// /// Конструктор для наследников /// /// Ширина прорисовки зенитной установки /// Высота прорисовки зенитной установки protected DrawningAircraftGun(int drawningGunWidth, int drawningGunHeight) : this() { _drawningGunWidth = drawningGunWidth; _drawningGunHeight = drawningGunHeight; } /// /// Установка границ поля /// /// /// /// 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; } /// /// Установка позиций /// /// /// 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; } } /// /// Изменение направления перемещения /// /// Направление /// 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; } } /// /// Прорисовка объекта /// /// 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); } }