From 3166c0b054b838393219a570e5e56684db97b23b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=90=D0=BB=D0=B5=D0=B9?= =?UTF-8?q?=D0=BA=D0=B8=D0=BD?= Date: Tue, 29 Nov 2022 20:50:45 +0400 Subject: [PATCH] With dopAsk --- DrawEngines.java | 36 ++++++++++++++++++++++++++++++++++++ DrawningBomber.java | 12 +++++++++--- Engines.java | 24 ++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 DrawEngines.java create mode 100644 Engines.java diff --git a/DrawEngines.java b/DrawEngines.java new file mode 100644 index 0000000..ba311df --- /dev/null +++ b/DrawEngines.java @@ -0,0 +1,36 @@ +import java.awt.*; + +public class DrawEngines +{ + private Engines numEngines; + + public void SetNumEngines(int i) { numEngines = Engines.GetNumEngines(i); } + + public void DrawningEngines(float _startPosX, float _startPosY, Graphics2D g2d, int _airBomberWidth, int _airBomberHeight) + { + switch(numEngines) + { + case TwoEngines: + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 - 20, 20, 10); + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 + 10, 20, 10); + break; + case FourEngines: + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 - 20, 20, 10); + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 + 10, 20, 10); + + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 15, (int)_startPosY + _airBomberHeight / 2 - 35, 15, 10); + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 15, (int)_startPosY + _airBomberHeight / 2 + 25, 15, 10); + break; + case SixEngines: + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 - 20, 20, 10); + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 20, (int)_startPosY + _airBomberHeight / 2 + 10, 20, 10); + + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 15, (int)_startPosY + _airBomberHeight / 2 - 35, 15, 10); + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 15, (int)_startPosY + _airBomberHeight / 2 + 25, 15, 10); + + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 10, (int)_startPosY + _airBomberHeight / 2 - 50, 10, 10); + g2d.fillRect((int)_startPosX + _airBomberWidth / 2 - 10, (int)_startPosY + _airBomberHeight / 2 + 40, 10, 10); + break; + } + } +} diff --git a/DrawningBomber.java b/DrawningBomber.java index 0e75f41..395a0aa 100644 --- a/DrawningBomber.java +++ b/DrawningBomber.java @@ -13,10 +13,15 @@ public class DrawningBomber extends JPanel private final int _airBomberWidth = 100; private final int _airBomberHeight = 100; + private int NumEngines = 1; + private DrawEngines drawEngines = new DrawEngines(); + public void Init(int speed, float weight, Color bodyColor) { AirBomber = new EntityAirBomber(); AirBomber.Init(speed, weight, bodyColor); + Random random = new Random(); + drawEngines.SetNumEngines(random.nextInt(1, 4)); } public void SetPosition(int x, int y, int width, int height) @@ -113,7 +118,7 @@ public class DrawningBomber extends JPanel (int)(_startPosY + _airBomberHeight), (int)(_startPosY + _airBomberHeight)}; - g.fillPolygon(xPos, yPos, xPos.length); + g2d.fillPolygon(xPos, yPos, xPos.length); xPos = new int[] { (int)(_startPosX + 20), @@ -127,7 +132,7 @@ public class DrawningBomber extends JPanel (int)(_startPosY + _airBomberHeight / 2 + 5), (int)(_startPosY + _airBomberHeight / 2 + 5)}; - g.fillPolygon(xPos, yPos, xPos.length); + g2d.fillPolygon(xPos, yPos, xPos.length); xPos = new int[] { (int)(_startPosX), @@ -139,7 +144,8 @@ public class DrawningBomber extends JPanel (int)(_startPosY + _airBomberHeight / 2 - 5), (int)(_startPosY + _airBomberHeight / 2 + 5)}; - g.fillPolygon(xPos, yPos, xPos.length); + g2d.fillPolygon(xPos, yPos, xPos.length); + drawEngines.DrawningEngines(_startPosX, _startPosY, g2d, _airBomberWidth, _airBomberHeight); } public void ChangeBorders(int width, int height) diff --git a/Engines.java b/Engines.java new file mode 100644 index 0000000..2d2e3a4 --- /dev/null +++ b/Engines.java @@ -0,0 +1,24 @@ +public enum Engines +{ + TwoEngines(1), + FourEngines(2), + SixEngines(6); + + Engines(int i) { + + } + + public static Engines GetNumEngines(int i) + { + switch(i) + { + case 1: + return TwoEngines; + case 2: + return FourEngines; + case 3: + return SixEngines; + } + return null; + } +}