Refactor into statebased game.
Merge branch 'issue2' into develop