Write game loop and end