The goal of this code is a simple project where I want to run a while-loop to see how long it takes for my static Bird Object to either die (reach 0) or Pass a set amount (goal = 20) but each time I run the project It does it's job once; Than it wants to pick a random number for my Bird1.HP and then breaks the code forever. If you could aid me I'd greatly appreciate it.
public static int loop() {
Random rand = new Random();
int pcChoice;
int shock = 1;
int health = 2;
int goal = 20;
pcChoice = rand.nextInt(2) + 1 ;
while (Bird1.HP < goal) {
if (pcChoice == shock) {
Bird1.HP = Bird1.HP - 5;
System.out.println("Chip was Shocked");
System.out.println("Chips Health is: " + Bird1.HP);
}
else if (pcChoice == health) {
Bird1.HP = Bird1.HP + 2;
System.out.println("Chip Ate some food");
System.out.println("Chips Health is: " + Bird1.HP);
}
else {
System.out.println("nothing is done");
}
}
return Bird1.HP;
Aucun commentaire:
Enregistrer un commentaire