diff --git a/ProjectStormtrooper/DrawingEngines.java b/ProjectStormtrooper/DrawingEngines.java new file mode 100644 index 0000000..25ba2db --- /dev/null +++ b/ProjectStormtrooper/DrawingEngines.java @@ -0,0 +1,84 @@ +package ProjectStormtrooper; + +import java.awt.*; + +public class DrawingEngines { + private EnumEnginesCount _enumEnginesCount; + + public void SetEnginesCount(int enginesCount) { + for (EnumEnginesCount val : EnumEnginesCount.values()) { + if (val.count == enginesCount) { + this._enumEnginesCount = val; + return; + } + } + } + + private void DrawEngine(Graphics2D g2d, Color color, int x, int y, int w, int h) { + g2d.setColor(Color.WHITE); + g2d.fillRect(x, y, w, h); + g2d.setColor(Color.BLACK); + g2d.drawRect(x, y, w, h); + g2d.setColor(color); + g2d.fillRect(x, y, 6, h); + } + + public void DrawEngines(Graphics g, Color color, int startPosX, int startPosY, int drawingWidth, int drawingHeight) { + if (_enumEnginesCount == null) { + return; + } + Graphics2D g2d = (Graphics2D) g; + + int engineWidth = 20; + int engineHeight = 6; + + if (_enumEnginesCount.count >= EnumEnginesCount.Two.count) { + DrawEngine( + g2d, color, + startPosX + drawingWidth - drawingWidth / 5, + startPosY + drawingHeight / 2 - drawingHeight / 6, + engineWidth, + engineHeight + ); + DrawEngine( + g2d, color, + startPosX + drawingWidth - drawingWidth / 5, + startPosY + drawingHeight / 2 + drawingHeight / 6 - engineHeight, + engineWidth, + engineHeight + ); + } + if (_enumEnginesCount.count >= EnumEnginesCount.Four.count) { + DrawEngine( + g2d, color, + startPosX + drawingWidth - drawingWidth / 5 + 5, + startPosY + drawingHeight / 2 - drawingHeight / 6 - 10, + engineWidth - 5, + engineHeight + ); + DrawEngine( + g2d, color, + startPosX + drawingWidth - drawingWidth / 5 + 5, + startPosY + drawingHeight / 2 + drawingHeight / 6 - engineHeight + 10, + engineWidth - 5, + engineHeight + ); + } + if (_enumEnginesCount.count >= EnumEnginesCount.Six.count) { + DrawEngine( + g2d, color, + startPosX + drawingWidth / 2 - 10, + startPosY + drawingHeight / 2 - drawingHeight / 6 - 10, + engineWidth, + engineHeight + ); + DrawEngine( + g2d, color, + startPosX + drawingWidth / 2 - 10, + startPosY + drawingHeight / 2 + drawingHeight / 6 + 3, + engineWidth, + engineHeight + ); + } + } +} diff --git a/ProjectStormtrooper/DrawingStormtrooper.java b/ProjectStormtrooper/DrawingStormtrooper.java index 36ba9b4..7d5c2ee 100644 --- a/ProjectStormtrooper/DrawingStormtrooper.java +++ b/ProjectStormtrooper/DrawingStormtrooper.java @@ -4,6 +4,7 @@ import java.awt.*; public class DrawingStormtrooper { public EntityStormtrooper EntityStormtrooper; + private DrawingEngines _drawingEngines; private int _pictureWidth; private int _pictureHeight; private int _startPosX; @@ -19,11 +20,16 @@ public class DrawingStormtrooper { } _pictureWidth = width; _pictureHeight = height; + _drawingEngines = new DrawingEngines(); EntityStormtrooper = new EntityStormtrooper(); EntityStormtrooper.Init(speed, weight, bodyColor, additionalColor, rockets, bombs); return true; } + public void SetEnginesCount(int enginesCount) { + _drawingEngines.SetEnginesCount(enginesCount); + } + public void SetPosition(int x, int y) { if (x < 0) { x = 0; @@ -80,6 +86,8 @@ public class DrawingStormtrooper { Color blackColor = Color.BLACK; Color redColor = Color.RED; + _drawingEngines.DrawEngines(g, additionalColor, _startPosX, _startPosY, _stormtrooperWidth, _stormtrooperHeight); + // Длина фюзеляжа int bodyHeight = _stormtrooperHeight / 9; int bodyWidth = _stormtrooperWidth - _stormtrooperWidth / 8; diff --git a/ProjectStormtrooper/FormStormtrooper.java b/ProjectStormtrooper/FormStormtrooper.java index 2ae42f0..bc8ab6b 100644 --- a/ProjectStormtrooper/FormStormtrooper.java +++ b/ProjectStormtrooper/FormStormtrooper.java @@ -39,6 +39,7 @@ public class FormStormtrooper { pictureBox.getHeight() ); + _drawingStormtrooper.SetEnginesCount(random.nextInt(2, 7)); _drawingStormtrooper.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); Draw();