Created
October 25, 2018 16:54
-
-
Save manzanit0/47961ffd12786eab60872d2caeeef78c to your computer and use it in GitHub Desktop.
Refactor: keeping the same level of abstraction.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def play | |
| clear_console | |
| print_menu | |
| option = get_menu_option | |
| factory = GameFactory.new | |
| @game = factory.create_game(option) | |
| clear_console | |
| print_board(@game.board) | |
| until @game.has_ended? | |
| @game.make_move | |
| clear_console | |
| print_board(@game.board) | |
| end | |
| if @game.winner != nil | |
| @out.print "The winner is #{@game.winner.symbol}" | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def play | |
| init_game | |
| until @game.has_ended? | |
| process_turn | |
| end | |
| restart | |
| end | |
| private | |
| def init_game | |
| print_menu | |
| options = get_menu_option | |
| factory = GameFactory.new | |
| @game = factory.create_game(options) | |
| print_board(@game.board) | |
| end | |
| def process_turn | |
| @game.make_move | |
| print_board(@game.board) | |
| end | |
| def restart | |
| if @game.winner != nil | |
| @out.print "The winner is #{@game.winner.symbol}" | |
| end | |
| # TODO prompt for reestart | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment