Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

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


As you can see in Figure 23-33, I have also selected the createBoardGameNodes() squareClick =
false; statement for deletion since we are going to do this in your createSceneProcessing() method. In fact,
this has already been shown in Figure 23-31, highlighted in yellow along the far right side of the screenshot,
which is where it logically belongs.


The place that you would want to set your four squareClick variables to true (allow a click on this
quadrant’s square) is at the end of each populateQuadrantNumber() method call to finalize the setup. This
allows one of the squares to be clicked in order to select the content for that quadrant’s topic.
A squareClick1 variable goes at the end of populateQuadrantOne(), a squareClick2 variable goes at
the end of populateQuadrantTwo(), a squareClick3 variable goes at the end of populateQuadrantThree(),
and the squareClick4 variable goes at the end of populateQuadrantFour().
Now there is a squareClickN variable that pertains to each of the four quadrants. This better matches
up with the gameplay paradigm, as now we can turn on mouse clicks selectively for only the game board
quadrant that a player has landed on and turn the game board squares off for the other three quadrants.
This will prevent what tests uncovered in Figure 23-30, where quadrants that had not been selected by the
random number generator could still be played. Since this looks incorrect visually (as you can see), we will
fix this by turning off the squares on a quadrant-by-quadrant basis, which will solve this problem, albeit with
more complex player-proofing Java code.
The Java code for the populateQuadrantOne() method body looks like the following, which is
highlighted in light blue and yellow at the bottom of Figure 23-34:


private void populateQuadrantOne() {
pickS1 = random.nextInt(3);
if (pickS1 == 0){diffuse1 = new Image("/gamesquare1bird0.png", 256, 256, true, true,
true);}
if (pickS1 == 0){diffuse1 = new Image("/gamesquare1bird1.png", 256, 256, true, true,
true);}
if (pickS1 == 0){diffuse1 = new Image("/gamesquare1bird2.png", 256, 256, true, true,
true);}
Shader1.setDiffuseMap(diffuse1);
...
squareClick1 = true;
}


Figure 23-33. Select and delete the squareClick = false; statement in createBoardGameNodes(), as we’ve
already moved it

Free download pdf