Declare That the Player Has Lost
Understand how to program the losing condition in a Ruby-based hangman game by counting incorrect guesses. Learn to update error counters, use conditional checks to end the game after seven wrong attempts, and reveal the hidden word to the player. This lesson helps you enhance game functionality and user feedback.
We'll cover the following...
We'll cover the following...
Define the rules of the game
Let’s now include a condition for the player to lose the game if they haven’t guessed the word in seven tries. Let's have a look at the updated implementation for this requirement.
Count errors
We must count the number of errors. Therefore, we assign the name errors_counter to zero (the value) at line 8.
When we conclude that the proposal is wrong, we recall the value associated with the errors_counter ...