import java.awt.*; public class DrawingCrossRollers implements IDrawingRollers { private RollersCount rollersCount; private Color color; public DrawingCrossRollers(int rollersCount, Color bodyColor) { setRollersCount(rollersCount); color = bodyColor; } public void setRollersCount(int num) { if (num <= 4) { rollersCount = RollersCount.Four; } else if (num >= 6) { rollersCount = RollersCount.Six; } else { rollersCount = RollersCount.Five; } } public void draw(Graphics2D g, int x, int y, int artilleryWidth, int artilleryHeight) { g.setColor(color != null ? color : Color.BLACK); g.fillOval(x + artilleryWidth / 20, y + artilleryHeight * 7 / 15, artilleryWidth * 4 / 20, artilleryHeight * 10 / 32); g.fillOval(x + artilleryWidth * 15 / 20, y + artilleryHeight * 7 / 15, artilleryWidth * 4 / 20, artilleryHeight * 10 / 32); switch (rollersCount) { case Six: { g.fillOval(x + artilleryWidth * 8 / 20, y + artilleryHeight * 10 / 16, artilleryWidth * 2 / 20, artilleryHeight * 6 / 32); } case Five: { g.fillOval(x + artilleryWidth * 10 / 20, y + artilleryHeight * 10 / 16, artilleryWidth * 2 / 20, artilleryHeight * 6 / 32); } case Four: { g.fillOval(x + artilleryWidth * 5 / 20, y + artilleryHeight * 9 / 16, artilleryWidth * 3 / 20, artilleryHeight * 8 / 32); g.fillOval(x + artilleryWidth * 12 / 20, y + artilleryHeight * 9 / 16, artilleryWidth * 3 / 20, artilleryHeight * 8 / 32); } } drawOrnament(g, x, y, artilleryWidth, artilleryHeight); } private void drawOrnament(Graphics2D g, int x, int y, int artilleryWidth, int artilleryHeight) { g.setStroke(new BasicStroke(1)); g.setColor(Color.BLACK); g.drawLine(x + artilleryWidth / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32, x + artilleryWidth * 5 / 20 - 1, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32); g.drawLine(x + artilleryWidth * 3 / 20, y + artilleryHeight * 7 / 15, x + artilleryWidth * 3 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 10 / 32); g.drawLine(x + artilleryWidth * 2 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64, x + artilleryWidth * 4 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64); g.drawLine(x + artilleryWidth * 4 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64, x + artilleryWidth * 2 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64); g.drawLine(x + artilleryWidth * 15 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32, x + artilleryWidth * 19 / 20 - 1, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 32); g.drawLine(x + artilleryWidth * 17 / 20, y + artilleryHeight * 7 / 15, x + artilleryWidth * 17 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 10 / 32); g.drawLine(x + artilleryWidth * 16 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64, x + artilleryWidth * 18 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64); g.drawLine(x + artilleryWidth * 18 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 5 / 64, x + artilleryWidth * 16 / 20, y + artilleryHeight * 7 / 15 + artilleryHeight * 15 / 64); switch(rollersCount) { case Six: { g.drawLine(x + artilleryWidth * 8 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32, x + artilleryWidth * 10 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32); g.drawLine(x + artilleryWidth * 9 / 20, y + artilleryHeight * 10 / 16, x + artilleryWidth * 9 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 6 / 32); g.drawLine(x + artilleryWidth * 8 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64, x + artilleryWidth * 10 / 20 - artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64); g.drawLine(x + artilleryWidth * 9 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64, x + artilleryWidth * 8 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64); } case Five: { g.drawLine(x + artilleryWidth * 10 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32, x + artilleryWidth * 12 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32); g.drawLine(x + artilleryWidth * 11 / 20, y + artilleryHeight * 10 / 16, x + artilleryWidth * 11 / 20, y + artilleryHeight * 10 / 16 + artilleryHeight * 6 / 32); g.drawLine(x + artilleryWidth * 12 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64, x + artilleryWidth * 12 / 20 - artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64); g.drawLine(x + artilleryWidth * 11 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 - artilleryHeight * 3 / 64, x + artilleryWidth * 10 / 20 + artilleryWidth * 2 / 80, y + artilleryHeight * 10 / 16 + artilleryHeight * 3 / 32 + artilleryHeight * 3 / 64); } case Four: { g.drawLine(x + artilleryWidth * 5 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32, x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32); g.drawLine(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16, x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16 + artilleryHeight * 8 / 32); g.drawLine(x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32, x + artilleryWidth * 5 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32); g.drawLine(x + artilleryWidth * 5 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32, x + artilleryWidth * 5 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32); g.drawLine(x + artilleryWidth * 12 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32, x + artilleryWidth * 12 / 20 + artilleryWidth * 3 / 20, y + artilleryHeight * 9 / 16 + artilleryHeight * 4 / 32); g.drawLine(x + artilleryWidth * 12 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16, x + artilleryWidth * 12 / 20 + artilleryWidth * 3 / 40, y + artilleryHeight * 9 / 16 + artilleryHeight * 8 / 32); g.drawLine(x + artilleryWidth * 12 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32, x + artilleryWidth * 12 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32); g.drawLine(x + artilleryWidth * 12 / 20 + artilleryWidth * 9 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 2 / 32, x + artilleryWidth * 12 / 20 + artilleryWidth * 3 / 80, y + artilleryHeight * 9 / 16 + artilleryHeight * 6 / 32); } } } public void setColor(Color color) { this.color = color; } }