Добавление конструкторов

This commit is contained in:
prodigygirl 2022-10-22 21:11:43 +04:00
parent 34fcedd0b7
commit b74e5b9fba
3 changed files with 4 additions and 6 deletions

View File

@ -22,9 +22,8 @@ public class DrawingArmoredCar {
return armoredCar;
}
public void Init(int speed, float weight, Color bodyColor) {
this.armoredCar = new EntityArmoredCar();
this.armoredCar.init(speed, weight, bodyColor);
public DrawingArmoredCar(int speed, float weight, Color bodyColor) {
this.armoredCar = new EntityArmoredCar(speed, weight, bodyColor);
Random r = new Random();
this.drawingCaterpillar = new DrawingCaterpillar();
this.drawingCaterpillar.Init(r.nextInt(4, 7), bodyColor);

View File

@ -7,7 +7,7 @@ public class EntityArmoredCar {
private Color bodyColor;
public float step;
public void init(int speed, float weight, Color bodyColor) {
public EntityArmoredCar(int speed, float weight, Color bodyColor) {
this.speed = speed;
this.weight = weight;
this.bodyColor = bodyColor;

View File

@ -42,8 +42,7 @@ public class FormArmoredCar extends JFrame{
@Override
public void actionPerformed(ActionEvent actionEvent) {
Random rnd = new Random();
armoredCar = new DrawingArmoredCar();
armoredCar.Init(rnd.nextInt(100,300), rnd.nextInt(1000, 2000),
armoredCar = new DrawingArmoredCar(rnd.nextInt(100,300), rnd.nextInt(1000, 2000),
new Color(rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)));
armoredCar.SetPosition(rnd.nextInt(10, 100), rnd.nextInt(10, 100),