Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1
Chapter 19 ■ Game Content enGine: ai LoGiC with random Content SeLeCtion methodS

Next, let’s code your rotGameBoard.setOnFinished() event handling method body using a series of
conditional if() statements. Each one of these will evaluate one of the four quadrantLanding angle offset
integer values and will “wire” that value up to a method call to one of these four populateQuadrant()
methods located at the end of the class.
These populateQuadrant() methods will then do the work of randomly selecting from your different
content images for each game board square, of which I currently have fifteen (three for each of the five
attached game board squares for quadrant 1). Therefore, we’ll have a random.nextInt(3) method, which
will select from the three image assets for each square, set the diffuse Image object to reference the selected
digital image asset, and then set the Shader for that game board square to reload that Image object into
memory for that texture map.
To test this, we will need to code at least one of these populateQuadrant() methods; the logical one
is the populateQuadrantOne() method since we have the game board quadrant content (game board
squares 1 through 5) created. After we test this .setOnFinished() event handler to see whether these angle
offsets do indeed take us to the correct quadrant, we will then create the populateQuadrantTwo() through
populateQuadrantFour() method body code by (temporarily) utilizing content from quadrant 1 as “dummy”
content, used for code testing purposes only.
Your new .setOnFinished() event handling method body will initially start with 45 degrees and progress
through 315 degrees; it should look like the following code, as shown highlighted in blue and yellow in
Figure 19-6:


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


Figure 19-5. The empty createAnimationAssets() setOnFinished() event handling infrastructure for the
rotGameBoard Animation

Free download pdf