refactor visualWhenGameOver function