PIbd-23_Polevoy_S.V._SelfPr.../DrawingRollers.java

40 lines
1.6 KiB
Java
Raw Permalink Normal View History

2022-09-25 19:20:16 +04:00
import java.awt.*;
public class DrawingRollers {
private RollersCount rollersCount;
private Color color;
2022-09-27 16:22:49 +04:00
public void Init(int rollersCount, Color bodyColor) {
2022-09-25 19:20:16 +04:00
setRollersCount(rollersCount);
2022-09-27 16:22:49 +04:00
color = bodyColor;
2022-09-25 19:20:16 +04:00
}
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);
}
}
}
}