Im making a dog text adventure game for my Java class, and my latest assignment was to add probability and training to the game.
Basically I have a random number generated, and if the number associated with the skill "Shake " for instance is greater then a set number, then the dog will perform the trick successfully.
That part is working 100% for me.
Now adding training is where Im running into problems. I have each skill set to an initial value of 1. Each time a skill is performed successfully the value increases by 1.
My goal is to have the max value of 3, and if the max valued is reached, then the dog performs the trick every single time its executed!
Here is what I have, hopefully someone can explain why its not working
// Sit
if (Trick.equalsIgnoreCase("Sit")) {
if (roll >= 4 || sitSkill == 3) {
System.out.println("\n" + name + " sat down for you!");
energy -= 10;
food -= 5;
sitSkill ++;
happy ++;
} else {
System.out.println("\n" + name + " did not perform the trick successfuly.");
energy -= 10;
food -= 6;
happy -= 20;
}
}
I can't tell exactly what you're trying to get help with, but the most obvious issue that I can see is that in the case where sitSkill == 3
, you still call sitSkill++
, and so after that iteration, it will be equal to four, causing the else statement to be triggered if the roll is too low.
I think you have to stop the increment sitSkill
once you reach 3, otherwise it will increment every time at which pointsitSkill == 3
would always be false.
if(roll >= 4 || sitSkill == 3){
if(sitSkill < 3) {
sitSkill++;
}
System.out.println("\n" + Name + " sat down for you!");
Energy -= 10;
Food -= 5;
Happy ++;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With