From 0d60e02b8a8a5ecf23a454666dc5fa5ab30b70f5 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 20:51:17 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20=D0=BF=D1=80=D0=BE=D1=80?= =?UTF-8?q?=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8=20DrawningAirPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 219 ++++++++++++++++++++++++ AirBomber/AirBomber/EntityAirPlane.cs | 31 +++- 2 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 AirBomber/AirBomber/DrawningAirPlane.cs diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs new file mode 100644 index 0000000..d884669 --- /dev/null +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -0,0 +1,219 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class DrawningAirPlane + { + /// + /// Класс-сущность + /// + public EntityAirPlane? EntityAirPlane { get; protected set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + /// + /// Левая координата прорисовки самолета + /// + protected int _startPosX; + /// + /// Верхняя кооридната прорисовки самолета + /// + protected int _startPosY; + /// + /// Ширина прорисовки самолета + /// + protected readonly int _airPlaneWidth = 100; + /// + /// Высота прорисовки самолета + /// + protected readonly int _airPlaneHeight = 55; + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Ширина картинки + /// Высота картинки + public DrawningAirPlane(int speed, double weight, Color bodyColor, int + width, int height) + { + // TODO: Продумать проверки + _pictureWidth = width; + _pictureHeight = height; + EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); + } + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Ширина картинки + /// Высота картинки + /// Ширина прорисовки самолета + /// Высота прорисовки самолета + protected DrawningAirPlane(int speed, double weight, Color bodyColor, int + width, int height, int airPlaneWidth, int airPlaneHeight) + { + // TODO: Продумать проверки + _pictureWidth = width; + _pictureHeight = height; + _airPlaneWidth = airPlaneWidth; + _airPlaneHeight = airPlaneHeight; + EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + // TODO: Изменение x, y, если при установке объект выходит за границы + _startPosX = x; + _startPosY = y; + } + /// + /// Изменение направления перемещения + /// + /// Направление + public void MoveTransport(DirectionType direction) + { + if (EntityAirPlane == null) + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX - EntityAirPlane.Step > 0) + { + _startPosX -= (int)EntityAirPlane.Step; + } + break; + //вверх + case DirectionType.Up: + if (_startPosY - EntityAirPlane.Step > 0) + { + _startPosY -= (int)EntityAirPlane.Step; + } + break; + // вправо + case DirectionType.Right: + // TODO: Продумать логику + break; + //вниз + case DirectionType.Down: + // TODO: Продумать логику + break; + } + } + /// + /// Прорисовка объекта + /// + /// + public virtual void DrawPlane(Graphics g) + { + if (EntityAirPlane == null) + { + return; + } + Pen pen = new(Color.Black); + Brush bodyColor = new SolidBrush(EntityAirPlane.BodyColor); + Brush wingsColor = new SolidBrush(Color.DeepPink); + g.FillPolygon(bodyColor, new Point[] //nose + { + new Point(_startPosX + 19, _startPosY + 50), + new Point(_startPosX + 19, _startPosY + 69), + new Point(_startPosX + 1, _startPosY + 59), + } + ); + g.FillRectangle(bodyColor, _startPosX + 20, _startPosY + 50, 120, 20); //body + g.FillPolygon(bodyColor, new Point[] //up left wing + { + new Point(_startPosX + 36, _startPosY + 49), + new Point(_startPosX + 36, _startPosY + 1), + new Point(_startPosX + 45, _startPosY + 1), + new Point(_startPosX + 55, _startPosY + 49), + } + ); + g.FillPolygon(bodyColor, new Point[] //down left wing + { + new Point(_startPosX + 36, _startPosY + 71), + new Point(_startPosX + 36, _startPosY + 116), + new Point(_startPosX + 45, _startPosY + 116), + new Point(_startPosX + 54, _startPosY + 71), + } + ); + g.FillPolygon(wingsColor, new Point[] //up right wing + { + new Point(_startPosX + 120, _startPosY + 49), + new Point(_startPosX + 120, _startPosY + 42), + new Point(_startPosX + 140, _startPosY + 7), + new Point(_startPosX + 140, _startPosY + 49), + } + ); + g.FillPolygon(wingsColor, new Point[] //down right wing + { + new Point(_startPosX + 120, _startPosY + 70), + new Point(_startPosX + 120, _startPosY + 77), + new Point(_startPosX + 140, _startPosY + 112), + new Point(_startPosX + 140, _startPosY + 70), + } + ); + + g.DrawPolygon(pen, new Point[] //nose + { + new Point(_startPosX + 20, _startPosY + 49), + new Point(_startPosX + 20, _startPosY + 70), + new Point(_startPosX, _startPosY + 59), + } + ); + g.DrawRectangle(pen, _startPosX + 19, _startPosY + 49, 121, 21); //body + g.DrawPolygon(pen, new Point[] //up left wing + { + new Point(_startPosX + 35, _startPosY + 49), + new Point(_startPosX + 35, _startPosY), + new Point(_startPosX + 45, _startPosY), + new Point(_startPosX + 55, _startPosY + 49), + } + ); + g.DrawPolygon(pen, new Point[] //down left wing + { + new Point(_startPosX + 36, _startPosY + 71), + new Point(_startPosX + 36, _startPosY + 116), + new Point(_startPosX + 45, _startPosY + 116), + new Point(_startPosX + 54, _startPosY + 71), + } + ); + g.DrawPolygon(pen, new Point[] //up right wing + { + new Point(_startPosX + 120, _startPosY + 49), + new Point(_startPosX + 120, _startPosY + 42), + new Point(_startPosX + 140, _startPosY + 7), + new Point(_startPosX + 140, _startPosY + 49), + } + ); + g.DrawPolygon(pen, new Point[] //down right wing + { + new Point(_startPosX + 120, _startPosY + 70), + new Point(_startPosX + 120, _startPosY + 77), + new Point(_startPosX + 140, _startPosY + 112), + new Point(_startPosX + 140, _startPosY + 70), + } + ); + } + + } +} diff --git a/AirBomber/AirBomber/EntityAirPlane.cs b/AirBomber/AirBomber/EntityAirPlane.cs index 643523a..d0f206c 100644 --- a/AirBomber/AirBomber/EntityAirPlane.cs +++ b/AirBomber/AirBomber/EntityAirPlane.cs @@ -6,7 +6,36 @@ using System.Threading.Tasks; namespace AirBomber { - internal class EntityAirPlane + public class EntityAirPlane { + /// + /// Скорость + /// + public int Speed { get; private set; } + /// + /// Вес + /// + public double Weight { get; private set; } + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + /// + /// Шаг перемещения самолета + /// + public double Step => (double)Speed * 100 / Weight; + /// + /// Конструктор с параметрами + /// + /// Скорость + /// Вес самолета + /// Основной цвет + public EntityAirPlane(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } + } }