Pro Java 9 Games Development Leveraging the JavaFX APIs

(Michael S) #1

Chapter 22 ■ SCoring engine: Creating the SCore Ui LayoUt and SCoring the Content


Also change “Great Job!” to “Spin Again.” To be able to display a wrongAnswer integer, we need to add
a wrongAnswers Text object to createScoreNodes(). This is done with a copy-and-paste process. Copy the
scoreWrong block of Java code directly underneath itself. Set the color to Black and the X position to 96.
The Y position stays the same to align the two Text objects. Set the initial text value to zero using a “0” String
value in the constructor method.
The Java 9 code, shown at the bottom of Figure 22-30, should look just like the following code:


wrongAnswers = new Text("0"); // Initializes wrongAnswers to Zero
wrongAnswers.setFont(Font.font("Arial Black", 64));
wrongAnswers.setFill(Color.BLACK);
wrongAnswers.setTranslateX( 96 );
wrongAnswers.setTranslateY(160);


Remember that in order to see the rightAnswers and wrongAnswers answer result Text object value
holders, you must add them to your SceneGraph hierarchy inside the scoreLayout StackPane .getChildren().
addAll() statement.
I used only one screenshot to show adding these Text Nodes to the StackPane to save space in
the chapter, as we have a lot of Java coding to do to complete your board game scoring and grading
infrastructure. Once we finish testing this code, all that you’ll have to do is to copy this scoring code for the
other 59 options inside of your createQAprocessing() method body, creating the scoring for the other 19
game board squares. This will need to match your other 59 sets of answers, which you’ll copy and paste to
create and then edit using the code we created in Chapter 21.


Figure 22-30. Add the wrongAnswers Text object to createScoreNodes() to display the result of the integer
calculation

Free download pdf