Class: CLIGame
Instance Attribute Summary collapse
-
#board ⇒ Object
Returns the value of attribute board.
-
#player_first_move ⇒ Object
Returns the value of attribute player_first_move.
-
#player_one ⇒ Object
Returns the value of attribute player_one.
-
#player_two ⇒ Object
Returns the value of attribute player_two.
-
#ui ⇒ Object
Returns the value of attribute ui.
Instance Method Summary collapse
- #exit_game ⇒ Object
- #get_next_move ⇒ Object
-
#initialize(settings) ⇒ CLIGame
constructor
A new instance of CLIGame.
- #invalid_move(cell) ⇒ Object
- #play! ⇒ Object
- #start_game! ⇒ Object
Methods inherited from Game
#advance_game, #current_player, #game_status_check, #total_markers, #verify_move
Constructor Details
Instance Attribute Details
#board ⇒ Object
Returns the value of attribute board.
54 55 56 |
# File 'lib/ruby_ttt.rb', line 54 def board @board end |
#player_first_move ⇒ Object
Returns the value of attribute player_first_move.
54 55 56 |
# File 'lib/ruby_ttt.rb', line 54 def player_first_move @player_first_move end |
#player_one ⇒ Object
Returns the value of attribute player_one.
54 55 56 |
# File 'lib/ruby_ttt.rb', line 54 def player_one @player_one end |
#player_two ⇒ Object
Returns the value of attribute player_two.
54 55 56 |
# File 'lib/ruby_ttt.rb', line 54 def player_two @player_two end |
#ui ⇒ Object
Returns the value of attribute ui.
54 55 56 |
# File 'lib/ruby_ttt.rb', line 54 def ui @ui end |
Instance Method Details
#exit_game ⇒ Object
92 93 94 95 |
# File 'lib/ruby_ttt.rb', line 92 def exit_game board.display_board ui.io.exit end |
#get_next_move ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/ruby_ttt.rb', line 78 def get_next_move if current_player.is_a?(HumanPlayer) move = ui.request_human_move verify_move(move) ? advance_game : invalid_move(move) else current_player.make_move(board) advance_game end end |
#invalid_move(cell) ⇒ Object
88 89 90 |
# File 'lib/ruby_ttt.rb', line 88 def invalid_move(cell) board.valid_cell?(cell) ? ui.(cell) : ui.(cell) end |
#play! ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/ruby_ttt.rb', line 69 def play! ui. until board.game_over? board.display_board get_next_move end exit_game end |
#start_game! ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/ruby_ttt.rb', line 60 def start_game! begin play! rescue Interrupt ui. exit end end |