Time for action – finishing the game
Following are the steps to complete our game:
The
nextTurn
method checks if the game is over. If so, it will delegate control to thegameOver
method, or else, it will generate the next random letter (by calling thegame.nextLetter()
method) and will update the label showing the new letter. As you have seen in previous snippets, this method is called every time the user clicks on an empty cell. Here is the implementation:public class BoxwordsUI extends UI implements ItemClickListener { // ... private void nextTurn() { if (game.over()) { gameOver(); } else { currentLetter.setValue("Next letter: "+ game.nextLetter()); } } // ... }
The
gameOver
method updates the UI to show the score and correct words. For each word, we include a link to the corresponding Merriam-Webster dictionary definition by using an HTML tag. Here is the implementation:public class BoxwordsUI extends UI implements ItemClickListener { // ... private...