diff --git a/src/BomberEntity.java b/src/BomberEntity.java index 5511fcb..8b7ece0 100644 --- a/src/BomberEntity.java +++ b/src/BomberEntity.java @@ -2,12 +2,12 @@ import java.awt.Color; public class BomberEntity { - public int Speed; - public double Weight; - public Color BodyColor; - public Color AdditionalColor; - public boolean Bombs; - public boolean FuelTanks; + private int Speed; + private double Weight; + private Color BodyColor; + private Color AdditionalColor; + private boolean Bombs; + private boolean FuelTanks; public double Step; public void Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor, boolean FuelTanks, boolean Bombs) @@ -21,4 +21,16 @@ public class BomberEntity this.Step = (double)Speed * 100 / Weight * 5 / 2; } + + public int GetSpeed() { return Speed; } + + public double GetWeight() { return Weight; } + + public Color GetBodyColor() { return BodyColor; } + + public Color GetAdditionalColor() { return AdditionalColor; } + + public boolean GetBombs() { return Bombs; } + + public boolean GetFuelTanks() { return FuelTanks; } } diff --git a/src/BomberRenderer.java b/src/BomberRenderer.java index 4eb202f..8a7ee8f 100644 --- a/src/BomberRenderer.java +++ b/src/BomberRenderer.java @@ -1,8 +1,9 @@ import java.awt.*; +import java.util.Random; public class BomberRenderer { - public BomberEntity EntityBomber; + private BomberEntity EntityBomber; private int _pictureWidth; private int _pictureHeight; @@ -13,6 +14,8 @@ public class BomberRenderer private int _bomberWidth = 200; private int _bomberHeight = 200; + public EngineRenderer EngineRenderer; + public boolean Init(int Speed, double Weight, Color BodyColor, Color AdditionalColor, boolean FuelTanks, boolean Bombs, int Width, int Height) { if (Width < _bomberWidth || Height < _bomberHeight) @@ -23,10 +26,17 @@ public class BomberRenderer EntityBomber = new BomberEntity(); EntityBomber.Init(Speed, Weight, BodyColor, AdditionalColor, FuelTanks, Bombs); + + EngineRenderer = new EngineRenderer(); + + Random Random = new Random(); + EngineRenderer.SetAmount(Random.nextInt(1, 7)); return true; } + public BomberEntity GetEntityBomber() { return EntityBomber; } + public void SetPosition(int x, int y) { if (EntityBomber == null) @@ -86,7 +96,7 @@ public class BomberRenderer return; /** Отрисовка основной части */ - g.setColor(EntityBomber.BodyColor); + g.setColor(EntityBomber.GetBodyColor()); int[] LeftWingX = { _startPosX + 90, @@ -172,9 +182,9 @@ public class BomberRenderer g.drawPolygon(BackRightWingX, BackRightWingY, 4); /** Отрисовка дополнительных элементов */ - g.setColor(EntityBomber.AdditionalColor); + g.setColor(EntityBomber.GetAdditionalColor()); - if (EntityBomber.FuelTanks) + if (EntityBomber.GetFuelTanks()) { int[] LeftGasTankX = { _startPosX + 50, @@ -205,10 +215,12 @@ public class BomberRenderer g.fillPolygon(RightGasTankX, RightGasTankY, 4); } - if (EntityBomber.Bombs) + if (EntityBomber.GetBombs()) { g.fillOval(_startPosX + 110, _startPosY + 115, 50, 25); g.fillOval(_startPosX + 110, _startPosY + 60, 50, 25); } + + EngineRenderer.DrawEngines(g, EntityBomber.GetBodyColor(), _startPosX, _startPosY); } } diff --git a/src/EngineRenderer.java b/src/EngineRenderer.java new file mode 100644 index 0000000..fd6c05c --- /dev/null +++ b/src/EngineRenderer.java @@ -0,0 +1,38 @@ +import java.awt.*; + +public class EngineRenderer +{ + 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.fillOval(_startPosX + 83, _startPosY + 50, 30, 15); + g.fillOval(_startPosX + 83, _startPosY + 135, 30, 15); + + if (Amount == EnginesAmount.Two) + return; + + g.fillOval(_startPosX + 83, _startPosY + 30, 30, 15); + g.fillOval(_startPosX + 83, _startPosY + 155, 30, 15); + + if (Amount == EnginesAmount.Four) + return; + + g.fillOval(_startPosX + 83, _startPosY + 10, 30, 15); + g.fillOval(_startPosX + 83, _startPosY + 175, 30, 15); + } +} diff --git a/src/EnginesAmount.java b/src/EnginesAmount.java new file mode 100644 index 0000000..b142799 --- /dev/null +++ b/src/EnginesAmount.java @@ -0,0 +1,6 @@ +public enum EnginesAmount +{ + Two, + Four, + Six +}