Game Development Reference
In-Depth Information
notice that the addNodesToStackPane() method is beginning to see more use now that
we are adding more UI elements to the game. Even though the gameScore variable will
be updated dynamically during game play, these Text objects will be static in nature,
since they are declared, instantiated, configured, and positioned at start-up, just like
your other UI elements.
Figure 17-8 . Add the scoreLabel Text Node object to the JavaFX Scene Graph using a .getChildren().add() method
chain
CreatingtheScoringEngineLogic:.scor-
ingEngine()
What I want to base scoring on in this game is the type of Object, as we are going to
have fixed Actor subclass objects for the InvinciBagel to score against, such as Prop,
PropV, PropH, PropB, Treasure, Projectile, Enemy, and similar. Since the switch-case
structure does not support using an Object in its evaluation logic, we are going to have
to use conditional if() statements, along with the Java instanceof operator, which, as
you can tell from its name, is used to determine object type or instance; in this particu-
lar case, to start with, if the Actor object is an instance of the Prop , PropV , PropH ,
or PropB class. The basic Java code structure for the scoringEngine() method evalu-
ates one if() for each Actor object type, and then sets the gameScore variable, which is
displayed by the scoreText Text object, inside of the invinciBagel object. This pro-
gramming logic can all be seen in Figure 17-9 . The Java code should look like this:
 
 
Search WWH ::




Custom Search