using System; using System.Collections.Generic; using System.Linq; using System.Net.Http.Headers; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; namespace AirBomber; /// /// Класс, отвечающий за отрисовку и перемещение объекта-сущности /// public class DrawningAirBomber { /// /// Класс-сущность /// public EntityAirBomber? EntityAirBomber { get; private set; } /// /// Ширина окна отрисовки /// private int? _pictureWidth; /// /// Высота окна отрисовки /// private int? _pictureHeight; /// /// Левая координата отрисовки бомбардировщика /// public int? _startPosX; /// /// Верхняя координата отрисовки бомбардировщика /// private int? _startPosY; /// /// Ширина отрисовки бомбардировщика /// private readonly int _drawningAirBomberWidth = 140; /// /// Высота отрисовки бомбардировщика /// private readonly int _drawningAirBomberHeight = 128; /// /// /// /// Скорость /// Вес /// Основной цвет /// Дополнительный цвет /// Признак наличия бомб /// Признак наличия дополнительный топливных баков public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks) { EntityAirBomber = new EntityAirBomber(); EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, bombs, fuelTanks); _pictureHeight = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } /// /// Установка границ поля /// /// <Ширина/param> /// Высота /// public bool SetPictureSize(int width, int height) { if (_drawningAirBomberHeight > height || _drawningAirBomberWidth > width) return false; _pictureHeight = height; _pictureWidth = width; if (_startPosX.HasValue || _startPosY.HasValue) { if (_startPosX + _drawningAirBomberWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningAirBomberWidth; else if (_startPosX < 0) _startPosX = 0; if (_startPosY + _drawningAirBomberHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningAirBomberHeight; else if (_startPosY < 0) _startPosY = 0; } return true; } /// /// Установка позиции /// /// Координата X /// Координата Y public void SetPosition(int x, int y) { if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) { return; } if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) return; if (x + _drawningAirBomberWidth > _pictureWidth) _startPosX = _pictureWidth - _drawningAirBomberWidth; else if (x < 0) _startPosX = 0; else _startPosX = x; if (y + _drawningAirBomberHeight > _pictureHeight) _startPosY = _pictureHeight - _drawningAirBomberHeight; else if (y < 0) _startPosY = 0; else _startPosY = y; } public bool MoveAirBomber(DirectionType direction) { if (EntityAirBomber == null || !_startPosX.HasValue || !_startPosY.HasValue) { return false; } switch (direction) { //влево case DirectionType.Left: if (_startPosX.Value - EntityAirBomber.Step > 0) { _startPosX -= (int)EntityAirBomber.Step; } return true; //вверх case DirectionType.Up: if (_startPosY.Value - EntityAirBomber.Step > 0) { _startPosY -= (int)EntityAirBomber.Step; } return true; //вправо case DirectionType.Right : if (_startPosX.Value + EntityAirBomber.Step + _drawningAirBomberWidth < _pictureWidth) { _startPosX += (int)EntityAirBomber.Step; } return true; //вниз case DirectionType.Down: if (_startPosY + EntityAirBomber.Step + _drawningAirBomberHeight < _pictureHeight) { _startPosY += (int)EntityAirBomber.Step; } return true; default: return false; } } /// /// Прорисовка объекта /// /// public void DrawAirBomber(Graphics g) { if (EntityAirBomber == null || !_startPosX.HasValue || !_startPosY.HasValue) { return; } Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(EntityAirBomber.AdditionalColor); if (EntityAirBomber.FuelTanks) { //Дополнительные топливные баки g.FillEllipse(additionalBrush, _startPosX.Value + 90, _startPosY.Value + 50, 29, 29); g.DrawEllipse(pen, _startPosX.Value + 90, _startPosY.Value + 50, 29, 29); g.FillEllipse(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 50, 29, 29); g.DrawEllipse(pen, _startPosX.Value + 30, _startPosY.Value + 50, 29, 29); } Brush brGreen = new SolidBrush(Color.Green); Brush brRed = new SolidBrush(Color.Red); Brush BodyBrush = new SolidBrush(EntityAirBomber.BodyColor); //Бомбы if (EntityAirBomber.Bombs) { Point[] Bomb1Point = { new Point(_startPosX.Value + 77, _startPosY.Value + 125), new Point(_startPosX.Value + 84, _startPosY.Value + 128), new Point(_startPosX.Value + 84, _startPosY.Value + 120), new Point(_startPosX.Value + 79, _startPosY.Value + 122) }; g.FillPolygon(brGreen, Bomb1Point); g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value + 125, _startPosX.Value + 84, _startPosY.Value + 128); g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value + 128, _startPosX.Value + 84, _startPosY.Value + 120); g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value + 120, _startPosX.Value + 79, _startPosY.Value + 122); g.FillRectangle(brGreen, _startPosX.Value + 65, _startPosY.Value + 121, 5, 5); g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 121, 5, 5); Point[] BombNose1Point = { new Point(_startPosX.Value + 65, _startPosY.Value + 119), new Point(_startPosX.Value + 60, _startPosY.Value + 123), new Point(_startPosX.Value + 65, _startPosY.Value + 128) }; g.FillPolygon(brRed, BombNose1Point); Point[] Bomb2Point = { new Point(_startPosX.Value + 77, _startPosY.Value + 3), new Point(_startPosX.Value + 84, _startPosY.Value), new Point(_startPosX.Value + 84, _startPosY.Value + 8), new Point(_startPosX.Value + 79, _startPosY.Value + 6) }; g.FillPolygon(brGreen, Bomb2Point); g.DrawLine(pen, _startPosX.Value + 77, _startPosY.Value + 3, _startPosX.Value + 84, _startPosY.Value); g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value, _startPosX.Value + 84, _startPosY.Value + 8); g.DrawLine(pen, _startPosX.Value + 84, _startPosY.Value + 8, _startPosX.Value + 79, _startPosY.Value + 6); g.FillRectangle(brGreen, _startPosX.Value + 65, _startPosY.Value + 2, 5, 5); g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 2, 5, 5); Point[] BombNose2Point = { new Point(_startPosX.Value + 65, _startPosY.Value + 9), new Point(_startPosX.Value + 60, _startPosY.Value + 5), new Point(_startPosX.Value + 65, _startPosY.Value) }; g.FillPolygon(brRed, BombNose2Point); } //Корпус 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); } }