Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 23 ■ Completing the gameplay Code and player proofing your event handling

Next, let’s “player proof ” your current code by adding boolean variables that will prevent repetitive
clicks.


Player-Proofing Code: Controlling Player Event Usage


The game is “theoretically” finished, and we could just trust players to click (once) on correct i3D and i2D
UI elements to play the game. However, the intended audience for this particular game includes underage
children, mentally challenged individuals, disabled players, and autistic players. Thus, we’ll put in place
some controls that make sure players click only once on the correct UI elements to play this game. Let’s
start the process by declaring (top of class) and adding a squareClick boolean variable set to true in
rotGameBoard.setOnFinished(), as shown here and in Figure 23-11:


rotGameBoard.setOnFinished(event-> {
if (quadrantLanding == 315) { populateQuadrantOne(); }
if (quadrantLanding == 225) { populateQuadrantTwo(); }
if (quadrantLanding == 135) { populateQuadrantThree(); }
if (quadrantLanding == 45) { populateQuadrantFour(); }
spinnerAudio.stop();
squareClick = true;
});


Figure 23-11. Add a squareClick boolean variable set to true at the end of your rotGameBoard.
setOnFinished() handler

Free download pdf