Implementing the rules
Now, we should pause and think about what we need to do later in the project because it will affect what we do while implementing our rules. When the player's ship is destroyed or when player reaches their goal, the game will end. This implies that the game will need to be restarted. We don't want to quit back to the home screen each time, so we need a way to restart the game from within the TDView
class.
To facilitate this, we are going to implement a startGame
method in our TDView
class. The constructor will be able to call it and our game loop will also be able to call it when necessary as well.
It will also be necessary to pass some of the tasks that the constructor currently performs onto the new startGame
method so that it can properly do its job. Also, we will use startGame
to initialize some of the variables that our game rules and HUD require.
In order to accomplish what we discussed, startGame()
will need a copy of the application's Context
object. So, like...