Im trying to subtract 100 and a random number but instead the 100 became a random number itself.
Below is a block of code which I used to generate random number and subtract the life which is a 100. Where did I go wrong I really thought my do-while statement works
public void run() {
Random r1 = new Random();
Random r2 = new Random();
int n1 = r1.nextInt(10 - 1) + 1;
int n2 = r2.nextInt(10 - 1) + 1;
damage1.setText(String.valueOf(n1));
damage2.setText(String.valueOf(n2));
int life1 = 100, life2 = 100;
if(life1 == 0 || life2 == 0){
gameOver();
} else {
do {
bar2.setProgress(life1);
percent2.setText(String.valueOf(life1));
life1-=n1;
}
while(life1 > 0);
do {
bar1.setProgress(life2);
percent1.setText(String.valueOf(life2));
life2-=n2;
}
while(life2 > 0);
}
}
Aucun commentaire:
Enregistrer un commentaire