Added the main game logic function