From 2bfb286f5d3552a53f73792159d1f5eca6aca73a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=20=D0=91=D0=BE=D0=BD=D0=B4=D0=B0?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= Date: Tue, 18 Oct 2022 20:14:31 +0400 Subject: [PATCH] Puk --- WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs | 18 ++++++--- WarmlyShip/WarmlyShip/DrawningMotorShip.cs | 44 ++++++++++++++++++++++ WarmlyShip/WarmlyShip/EntityMotorShip.cs | 24 ++++++++++++ 3 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 WarmlyShip/WarmlyShip/DrawningMotorShip.cs create mode 100644 WarmlyShip/WarmlyShip/EntityMotorShip.cs diff --git a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs index 71908a5..1f6c264 100644 --- a/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs +++ b/WarmlyShip/WarmlyShip/DrawingWarmlyShip.cs @@ -8,13 +8,13 @@ namespace WarmlyShip { internal class DrawingWarmlyShip { - public EntityWarmlyShip warmlyShip { private set; get; } //Класс-сущность - public float _startPosX; //Координаты отрисовки по оси x - public float _startPosY; //Координаты отрисовки по оси y + public EntityWarmlyShip warmlyShip { protected set; get; } //Класс-сущность + protected float _startPosX; //Координаты отрисовки по оси x + protected float _startPosY; //Координаты отрисовки по оси y private int? _pictureWidth = null; //Ширина окна private int? _pictureHeight = null; //Высота окна - private readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля - private readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля + protected readonly int _warmlyShipWidth = 125; //Ширина отрисовки корабля + protected readonly int _warmlyShipHeight = 50; //Высота отрисовки корабля //Инициализация public DrawingWarmlyShip(int speed, float weight, Color bodyColor) @@ -22,6 +22,12 @@ namespace WarmlyShip warmlyShip = new EntityWarmlyShip(speed, weight, bodyColor); } + protected DrawingWarmlyShip(int speed, float weight, Color bodyColor, int warmlyWidth, int warmlyHeight) : this(speed, weight, bodyColor) + { + _warmlyShipWidth = warmlyWidth; + _warmlyShipHeight = warmlyHeight; + } + //Начальные коордитанты public void SetPosition(int x, int y, int width, int height) { @@ -55,7 +61,7 @@ namespace WarmlyShip } //Отрисовка транспорта - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) { diff --git a/WarmlyShip/WarmlyShip/DrawningMotorShip.cs b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs new file mode 100644 index 0000000..0d17867 --- /dev/null +++ b/WarmlyShip/WarmlyShip/DrawningMotorShip.cs @@ -0,0 +1,44 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class DrawningMotorShip : DrawingWarmlyShip + { + public DrawningMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool tubes, bool cistern) : base(speed, weight, bodyColor, 150, 75) + { + warmlyShip = new EntityMotorShip(speed, weight, bodyColor, dopColor, tubes , cistern); + } + + public override void DrawTransport(Graphics g) + { + if (warmlyShip is not EntityMotorShip motorShip) + { + return; + } + + Pen pen = new(Color.Black, 2); + Brush dopBrush = new SolidBrush(motorShip.DopColor); + if (motorShip.Tubes) + { + g.FillRectangle(dopBrush, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2); + g.DrawRectangle(pen, _startPosX + _warmlyShipWidth / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2); + g.FillRectangle(dopBrush, _startPosX + _warmlyShipWidth * 3 / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2); + g.DrawRectangle(pen, _startPosX + _warmlyShipWidth * 3 / 5, _startPosY, _warmlyShipWidth / 5, _warmlyShipHeight / 2); + } + + _startPosY += 25; + base.DrawTransport(g); + _startPosY -= 25; + + if (motorShip.Cistern) + { + g.FillEllipse(dopBrush, _startPosX, _startPosY + 25, 25, 20); + g.DrawEllipse(pen, _startPosX, _startPosY + 25, 25, 20); + } + } + } +} \ No newline at end of file diff --git a/WarmlyShip/WarmlyShip/EntityMotorShip.cs b/WarmlyShip/WarmlyShip/EntityMotorShip.cs new file mode 100644 index 0000000..55ddeb5 --- /dev/null +++ b/WarmlyShip/WarmlyShip/EntityMotorShip.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WarmlyShip +{ + internal class EntityMotorShip : EntityWarmlyShip + { + public Color DopColor { get; private set; } + public bool Tubes { get; private set; } + public bool Cistern { get; private set; } + + public EntityMotorShip(int speed, float weight, Color bodyColor, Color dopColor, bool tubes, bool cistern) : base(speed, weight, bodyColor) + { + DopColor = dopColor; + Tubes = tubes; + Cistern = cistern; + } + + } +} + \ No newline at end of file