The controller class for this view is StatsController.java. The Statistics ViewįXML file stats.fxml describes the Statistics view, shown in Figure 2. Note: See WordStats.java and GameStatus.java. forEach(i -> guessDistribution.put(i, 0)) A value of zero means the user did not guess the word in the allotted six tries. Variable thisGameGuesses is how many guesses the most recent game took (one through six). The key corresponds to the number of tries a successful play took (a number between 1 and 6, inclusive) and the value is the number of games that took that number of tries. Variable guessDistribution is a HashMap with Integer keys and values. Here’s the WordStats class and its class variables (without the getters and setters). Keeping Track of the Game StatsĬlass WordStats stores our game-playing statistics as the user works through each game. Let’s show you how to display both these game statistics as well as the JavaFX BarChart Guess Distribution, as shown in Figure 2. Note: This version of Wordish does not persist game statistics. However, if the most recent game is a loss, then none of the bars are green. The green bar shows the guess level of the most recent game. Likewise, the corresponding X axis value reflects the number of games at each guess level. Here you see the left Y axis shows the number of guesses it took the user for a correct answer (1 through 6). Similar to the Wordle game, we display the number of games played, win percentage, current streak, and maximum streak, as shown in Figure 2.īelow the statistics data, we display the Guess Distribution as a horizontal bar chart. To do this, we collect the game statistics in a singleton object, GameStats, which includes data collected into object WordStats. The bar chart icon in the main Wordish view takes you to the Statistics view, where a user can see game statistics accumulated during play. Part 4, What’s in a Word, Anyway?, examines how we get our words and how we determine if a submitted word is valid.Īnd now in Part 5, we turn to JavaFX charts, showing how to customize charts with orientation and colors and how to add nodes to the chart scene graph.įurthermore, we look at implementing a customized Popup control.īefore we start, here’s an example screenshot of Wordish. In addition, we covered incorporating third-party font libraries and customizing Scene Builder to leverage these features.Next, in Part 3, we explored the controller code that maintains game state and responds to user input with appropriate updates to the UI. We introduced specialized Label and Button controls that use pseudo-classes for advanced CSS styling. In Part 2, we discussed look and feel enhancements. In Part 1, we introduced the Wordish game with JavaFX and discussed the main UI layout. Welcome to Part 5 and the final installment of this series. NLJUG Academy Masterclasses: Java Flight Recorder.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |