implementing the main game logic