Handling Guesses, Attempts, and Game Over Conditions

Learn about handling correct guesses and determining game-over scenarios due to excessive incorrect guesses in the Wordz game.

In this lesson, we will complete the tests and production code we need to drive out detecting the end of a game. This will happen when we do either of the following:

  • Guess the word correctly.

  • Make our final allowed attempt, based on a maximum number.

We can make a start by coding the end-of-game detection when we guess the word correctly.

Responding to a correct guess

In this case, the player guesses the target word correctly. The game is over, and the player is awarded a number of points, based on how few attempts were needed before the correct guess was made. We need to communicate that the game is over and how many points have been awarded, leading to two new fields in our class GuessResult. We can add a test to our existing class GuessTest as follows:

Get hands-on with 1200+ tech skills courses.