using AirBomber.Entities; using AirBomber.Drawnings; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AirBomber.Drawnings; public class DrawningAirPlane { /// /// Класс-сущность /// public EntityAirPlane? EntityAirPlane { get; protected set; } /// /// Ширина окна отрисовки /// private int? _pictureWidth; /// /// Высота окна отрисовки /// private int? _pictureHeight; /// /// Левая координата отрисовки бомбардировщика /// public int? _startPosX; /// /// Верхняя координата отрисовки бомбардировщика /// public int? _startPosY; /// /// Ширина отрисовки бомбардировщика /// private readonly int _drawningAirPlaneWidth = 140; /// /// Высота отрисовки бомбардировщика /// private readonly int _drawningAirPlaneHeight = 128; /// /// Координата X объекта /// public int? GetPosX => _startPosX; /// /// Координата Y объекта /// public int? GetPosY => _startPosY; /// /// Ширина объекта /// public int GetWidth => _drawningAirPlaneWidth; /// /// Высота объекта /// public int GetHeight => _drawningAirPlaneHeight; /// /// Пустой конструктор /// /// Пустой конструктор /// /// protected DrawningAirPlane() { _pictureHeight = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } /// /// Конструктор /// /// Скорость /// Вес /// Основной цвет public DrawningAirPlane(int speed, double weight, Color bodyColor) : this() { EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); } /// /// Конструктор для наследников /// /// Ширина прорисовки самолета /// Высота прорисовки самолета public DrawningAirPlane(int drawningAirBomberWidth, int drawningAirBomberHeight) : this() { _drawningAirPlaneHeight = drawningAirBomberHeight; _drawningAirPlaneWidth = drawningAirBomberWidth; } /// /// Конструктор через сущность /// /// public DrawningAirPlane(EntityAirPlane entityAirPlane) : base() { EntityAirPlane = entityAirPlane; } /// /// Установка границ поля /// /// <Ширина/param> /// Высота /// public bool SetPictureSize(int width, int height) { if (_drawningAirPlaneHeight > height || _drawningAirPlaneWidth > width) return false; _pictureHeight = height; _pictureWidth = width; if (_startPosX.HasValue || _startPosY.HasValue) { if (_startPosX + _drawningAirPlaneWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningAirPlaneWidth; else if (_startPosX < 0) _startPosX = 0; if (_startPosY + _drawningAirPlaneHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningAirPlaneHeight; else if (_startPosY < 0) _startPosY = 0; } return true; } /// /// Установка позиции /// /// Координата X /// Координата Y public void SetPosition(int x, int y) { if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) { return; } if (x + _drawningAirPlaneWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningAirPlaneWidth; else if (x < 0) _startPosX = 0; else _startPosX = x; if (y + _drawningAirPlaneHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningAirPlaneHeight; else if (y < 0) _startPosY = 0; else _startPosY = y; } public bool MoveTransport(DirectionType direction) { if (EntityAirPlane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } switch (direction) { //влево case DirectionType.Left: if (_startPosX.Value - EntityAirPlane.Step > 0) { _startPosX -= (int)EntityAirPlane.Step; } return true; //вверх case DirectionType.Up: if (_startPosY.Value - EntityAirPlane.Step > 0) { _startPosY -= (int)EntityAirPlane.Step; } return true; //вправо case DirectionType.Right: if (_startPosX.Value + EntityAirPlane.Step + _drawningAirPlaneWidth < _pictureWidth) { _startPosX += (int)EntityAirPlane.Step; } return true; //вниз case DirectionType.Down: if (_startPosY + EntityAirPlane.Step + _drawningAirPlaneHeight < _pictureHeight) { _startPosY += (int)EntityAirPlane.Step; } return true; default: return false; } } /// /// Прорисовка объекта /// /// public virtual void DrawTransport(Graphics g) { if (EntityAirPlane == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } Pen pen = new(Color.Black); Brush BodyBrush = new SolidBrush(EntityAirPlane.BodyColor); //Корпус Brush brGray = new SolidBrush(Color.Gray); g.FillRectangle(BodyBrush, _startPosX.Value + 20, _startPosY.Value + 55, 120, 18); g.DrawRectangle(pen, _startPosX.Value + 20, _startPosY.Value + 55, 120, 18); //Нос Brush brBlack = new SolidBrush(Color.Black); Point[] NosePoints = { new Point(_startPosX.Value + 20, _startPosY.Value + 55), new Point(_startPosX.Value, _startPosY.Value + 64), new Point(_startPosX.Value + 20, _startPosY.Value + 73) }; g.FillPolygon(brBlack, NosePoints); g.DrawLine(pen, _startPosX.Value + 20, _startPosY.Value + 55, _startPosX.Value, _startPosY.Value + 64); g.DrawLine(pen, _startPosX.Value, _startPosY.Value + 64, _startPosX.Value + 20, _startPosY.Value + 73); //Крылья Point[] UpperWingPoint = { new Point(_startPosX.Value + 71, _startPosY.Value + 55), new Point(_startPosX.Value + 71, _startPosY.Value + 1), new Point(_startPosX.Value + 77, _startPosY.Value + 1), new Point(_startPosX.Value + 85, _startPosY.Value + 54) }; g.FillPolygon(BodyBrush, UpperWingPoint); g.DrawLine(pen, _startPosX.Value + 70, _startPosY.Value + 55, _startPosX.Value + 70, _startPosY.Value); g.DrawLine(pen, _startPosX.Value + 70, _startPosY.Value, _startPosX.Value + 77, _startPosY.Value); g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value, _startPosX.Value + 85, _startPosY.Value + 55); Point[] LowerWingPoint = { new Point(_startPosX.Value + 71, _startPosY.Value + 74), new Point(_startPosX.Value + 71, _startPosY.Value + 128), new Point(_startPosX.Value + 77, _startPosY.Value + 128), new Point(_startPosX.Value + 85, _startPosY.Value + 74) }; g.FillPolygon(BodyBrush, LowerWingPoint); g.DrawLine(pen, _startPosX.Value + 70, _startPosY.Value + 73, _startPosX.Value + 70, _startPosY.Value + 128); g.DrawLine(pen, _startPosX.Value + 70, _startPosY.Value + 128, _startPosX.Value + 77, _startPosY.Value + 128); g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value + 128, _startPosX.Value + 85, _startPosY.Value + 73); //Хвост Point[] UpTailPoint = { new Point(_startPosX.Value + 140, _startPosY.Value + 55), new Point(_startPosX.Value + 140, _startPosY.Value + 27), new Point(_startPosX.Value + 120, _startPosY.Value + 46), new Point(_startPosX.Value + 120, _startPosY.Value + 55) }; g.FillPolygon(BodyBrush, UpTailPoint); g.DrawLine(pen, _startPosX.Value + 140, _startPosY.Value + 55, _startPosX.Value + 140, _startPosY.Value + 27); g.DrawLine(pen, _startPosX.Value + 140, _startPosY.Value + 27, _startPosX.Value + 120, _startPosY.Value + 46); g.DrawLine(pen, _startPosX.Value + 120, _startPosY.Value + 46, _startPosX.Value + 120, _startPosY.Value + 55); Point[] LowerTailPoint = { new Point(_startPosX.Value + 140, _startPosY.Value + 73), new Point(_startPosX.Value + 140, _startPosY.Value + 102), new Point(_startPosX.Value + 120, _startPosY.Value + 83), new Point(_startPosX.Value + 120, _startPosY.Value + 55) }; g.FillPolygon(BodyBrush, LowerTailPoint); g.DrawLine(pen, _startPosX.Value + 140, _startPosY.Value + 73, _startPosX.Value + 140, _startPosY.Value + 102); g.DrawLine(pen, _startPosX.Value + 140, _startPosY.Value + 102, _startPosX.Value + 120, _startPosY.Value + 83); g.DrawLine(pen, _startPosX.Value + 120, _startPosY.Value + 83, _startPosX.Value + 120, _startPosY.Value + 73); g.DrawLine(pen, _startPosX.Value + 140, _startPosY.Value + 73, _startPosX.Value + 100, _startPosY.Value + 73); } }