Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 20 ■ Coding gameplay: Set Up gameplay methodS and animated Camera View


questions that the player will need to master to score points. These if() statements will look for the Node
picked and send the player to the correct selectQSgameplay() method. The pseudocode for this structure
would look like the following:


if (pickedNode == Q1S1) { call the selectQ1S1gameplay() method }
if (pickedNode == Q2S2) { call the selectQ2S2gameplay() method } // and so on, out through Q4S5


Once we’ve created several of these statements, we can use the Alt+Enter keystroke combination and
have NetBeans create an empty method structure for us. Once we create that method structure, we can then
use copy and paste to create 20 methods, testing the code for each quadrant as we create it, until all 20 have
been completed.


Game Board Square Interaction: OnMouseClick() Event Handling


Let’s create the first of the event processing conditional if() statements that look for Q1S1 through Q4S5
square node mouse click events. I’m going to put 20 game board square Node evaluations inside of (right
after) the if(picked != null) outer if() structure and before the if(picked == spinner) structure since
these structures simply call a method if a Box Node is clicked. It is important to note that I cannot use the
switch-case structure because currently that structure is not compatible with object evaluations, only string,
enum, and numeric evaluations. This should look like the Java statements and method call shown here (and
highlighted in light blue and yellow in Figure 20-1):


if (picked != null) {
if (picked == Q1S1) { setupQ1S1gameplay(); }
... // 3D spinner UI processing logic will go after all game board square processing
logic
}


Figure 20-1. Add an if(picked==Q1S1) conditional evaluation; use Alt+Enter to create a
setupQ1S1gameplay() method

Free download pdf