How can I rewrite this code ? I want to use for loop . If my score will increase about 2 points my game will add extra bomb. I dont wnat to copy cody for every 2 points
if(this.score == 2){
this.bomb.create(Phaser.Math.RND.between(0, 3200), Phaser.Math.RND.between(0, 2200), 'bomba2');
} else if (this.score == 4){
this.bomb.create(Phaser.Math.RND.between(0, 3200), Phaser.Math.RND.between(0, 2200), 'bomba2');
} else if (this.score == 6){
this.bomb.create(Phaser.Math.RND.between(0, 3200), Phaser.Math.RND.between(0, 2200), 'bomba2');
}
CodePudding user response:
Considering this language is C-style (I'm guessing Java?), I would suggest doing something along the lines of
for (int i = 2; i = 2; i < {whatever value you want goes here}) {
this.bomb.create(Phaser.Math.RND.between(0, 3200), Phaser.Math.RND.between(0, 2200), 'bomba2');
}
that should be about it considering what you are asking.