Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

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


You could add pickS1 through pickS20 to this compound statement, as you modify each
populateQuadrant() method’s Java code, or you could just add all 20 new int variables first and then remove
the int declaration from all of the populateQuadrant() methods second, at which point your code structure,
shown in Figure 20-3, will be error-free.


Initially, we were using this statement in the populateQuadrant() methods to declare and load the
pickSn int (integer) variable with the current content result for the game board square from a random
number generator object.


int pickS1 = random.nextInt(3); // Next declare int at top of class, so it needs to be
removed!


Now that we have declared these integer random number “holders” with “global” (rather than local)
access, the previous Java 9 statement will become even simpler and will look like the following, as shown in
Figure 20-3:


pickS1 = random.nextInt(3);


Figure 20-3. Declare int pickS1 at the top of the class so it can be used in the populateQuadrant() and
setupQSgameplay() methods

Free download pdf