an example of how to use state machine to build a game