From ac0f95e2054e35e18eceafd14e2fad6c8ea24b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC=20=D0=A5=D0=B0=D1=80=D0=BB?= =?UTF-8?q?=D0=B0=D0=BC=D0=BE=D0=B2?= Date: Tue, 20 Dec 2022 17:17:11 +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=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BE=D0=B2.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrawingEngines.java | 76 +++++++++++++++++++++++----------------- DrawingStormtrooper.java | 45 ++++++++++++++++++------ EntityStormtrooper.java | 2 +- 3 files changed, 79 insertions(+), 44 deletions(-) diff --git a/DrawingEngines.java b/DrawingEngines.java index fdb7b52..1ff25c0 100644 --- a/DrawingEngines.java +++ b/DrawingEngines.java @@ -1,38 +1,50 @@ import java.awt.*; -public class DrawingEngines { +public class DrawingEngines implements IDrawningEngines{ private DirectionEnginesOnStormtrooper enginesCount; - public void SetNewEngines(int countEngines){ - if (countEngines == 4) { - enginesCount = DirectionEnginesOnStormtrooper.FOUR; - } else if (countEngines == 6) { - enginesCount = DirectionEnginesOnStormtrooper.SIX; - } - else { - enginesCount = DirectionEnginesOnStormtrooper.TWO; - } + public DrawingEngines(int count) { + SetNewEngines(count); } - public void Draw(Graphics2D g, int x, int y, Color color) { - g.setColor(color != null ? color : Color.BLACK); - switch (enginesCount) { - case TWO: - g.fillRect(x + 50, y, 20, 5); - g.fillRect(x + 50, y+95, 20, 5); - break; - case FOUR: - g.fillRect(x + 50, y, 20, 5); - g.fillRect(x + 50, y+10, 20, 5); - g.fillRect(x + 50, y+85, 20, 5); - g.fillRect(x + 50, y+95, 20, 5); - break; - case SIX: - g.fillRect(x + 50, y, 20, 5); - g.fillRect(x + 50, y+10, 20, 5); - g.fillRect(x + 50, y+20, 20, 5); - g.fillRect(x + 50, y+75, 20, 5); - g.fillRect(x + 50, y+85, 20, 5); - g.fillRect(x + 50, y+95, 20, 5); - break; - } + @Override + public void Draw(Graphics g, int x, int y, Color bodycolor) { + g.setColor(bodycolor); + switch (enginesCount) { + case TWO: + g.fillRect(x + 50, y, 20, 5); + g.fillRect(x + 50, y+95, 20, 5); + break; + case FOUR: + g.fillRect(x + 50, y, 20, 5); + g.fillRect(x + 50, y+10, 20, 5); + g.fillRect(x + 50, y+85, 20, 5); + g.fillRect(x + 50, y+95, 20, 5); + break; + case SIX: + g.fillRect(x + 50, y, 20, 5); + g.fillRect(x + 50, y+10, 20, 5); + g.fillRect(x + 50, y+20, 20, 5); + g.fillRect(x + 50, y+75, 20, 5); + g.fillRect(x + 50, y+85, 20, 5); + g.fillRect(x + 50, y+95, 20, 5); + break; + } } + + @Override + public void SetNewEngines(int count) { + switch(count) + { + case 2: + enginesCount = DirectionEnginesOnStormtrooper.TWO; + break; + case 4: + enginesCount = DirectionEnginesOnStormtrooper.FOUR; + break; + case 6: + enginesCount = DirectionEnginesOnStormtrooper.SIX; + break; + default: + break; + } + } } diff --git a/DrawingStormtrooper.java b/DrawingStormtrooper.java index 1340d02..9e91bf5 100644 --- a/DrawingStormtrooper.java +++ b/DrawingStormtrooper.java @@ -3,24 +3,42 @@ import java.util.Random; public class DrawingStormtrooper { public EntityStormtrooper Stormtrooper; + public EntityStormtrooper getStormtrooper() { + return Stormtrooper; + } public DrawingEngines drawingEngines; + private IDrawningEngines iDrawingEngines; public float _startPosX; public float _startPosY; private Integer _pictureWidth = null; private Integer _pictureHeight = null; - private static final int _StormWidth = 135; - private static final int _StormHeight = 100; + private int _StormWidth = 135; + private int _StormHeight = 100; - public void Init(int speed, float weight, Color bodyColor, int numberOfEngines){ - Stormtrooper = new EntityStormtrooper(); - drawingEngines = new DrawingEngines(); - Stormtrooper.Init(speed, weight, bodyColor); - System.out.println(numberOfEngines + ""); - drawingEngines.SetNewEngines(numberOfEngines); + public DrawingStormtrooper(int speed, float weight, Color bodyColor){ + Random random = new Random(); + int[] ArrayEngines = new int[]{2, 4, 6}; + + switch (random.nextInt(3)){ + case 0: + iDrawingEngines = new DrawingEngines(ArrayEngines[random.nextInt(0, 3)]); + break; + case 1: + iDrawingEngines = new DrawningOvalEngines(ArrayEngines[random.nextInt(0, 3)]); + break; + case 2: + iDrawingEngines = new DrawningTriangleEngines(ArrayEngines[random.nextInt(0, 3)]); + break; + + } + Stormtrooper = new EntityStormtrooper(speed,weight, bodyColor); } - public EntityStormtrooper getStormtrooper() { - return Stormtrooper; + protected DrawingStormtrooper(int speed, float weight, Color bodyColor, int StormWidth, int StormHeight) + { + this (speed, weight, bodyColor); + _StormWidth = StormWidth; + _StormHeight = StormHeight; } public void SetPosition(int x, int y, int width, int height){ @@ -86,6 +104,7 @@ public class DrawingStormtrooper { //фюзеляж самолёта + g.setColor(Color.BLACK); g.fillRect(_startPosXInt + 20, _startPosYInt + 40, 100, 20); //отрисовка крыла @@ -148,7 +167,7 @@ public class DrawingStormtrooper { g.fillPolygon(stabX, stabY, stabX.length); //отрисовка двигателей - drawingEngines.Draw(g, (int) _startPosX, (int) _startPosY,Stormtrooper.getBodyColor()); + iDrawingEngines.Draw(g, (int) _startPosX, (int) _startPosY, Stormtrooper.getBodyColor()); g.setColor(Color.BLACK); @@ -177,4 +196,8 @@ public class DrawingStormtrooper { _startPosY = _pictureHeight - _StormHeight; } } + public float[] GetCurrentPosition() + { + return new float[]{_startPosX, _startPosX + _StormWidth, _startPosY, _startPosY + _StormHeight}; + } } diff --git a/EntityStormtrooper.java b/EntityStormtrooper.java index 4119e90..88c4f11 100644 --- a/EntityStormtrooper.java +++ b/EntityStormtrooper.java @@ -22,7 +22,7 @@ public class EntityStormtrooper { return BodyColor; } - public void Init(int speed, float weight, Color bodyColor){ + public EntityStormtrooper(int speed, float weight, Color bodyColor){ Random rnd = new Random(); Speed = speed <= 0 ? rnd.nextInt(50 + 1) +50 : speed; //генерация в диапазоне от 50 до 100 Weight = weight <= 0 ? rnd.nextInt(50 + 1) +50 : weight;