Start a new Game
If you remember our originally planned behavior, and I don't blame you if you don't, we wanted to draw a new game button on the screen when RHB crashed and fell over. Then, when it's clicked, we want to start a new game. For that to happen, we'll need to do the following:
- Check whether
RedHatBoyStateMachine
isKnockedOut
, and if so, transition fromWalking
toGameOver
. - On that transition, draw the new game button.
- Add an
onclick
handler so that when the button is clicked, we transition back toReady
with a newWalk
instance. - On the transition to
Ready
, hide the button and restart the game.
All the code we wrote before was to make that change easier. Let's see whether we were right about that:
- Transition from
Walking
toGameOver
.
To transition from Walking
to GameOver
, we need to return the GameOver
state from the WalkTheDogState<Walking>
update
method, but when should we do that? We'll need...