Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 23 ■ Completing the gameplay Code and player proofing your event handling


Finishing Gameplay: Populating Gameplay Methods


The first part of this chapter will show you how I put the Java code in place that finishes up gameplay. We will
add the answer options to the four Button UI elements in the setupQSgameplay() methods (twenty of them,
the first of which was coded already in Chapter 21 to show you how this Java coding works), and then we
will add the scoring for these answers in the createQAprocessing() method inside the ActionEvent handling
methods for each of four Q&A Button UI elements.


Add Answer Options: Finishing the setupQSgameplay() Methods


It’s not the copying and pasting of Java 9 code in the setupQSgameplay() methods that will take up most of
your time in this phase of gameplay content development but rather the confirmation of the correct answer
and the creation of incorrect answers that stump the player and cause a “Wrong:” answer. The method body
for setupQ1S1gameplay() looks like the 18 Java statements in Figure 23-1 once you’ve added four answer
options for each random pick.


Add your corresponding right and wrong answer processing to the createQAprocessing() scoring engine
we created in Chapter 22. The correct (rightAnswer and rightAnswers) answers are highlighted in yellow in
Figure 23-2.


Figure 23-1. Find and add a correct answer to a different button (and three incorrect answers) for each
random image

Free download pdf