Pro Java 9 Games Development Leveraging the JavaFX APIs

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

To do this, we’ll need to “wrap” the score-processing contents of each Button ActionEvent event
processing construct with an if(buttonClick == true) conditional evaluation layer. This will only
allow event processing if the buttonClick is on (true) and will then turn it off at the end of that processing
using the simple buttonClick = false; Java statement. This will be the last statement before exiting the
if(buttonClick == true) Java code construct.
Your Java code should look like the following, which is also highlighted at the beginning of Figure 23-15
and at the end of Figure 23-16, since the ActionEvent handling structures for these four Button UI objects
span more than 120 lines of Java code for each Button’s .setOnAction() event-handling infrastructure:


private void createQAprocessing() {
a1Button.setOnAction( (ActionEvent event) -> {
if (buttonClick == true) { // Evaluates if (buttonClick == true) then {not yet clicked}
if (picked == Q1S1 && pickS1 == 0)
...
buttonClick = false; // If this Button has been clicked then set buttonClick to false
}
});
}


Figure 23-15. Use a conditional if(buttonClick == true) statement at the top of each Button event processing
structure

Free download pdf