Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

© Wallace Jackson 2017 513
W. Jackson, Pro Java 9 Games Development, https://doi.org/10.1007/978-1-4842-0973-8_21


CHAPTER 21


Questions and Answers:


Finishing the Setup Methods


and Digital Audio


Now that your players can click more than one image for each board game square to select the visual
question to be answered, we can add the answers to these questions in their own UI. This will be done
using a second qaLayout StackPane object and four child Button objects, which expands our SceneGraph
hierarchy to four branches (one for 3D, one for 2D UI, one for 3D UI, and one for 2D answer content). We will
add a fifth top-level branch for scoring in the next chapter, when we implement our scoring engine and a 2D
scoring content UI area on the right side of your game.
During this chapter, we will continue populating the 20 setupQSgameplay() methods with all the text-
based answer content that matches up with the visuals (questions) that we added during Chapter 20. We’ll
also be adding the qaLayout branch to your SceneGraph, which includes a StackPane background and four
large Button UI elements. The players will use these to select the correct answer, revealing what the visual for
that square represents.
This means you’ll be adding several hundred lines of code during this chapter. Fortunately, you can use
an optimal “code once, then copy, paste, and modify” approach, so there won’t be much typing involved! I
only need to show you how to add one group of answers to one setupQ1S1gameplay() method, and then you
will be able to add the rest of your visual question’s answer options, so I won’t need to actually add hundreds
of lines of Java 9 code into this chapter’s code (text) and figures. However, I will have to add them to the
source code, which you can download.
Once we finish coding the bulk of the gameplay “answer selection and display” infrastructure and test
each quadrant to make sure it is working, we can create the scoring portion of the Java code in Chapter 22.
We will also be looking at the JavaFX AudioClip class, which will allow us to add audio sound effects. This
will further enhance the pro Java 9 gameplay experience using yet another new media component (digital
audio) of the JavaFX API (environment).


Finishing the Gameplay: Adding a qaLayout Branch


The primary task for the first part of the chapter is to finish up gameplay by adding the UI for answer
selection to the game. We’ll also load the setupQSgameplay() methods with the text (Button labels) answers
for each visual question. We will do this in the first half of the chapter and then add some sound effects to the
game in the second part of the chapter. We’ll start with a bit of custom method organization and stratify our
methods so that there is one for 3D Node components, one for 2D UI Node components that you see upon
game startup, one for 2D UI Node components for selecting answers (we will create this during this chapter),

Free download pdf