Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

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


CHAPTER 20


Coding Gameplay: Set Up


Gameplay Methods and


Animated Camera View


So far you have your gameplay random quadrant selection logic coded, and you are tracking the quadrant
landing for each spin. Now we need to put the bulk of the Java code into place that populates these four
quadrants with the game board square random content selection for each of the five squares that are
attached to any given quadrant. We also need to create the code that allows a player to select one of the
topic questions by clicking an image. This will populate the quadrant with images and move the camera
into position so the selected image is larger (more viewable). This means we’ll also be covering the use of
Animation objects, in conjunction with your Camera object, during this chapter.
During this chapter, we’ll be creating more than a dozen new setupQSgameplay() methods, which will
contain the code that sets up the next level of gameplay (the questions regarding the image content) for each
game board square. This way, when a player clicks a given game board square, that method will be called to
set up the “Q&A” experience.
This means that we will be adding several hundred lines of code during this chapter; fortunately, we
will use an optimal “code once, then copy, paste, and modify” approach, so there will not be as much typing
involved as you might imagine. Once we finish coding the bulk of this gameplay content selection and
display infrastructure and test each quadrant to make sure it is working, we can do the question and answer
portion of the code in Chapter 21 and then code the scoring engine in Chapter 22 to complete the majority of
the “core” gameplay experience.


Select Game Content: selectQSgameplay() Methods


To allow a player to select a game board square to test their knowledge, we must add to the
createSceneProcessing() method, which contains our event handling for mouse clicks on the 3D
SceneGraph Node objects. Prior to this chapter, this was the 3D spinner UI element, but now we’ll have
to add 20 more event handling conditional if() processing statements so that if one of the 20 game board
squares is clicked, its corresponding selectQxSxgameplay() methods is called to process the gameplay
logic for that square’s content. We’ll start with coding and testing the first if (picked == Q1S1) structure.
Since visuals (texture maps) for the gameplay content are already created, using a work process outlined
in Chapter 18 , these methods will correctly display those image assets and also trigger the gameplay

Free download pdf