Change the main game logic

I've rewritten in sequence and events to be processed by a recursive
function.