From dd3c7079533ba40db2e28da064a7a3ea36ca1719 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 26 Nov 2023 16:04:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=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?=C2=AB=D0=BF=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD=D1=83=D1=82?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=C2=BB=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0=20+=20fix=20in=20EntityAirBomber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 195 +++-------------------- AirBomber/AirBomber/EntityAirBomber.cs | 4 +- 2 files changed, 22 insertions(+), 177 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index 4358657..f92ad33 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -6,190 +6,37 @@ using System.Threading.Tasks; namespace AirBomber { - public class DrawningAirBomber + public class DrawningAirBomber : DrawningAirPlane { - public EntityAirBomber? EntityAirBomber { get; private set; } - private int _pictureWidth; - private int _pictureHeight; - private int _startPosX; - private int _startPosY; - private readonly int _bomberWidth = 160; - private readonly int _bomberHeight = 118; - private DrawningEngines drawningEngines; - - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, int engines, int width, int height) + public DrawningAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, int width, int height) : + base(speed, weight, bodyColor, width, height, 160, 118) { - if (width < _bomberWidth || height < _bomberHeight) + if (EntityAirPlane != null) { - return false; - } - _pictureWidth = width; - _pictureHeight = height; - EntityAirBomber = new EntityAirBomber(); - EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, bombs, fuelTanks, engines); - - drawningEngines = new DrawningEngines(); - drawningEngines.SetAmount(engines); - - return true; - } - - public void SetPosition(int x, int y) - { - if (x < 0 || x + _bomberWidth > _pictureWidth) - { - x = _pictureWidth - _bomberWidth; - } - - if (y < 0 || y + _bomberWidth > _pictureHeight) - { - y = _pictureHeight - _bomberHeight; - } - _startPosX = x; - _startPosY = y; - } - public void MoveTransport(DirectionType direction) - { - if (EntityAirBomber == null) - { - return; - } - switch (direction) - { - case DirectionType.Left: - if (_startPosX - EntityAirBomber.Step > 0) - { - _startPosX -= (int)EntityAirBomber.Step; - } - break; - case DirectionType.Up: - if (_startPosY - EntityAirBomber.Step > 0) - { - _startPosY -= (int)EntityAirBomber.Step; - } - break; - case DirectionType.Right: - if (_startPosX + EntityAirBomber.Step + _bomberWidth < _pictureWidth) - { - _startPosX += (int)EntityAirBomber.Step; - } - break; - case DirectionType.Down: - if (_startPosY + EntityAirBomber.Step + _bomberHeight < _pictureHeight) - { - _startPosY += (int)EntityAirBomber.Step; - } - break; + EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, fuelTanks); } } - public void DrawBomber(Graphics g) + public override void DrawPlane(Graphics g) { - if (EntityAirBomber == null) + if (EntityAirPlane is not EntityAirBomber airBomber) { return; } Pen pen = new(Color.Black); - Brush additionalBrush = new SolidBrush(EntityAirBomber.AdditionalColor); - Brush bodyColor = new SolidBrush(EntityAirBomber.BodyColor); - Brush wingsColor = new SolidBrush(Color.DeepPink); - if (EntityAirBomber.Bombs) - { - g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 50, 15, 15); - g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15); - g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 30, 15, 15); - g.DrawEllipse(pen, _startPosX + 140, _startPosY + 30, 15, 15); - g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 70, 15, 15); - g.DrawEllipse(pen, _startPosX + 140, _startPosY + 70, 15, 15); - } - g.FillPolygon(additionalBrush, 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(additionalBrush, 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(additionalBrush, 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), - } - ); - if (EntityAirBomber.FuelTanks) - { - g.FillRectangle(additionalBrush, _startPosX + 85, _startPosY + 34, 30, 15); - g.DrawRectangle(pen, _startPosX + 85, _startPosY + 34, 30, 15); - g.FillRectangle(additionalBrush, _startPosX + 85, _startPosY + 70, 30, 15); - g.DrawRectangle(pen, _startPosX + 85, _startPosY + 70, 30, 15); - } - drawningEngines.DrawEngines(g, _startPosX, _startPosY); + Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor); + base.DrawPlane(g); + // bombs + g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 20, 15, 29); + g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29); + g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 70, 15, 29); + g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29); + g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 50, 15, 15); + g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15); + // fueltanks + g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 34, 20, 15); + g.DrawRectangle(pen, _startPosX + 63, _startPosY + 34, 20, 15); + g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 70, 20, 15); + g.DrawRectangle(pen, _startPosX + 63, _startPosY + 70, 20, 15); } } } diff --git a/AirBomber/AirBomber/EntityAirBomber.cs b/AirBomber/AirBomber/EntityAirBomber.cs index 30eac2f..2b4b3fa 100644 --- a/AirBomber/AirBomber/EntityAirBomber.cs +++ b/AirBomber/AirBomber/EntityAirBomber.cs @@ -11,13 +11,11 @@ namespace AirBomber public Color AdditionalColor { get; private set; } public bool Bombs { get; private set; } public bool FuelTanks { get; private set; } - public int Engines { get; private set; } - public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, int engines) : base(speed, weight, bodyColor) + public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks) : base(speed, weight, bodyColor) { AdditionalColor = additionalColor; Bombs = bombs; FuelTanks = fuelTanks; - Engines = engines; } } }