detect endings and stop the game