game logic from begin to end