Added functionality to detect when the game is over