refactor game finish function, add a end game dialog