refactoring gameFrame and endGame  bug-fix