Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 20 ■ Coding gameplay: Set Up gameplay methodS and animated Camera View

Once you type in the first if() conditional evaluation, your method name will be underlined in red
because the method does not yet exist. Use the Alt+Enter work process to have NetBeans 9 write the code
for you and select the Create method “setupQ1S1gameplay()” in javafxgame.JavaFXGame option, as
shown in blue in Figure 20-1.
Inside your setupQ1S1gameplay() method, replace the bootstrap error code with three if() random
picks for square 1 (int pickS1) conditional evaluations. This will tell your game what to do when three
different random pick numbers (0, 1, or 2) are generated. This should look like the following Java code, as
shown highlighted in Figure 20-2:


private void setupQ1S1gameplay() {
if (pickS1 == 0 ) {}
if (pickS1 == 1 ) {}
if (pickS1 == 2 ) {}
}


The reason these have wavy red error underlining under them is because pickS1 is currently declared
as int (integer) inside of the populateQuadrantOne() method, so the pickS1 variable is currently local and
needs to be made “package protected” (using no public, private, or protected keyword) and thus accessible
to your entire class.
This will be accomplished by moving your pickS1 declaration to the top of the class so that all methods
in your class (and package) can reference its data value loaded from the random number generator. You can
add pickS1 to int quadrantLanding and create a compound statement, declaring all of your integer variables
for use in one line of code.


Figure 20-2. Add conditional if() structures for random number generator result processing inside
setupQ1S1gameplay

Free download pdf