Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

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


Figure 19-12. Use Run ➤ Project to test your code; something is still wrong with the quadrantLanding
conditional if() code


Since we can’t simply rotate the values again in the conditional if() evaluation lookup matrix, something
else must be going on here! In thinking about the rotation, even though the values in the RotateTransform
are positive, I remember from correcting the spinner direction using negative values to make it move
forward that the game board is actually spinning backward or counterclockwise, which looks better for the
game board spin anyway. Thus, I do not want to change that! This means I need to go back to the original
45, 135, 225, 315 evaluation and simply reverse that because the game board is actually spinning backward
mathematically, so your correct evaluation order should be reversed to be 315 (quadrant 1), 225 (quadrant
2), 135 (quadrant 3), and then 45 (quadrant 4).
This new angle evaluation order to the populateQuadrant() method pairing should fix our problem
once and for all, so let’s go back into the createSceneProcessing() method body in the OnFinished() event-
handling infrastructure and reorder these quadrantLanding == angle values to start with 315 and decrease
by 90 degrees each time down to 45 degrees. You can see here that your code and thought logic must be in
sync to successfully create your game logic!
Notice that populating these quadrants with “dummy content” allows you to better ascertain what
is going on with your gameplay logic and still put in place code where later you only have to change a
few characters once all of the game board content has been developed. As you can probably tell from the
previous chapter, this takes as long as coding the game, possibly even longer, depending on how much
content you are going to include with your game.
I’m going to try to provide at least three images (topics or questions) per game board square. However,
for a professional Java 9 game, you would want to have at least nine (using a random.nextInt(9) method call)
to get a more random content appearance to the content selection frequency. Since I have to write this book
in a short time period, I will not be able to pull this off while also developing the gameplay logic, coding, and
screenshots.
Besides trying this new .setOnFinished() event handling Java code block, I copied and pasted the Java
code from the populateQuadrantOne() method body to create the populateQuadrantThree() method body
and edited it to create game square content for the next round of tests. If it works, I’ll do the same thing for
populateQuadrantFour().

Free download pdf