- implemented logic for the end of the game