diff --git a/src/AirBomber/Rendering/BomberRendererBase.java b/src/AirBomber/Rendering/BomberRendererBase.java index aa18112..d39701f 100644 --- a/src/AirBomber/Rendering/BomberRendererBase.java +++ b/src/AirBomber/Rendering/BomberRendererBase.java @@ -1,6 +1,5 @@ package AirBomber.Rendering; -import AirBomber.*; import AirBomber.Entities.*; import AirBomber.MovementStrategy.*; import java.awt.*; @@ -22,7 +21,7 @@ public class BomberRendererBase public int PosX() { return _startPosX; } public int PosY() { return _startPosY; } - public EngineRenderer EngineRenderer; + public IEngineRenderer EngineRenderer; public int EntityWidth() { return _bomberWidth; } public int EntityHeight() { return _bomberHeight; } @@ -37,9 +36,27 @@ public class BomberRendererBase EntityBomber = new BomberEntityBase(Speed, Weight, BodyColor); - EngineRenderer = new EngineRenderer(); - Random Random = new Random(); + + /** Создание прорисовщика дополнительных элементов */ + int EngineRendererVariant = Random.nextInt(1, 4); + switch (EngineRendererVariant) { + case 1: + EngineRenderer = new EngineRenderer(); + break; + + case 2: + EngineRenderer = new RectangleEngineRenderer(); + break; + + case 3: + EngineRenderer = new TriangleEngineRenderer(); + break; + + default: + break; + } + EngineRenderer.SetAmount(Random.nextInt(1, 7)); } @@ -56,9 +73,27 @@ public class BomberRendererBase EntityBomber = new BomberEntityBase(Speed, Weight, BodyColor); - EngineRenderer = new EngineRenderer(); - Random Random = new Random(); + + /** Создание прорисовщика дополнительных элементов */ + int EngineRendererVariant = Random.nextInt(1, 4); + switch (EngineRendererVariant) { + case 1: + EngineRenderer = new EngineRenderer(); + break; + + case 2: + EngineRenderer = new RectangleEngineRenderer(); + break; + + case 3: + EngineRenderer = new TriangleEngineRenderer(); + break; + + default: + break; + } + EngineRenderer.SetAmount(Random.nextInt(1, 7)); } diff --git a/src/AirBomber/EngineRenderer.java b/src/AirBomber/Rendering/EngineRenderer.java similarity index 89% rename from src/AirBomber/EngineRenderer.java rename to src/AirBomber/Rendering/EngineRenderer.java index 16166d7..c597683 100644 --- a/src/AirBomber/EngineRenderer.java +++ b/src/AirBomber/Rendering/EngineRenderer.java @@ -1,8 +1,9 @@ -package AirBomber; +package AirBomber.Rendering; import java.awt.*; +import AirBomber.EnginesAmount; -public class EngineRenderer +public class EngineRenderer implements IEngineRenderer { private EnginesAmount Amount; diff --git a/src/AirBomber/Rendering/IEngineRenderer.java b/src/AirBomber/Rendering/IEngineRenderer.java new file mode 100644 index 0000000..8af1f62 --- /dev/null +++ b/src/AirBomber/Rendering/IEngineRenderer.java @@ -0,0 +1,10 @@ +package AirBomber.Rendering; + +import java.awt.*; + +public interface IEngineRenderer +{ + public void SetAmount(int Amount); + + public void DrawEngines(Graphics g, Color BodyColor, int StartPosX, int StartPosY); +} diff --git a/src/AirBomber/Rendering/RectangleEngineRenderer.java b/src/AirBomber/Rendering/RectangleEngineRenderer.java new file mode 100644 index 0000000..508063d --- /dev/null +++ b/src/AirBomber/Rendering/RectangleEngineRenderer.java @@ -0,0 +1,41 @@ +package AirBomber.Rendering; + +import java.awt.*; +import AirBomber.EnginesAmount; + +public class RectangleEngineRenderer implements IEngineRenderer +{ + private EnginesAmount Amount; + + public void SetAmount(int Amount) + { + if (Amount <= 2) + this.Amount = EnginesAmount.Two; + + else if (Amount > 2 && Amount <= 4) + this.Amount = EnginesAmount.Four; + + else + this.Amount = EnginesAmount.Six; + } + + public void DrawEngines(Graphics g, Color BodyColor, int _startPosX, int _startPosY) + { + g.setColor(BodyColor); + + g.fillRect(_startPosX + 83, _startPosY + 50, 30, 15); + g.fillRect(_startPosX + 83, _startPosY + 135, 30, 15); + + if (Amount == EnginesAmount.Two) + return; + + g.fillRect(_startPosX + 83, _startPosY + 30, 30, 15); + g.fillRect(_startPosX + 83, _startPosY + 155, 30, 15); + + if (Amount == EnginesAmount.Four) + return; + + g.fillRect(_startPosX + 83, _startPosY + 10, 30, 15); + g.fillRect(_startPosX + 83, _startPosY + 175, 30, 15); + } +} diff --git a/src/AirBomber/Rendering/TriangleEngineRenderer.java b/src/AirBomber/Rendering/TriangleEngineRenderer.java new file mode 100644 index 0000000..1474534 --- /dev/null +++ b/src/AirBomber/Rendering/TriangleEngineRenderer.java @@ -0,0 +1,56 @@ +package AirBomber.Rendering; + +import java.awt.*; +import AirBomber.EnginesAmount; + +public class TriangleEngineRenderer implements IEngineRenderer +{ + private EnginesAmount Amount; + + public void SetAmount(int Amount) + { + if (Amount <= 2) + this.Amount = EnginesAmount.Two; + + else if (Amount > 2 && Amount <= 4) + this.Amount = EnginesAmount.Four; + + else + this.Amount = EnginesAmount.Six; + } + + public void DrawEngines(Graphics g, Color BodyColor, int _startPosX, int _startPosY) + { + g.setColor(BodyColor); + + int[] FirstTopX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 }; + int[] FirstTopY = { _startPosY + 50, _startPosY + 57, _startPosY + 65 }; + g.fillPolygon(FirstTopX, FirstTopY, 3); + + int[] FirstBottomX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 }; + int[] FirstBottomY = { _startPosY + 135, _startPosY + 142, _startPosY + 150 }; + g.fillPolygon(FirstBottomX, FirstBottomY, 3); + + if (Amount == EnginesAmount.Two) + return; + + int[] SecondTopX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 }; + int[] SecondTopY = { _startPosY + 30, _startPosY + 37, _startPosY + 45 }; + g.fillPolygon(SecondTopX, SecondTopY, 3); + + int[] SecondBottomX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 }; + int[] SecondBottomY = { _startPosY + 155, _startPosY + 162, _startPosY + 170 }; + g.fillPolygon(SecondBottomX, SecondBottomY, 3); + + if (Amount == EnginesAmount.Four) + return; + + int[] ThirdTopX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 }; + int[] ThirdTopY = { _startPosY + 10, _startPosY + 17, _startPosY + 25 }; + g.fillPolygon(ThirdTopX, ThirdTopY, 3); + + int[] ThirdBottomX = { _startPosX + 83, _startPosX + 113, _startPosX + 83 }; + int[] ThirdBottomY = { _startPosY + 175, _startPosY + 182, _startPosY + 190 }; + g.fillPolygon(ThirdBottomX, ThirdBottomY, 3); + } +}