implemented the main game logic