Constructors have been added

This commit is contained in:
Сергей Полевой 2022-10-08 14:43:17 +04:00
parent 7ea460dab0
commit 02566d7957
4 changed files with 13 additions and 16 deletions

View File

@ -14,11 +14,9 @@ public class DrawingArtillery {
return artillery;
}
public void Init(int speed, float weight, Color bodyColor, int rollersCount) {
artillery = new EntityArtillery();
artillery.Init(speed, weight, bodyColor);
drawingRollers = new DrawingRollers();
drawingRollers.Init(rollersCount, bodyColor);
public DrawingArtillery(int speed, float weight, Color bodyColor, int rollersCount) {
artillery = new EntityArtillery(speed, weight, bodyColor);
drawingRollers = new DrawingRollers(rollersCount, bodyColor);
}
public void SetPosition(int x, int y, int width, int height) {

View File

@ -4,7 +4,7 @@ public class DrawingRollers {
private RollersCount rollersCount;
private Color color;
public void Init(int rollersCount, Color bodyColor) {
public DrawingRollers(int rollersCount, Color bodyColor) {
setRollersCount(rollersCount);
color = bodyColor;
}

View File

@ -6,7 +6,7 @@ public class EntityArtillery {
private float weight;
private Color bodyColor;
public void Init(int speed, float weight, Color bodyColor) {
public EntityArtillery(int speed, float weight, Color bodyColor) {
Random rnd = new Random();
this.speed = speed <= 0 ? rnd.nextInt(50, 150) : speed;
this.weight = weight <= 0 ? rnd.nextInt(40, 70) : weight;

View File

@ -23,15 +23,14 @@ public class FormArtillery extends JFrame {
this.setContentPane(artilleryPane);
createButton.addActionListener(e -> {
Random rnd = new Random();
_artillery = new DrawingArtillery();
_artillery.Init(
rnd.nextInt(100, 300),
rnd.nextInt(1000, 2000),
new Color(
rnd.nextInt(0, 256),
rnd.nextInt(0, 256),
rnd.nextInt(0, 256)),
rnd.nextInt(4, 7)
_artillery = new DrawingArtillery(
rnd.nextInt(100, 300),
rnd.nextInt(1000, 2000),
new Color(
rnd.nextInt(0, 256),
rnd.nextInt(0, 256),
rnd.nextInt(0, 256)),
rnd.nextInt(4, 7)
);
_artillery.SetPosition(10 + rnd.nextInt(90), 10 + rnd.nextInt(90), pictureBox.getWidth(), pictureBox.getHeight());
speedLabel.setText(String.format("Скорость: %s", _artillery.getArtillery().getSpeed()));