![]() | Dice game, Need help improving game! |
|
30 Jul 2012, 19:44
kevin estrella (1 post) |
Ok so I have the dice game working and everything but i want to change it. |
|
31 Jul 2012, 15:14
Maik Schmidt (110 posts) |
Hi Kevin! So, you wanna cheat, eh? :-) For the current structure of the sample program I do not see an easy solution to your problem. To increase your chances you have to increase your amount of guesses. Therefore you have to count the current number of guesses in a separate variable. You also need a constant storing the maximum number of guesses. Add the following declarations to the top of the program: const unsigned int MAX_GUESSES = 2; int guess_count = MAX_GUESSES; Now you have to change both the if (guess > 0) return; In
void handle_start_button() {
if (start_button.update()) {
if (start_button.read() == HIGH) {
if (guess > 0) {
while (guess_count-- > 0)
{
const int result = random(1, 7);
if (result == guess) {
output_result(result);
Serial.print("Result: ");
Serial.println(result);
Serial.println("You win!");
hooray();
break;
} else if (guess_count > 0) {
continue;
} else {
Serial.println("You lose!");
break;
}
}
}
delay(2000);
guess = 0;
guess_count = MAX_GUESSES;
}
}
}
I do not have an Arduino at hand right now, so I could not test the program. Still it should give you an idea of what you have to do. If you still have any problems, do not hesitate to ask. Hm, now that I think of it, Cheers, |
| You must be logged in to comment |

