Ending the game
If the game is not ended, the game is playing, and if the player has just died or won, the game is ended. We need to know when the game is ended and when it is playing. Let's make a new member variable gameEnded
and declare it after the TDView
class declaration:
private boolean gameEnded;
Now, we can initialize gameEnded
in the startGame
method. Enter this code as the very last line in the method.
gameEnded = false;
Now, we can finish the last few lines of our game rules logic, but wrap them in a test to see if the game has ended or not. Add the following code to conditionally update our game rules logic, right at the end of the TDView
class's update
method:
if(!gameEnded) { //subtract distance to home planet based on current speed distanceRemaining -= player.getSpeed(); //How long has the player been flying timeTaken = System.currentTimeMillis() - timeStarted; }
Our HUD will now have accurate data to keep the player informed of...