Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 19 ■ Game Content enGine: ai LoGiC with random Content SeLeCtion methodS


We also want to see that we’re getting a random quadrant selection result, which is circled in red in the
bottom-left corner of Figure 19-4.


Now that you have ascertained that your calculateQuadrantLanding() method works and random
quadrant selection is working relatively well, we need to work on the code that populates your selected game
board squares.


Populating Quadrants After a Spin: OnFinished() Event Handling


Now that we have modified your MouseEvent handling construct in the createSceneProcessing()
method, let’s open up the createAnimationAssets() method and add some more event handling in the
rotGameBoard Animation object so that we can trigger some code upon the completion of the Animation
object’s rotation cycle to populate the game board squares. The reason we’re doing this is because if we
populate the game board squares before the spin, players will know where the spinning game board is going
to stop! Also, I wanted to show you how to “wire up” an Animation object so that it can trigger other events
and code constructs once it finishes playing, which is important for pro Java 9 games development, as you
might well imagine. We will start by implementing an empty event handling infrastructure that we will use to
hold conditional if() Java logic telling the game board squares how to populate themselves using a method
call to one of four populateQuadrant() methods, populateQuadrantOne() through populateQuadrantFour().
This is where we have to initially speculate on which angle offset value in quadrantLanding should equate
to each of the game board quadrant color spaces (orange or animal, green or vegetable, blue or mineral, and
pink or other topic).
The Java 9 code needed to create your initial (empty) OnFinished event handler lambda expression is
as follows; it is also highlighted in red, yellow, and blue in Figure 19-5:


rotGameBoard.setOnFinished( event-> { ... } );


Figure 19-4. Test the code to make sure that the remainder output represents one of the four quadrant
rotation offsets

Free download pdf