Created
September 24, 2014 16:09
-
-
Save pumpkincouture/b4473a5ed9c74059b887 to your computer and use it in GitHub Desktop.
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
class Board | |
include TTTConstants | |
attr_reader :cells | |
def initialize(user_interface, board_choice) | |
@ui = user_interface | |
@board_choice = board_choice | |
@cells = Array.new(board_choice * board_choice, []) | |
end | |
def invalid_key(answer) | |
answer.to_i == 0 || cells[answer.to_i - 1] == X_PIECE || cells[answer.to_i - 1] == O_PIECE | |
end | |
def valid_move(answer) | |
cells[answer.to_i - 1] = O_PIECE | |
@ui.human_choice(answer) | |
@ui.display_board(cells) | |
end | |
def computer_move(answer) | |
cells[answer] = X_PIECE | |
@ui.computer_choice(answer) | |
@ui.display_board(cells) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment