Pro Java 9 Games Development Leveraging the JavaFX APIs

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

The first thing we’ll need to do is to add each spin’s rotation amount to the spinDeg “accumulator”
variable. This will be done inside the if(picked == spinner) logic in the MouseEvent handler in
the createSceneProcessing() method body, inside each of four if(spin == randomNum) conditional
statements that set each random quadrant.
Inside of your .createSceneProcessing() method and inside of the if(picked == spinner) conditional
construct, add an accumulator statement spinDeg += degrees for each of the four random spin if(spin ==
random) conditional constructs.
These should be spinDeg += 1080;, spinDeg += 1170;, spinDeg += 1260;, and spinDeg += 1350;,
respectively. As you can see, the angle value passed to the Animation objects should also be the same value
added to the spinDeg accumulator variable so that you have a record of all the angle increments that your
user has spun.
At the bottom of the spinner random number picked conditional if() structure body, add the call
to the calculateQuadrantLanding() method so that after the spin has occurred, you then calculate the
offset (the quadrant) for that pick and seed (write) that integer data value into your quadrantLanding
variable for use in your other game logic, which we will be coding later during this chapter. We will code the
calculateQuadrantLanding() method next.
The Java code for the spinDeg accumulator and the calculateQuadrantLanding() method call should
look like the following and is highlighted in blue and yellow in Figure 19-2:


if (picked == spinner) {


int spin = random.nextInt(4); // Random Number Generator determines next quadrant


if (spin == 0) {
rotGameBoard.setByAngle(1080);
rotSpinner.setByAngle(-1080);
spinDeg += 1080; // Add 1080 to the spinDeg total
}


if (spin == 1) {
rotGameBoard.setByAngle(1170);
rotSpinner.setByAngle(-1170);
spinDeg += 1170; // Add 1170 to the spinDeg total
}


if (spin == 2) {
rotGameBoard.setByAngle(1260);
rotSpinner.setByAngle(-1260);
spinDeg += 1260; // Add 1260 to the spinDeg total
}


if (spin == 3) {
rotGameBoard.setByAngle(1350);
rotSpinner.setByAngle(-1350);
spinDeg += 1350; // Add 1350 to the spinDeg total
}


rotGameBoard.play();
rotSpinner.play();


calculateQuadrantLanding(); // Call Method to calculate quadrantLanding variable
}

Free download pdf