Skip to content

Instantly share code, notes, and snippets.

@manzanit0
Created October 25, 2018 16:54
Show Gist options
  • Select an option

  • Save manzanit0/47961ffd12786eab60872d2caeeef78c to your computer and use it in GitHub Desktop.

Select an option

Save manzanit0/47961ffd12786eab60872d2caeeef78c to your computer and use it in GitHub Desktop.
Refactor: keeping the same level of abstraction.
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
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