From 218296886787633af80aaec546fc148377e83786 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 25 Sep 2023 23:03:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=81=D1=82=D0=BE=D0=B3=D0=BE=20=D0=BE=D0=B1?= =?UTF-8?q?=D1=8A=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectStormtrooper/DrawingPlane.cs | 211 ++++++++++++++++++ .../ProjectStormtrooper/EntityPlane.cs | 6 + 2 files changed, 217 insertions(+) create mode 100644 ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs diff --git a/ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs b/ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs new file mode 100644 index 0000000..cc21783 --- /dev/null +++ b/ProjectStormtrooper/ProjectStormtrooper/DrawingPlane.cs @@ -0,0 +1,211 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectStormtrooper +{ + /// + /// Класс отвечающий за прорисовку и перемещение объекта-сущности + /// + public class DrawingPlane + { + /// + /// Класс-сущность + /// + public EntityPlane? EntityPlane{ get; protected set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + /// + /// Левая координата начала прорисовки + /// + private int _startPosX; + /// + /// Верхняя координата начала прорисовки + /// + private int _startPosY; + /// + /// Ширина прорисовки + /// + private readonly int _planeWidth = 110; + /// + /// Высота прорисовки + /// + private readonly int _planeHeight = 110; + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Ширина картинки + /// Высота картинки + public DrawingPlane(int speed, double weight, Color bodyColor, int width, int height) + { + if (width < _planeWidth && height < _planeHeight) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + EntityPlane = new EntityPlane(speed, weight, bodyColor); + } + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Ширина окна + /// Высота окна + /// Ширина объекта + /// Высота объекта + protected DrawingPlane(int speed, double weight, Color bodyColor, + int width, int height, int planeWidth, int planeHeight) + { + if (width < planeWidth && height < planeHeight) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + _planeWidth = planeWidth; + _planeHeight = planeHeight; + EntityPlane = new EntityPlane(speed, weight, bodyColor); + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if (x < 0) + { + x = 0; + } + else if (x > _pictureWidth - _planeWidth) + { + x = _pictureWidth - _planeWidth; + } + _startPosX = x; + + if (y < 0) + { + y = 0; + } + else if (y > _pictureHeight - _planeHeight) + { + y = _pictureHeight - _planeHeight; + } + _startPosY = y; + } + /// + /// Перемещение объекта + /// + /// Направление перемещения + public void MoveTransport(DirectionType direction) + { + if (EntityPlane == null) + { + return; + } + switch (direction) + { + // Вверх + case DirectionType.Up: + if (_startPosY - EntityPlane.Step >= 0) + { + _startPosY -= (int)EntityPlane.Step; + } + break; + // Вниз + case DirectionType.Down: + if (_startPosY + _planeHeight + EntityPlane.Step <= _pictureHeight) + { + _startPosY += (int)EntityPlane.Step; + } + break; + // Влево + case DirectionType.Left: + if (_startPosX - EntityPlane.Step >= 0) + { + _startPosX -= (int)EntityPlane.Step; + } + break; + // Вправо + case DirectionType.Right: + if (_startPosX + _planeWidth + EntityPlane.Step <= _pictureWidth) + { + _startPosX += (int)EntityPlane.Step; + } + break; + } + } + /// + /// Прорисовка объекта + /// + /// + public void DrawTransport(Graphics g) + { + if (EntityPlane == null) + { + return; + } + Pen penBlack = new Pen(Color.Black); + Brush brushBlack = new SolidBrush(Color.Black); + Brush brushBodyColor = new SolidBrush(EntityPlane.BodyColor); + + // Высота фюзеляжа + int bodyHeight = _planeHeight / 9; + + // Рисуем нос + + Point[] pointsCockPit = { + new Point(_startPosX, _startPosY + _planeHeight / 2), + new Point(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2), + new Point(_startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 + bodyHeight / 2) + }; + + g.FillPolygon(brushBlack, pointsCockPit); + + // Рисуем крылья + + Point[] pointsWings = { + new Point(_startPosX + _planeWidth / 2, _startPosY), + new Point(_startPosX + _planeWidth / 2 + _planeWidth / 15, _startPosY), + new Point(_startPosX + _planeWidth / 2 + _planeWidth / 6, _startPosY + _planeHeight / 2), + new Point(_startPosX + _planeWidth / 2 + _planeWidth / 15, _startPosY + _planeHeight), + new Point(_startPosX + _planeWidth / 2 , _startPosY + _planeHeight) + }; + + g.FillPolygon(brushBodyColor, pointsWings); + g.DrawPolygon(penBlack, pointsWings); + + // Рисуем хвостовое оперение + + Point[] pointsTail = { + new Point(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 - _planeHeight / 3), + new Point(_startPosX + _planeWidth - _planeWidth / 8, _startPosY + _planeHeight / 2 - _planeHeight / 8), + new Point(_startPosX + _planeWidth - _planeWidth / 8, _startPosY + _planeHeight / 2 + _planeHeight / 8), + new Point(_startPosX + _planeWidth, _startPosY + _planeHeight / 2 + _planeHeight / 3) + + }; + + g.FillPolygon(brushBodyColor, pointsTail); + g.DrawPolygon(penBlack, pointsTail); + + // Рисуем фюзеляж + + g.FillRectangle(brushBodyColor, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight); + g.DrawRectangle(penBlack, _startPosX + _planeWidth / 8, _startPosY + _planeHeight / 2 - bodyHeight / 2, _planeWidth - _planeWidth / 8, bodyHeight); + } + } +} diff --git a/ProjectStormtrooper/ProjectStormtrooper/EntityPlane.cs b/ProjectStormtrooper/ProjectStormtrooper/EntityPlane.cs index 3411574..f384c92 100644 --- a/ProjectStormtrooper/ProjectStormtrooper/EntityPlane.cs +++ b/ProjectStormtrooper/ProjectStormtrooper/EntityPlane.cs @@ -29,6 +29,12 @@ namespace ProjectStormtrooper /// Шаг перемещения /// public double Step => (double)Speed * 250 / Weight; + /// + /// Конструктор + /// + /// + /// + /// public EntityPlane(int speed, double weight, Color bodyColor) { Speed = speed;