Class: GameController
- Inherits:
-
Object
- Object
- GameController
- Defined in:
- lib/game_controller.rb
Instance Attribute Summary collapse
-
#ai ⇒ Object
readonly
Returns the value of attribute ai.
-
#console ⇒ Object
readonly
Returns the value of attribute console.
Instance Method Summary collapse
- #display_board ⇒ Object
-
#initialize ⇒ GameController
constructor
A new instance of GameController.
- #opponent(player) ⇒ Object
- #play_again? ⇒ Boolean
- #present_game_result ⇒ Object
- #run ⇒ Object
- #set_players ⇒ Object
- #setup_game ⇒ Object
Constructor Details
#initialize ⇒ GameController
Returns a new instance of GameController.
14 15 16 17 |
# File 'lib/game_controller.rb', line 14 def initialize @console = ConsoleUI.new @config = Factory.new(@console) end |
Instance Attribute Details
#ai ⇒ Object (readonly)
Returns the value of attribute ai.
12 13 14 |
# File 'lib/game_controller.rb', line 12 def ai @ai end |
#console ⇒ Object (readonly)
Returns the value of attribute console.
12 13 14 |
# File 'lib/game_controller.rb', line 12 def console @console end |
Instance Method Details
#display_board ⇒ Object
52 53 54 |
# File 'lib/game_controller.rb', line 52 def display_board @board_printer.print(@board.get_print_results) end |
#opponent(player) ⇒ Object
70 71 72 |
# File 'lib/game_controller.rb', line 70 def opponent player if player == @player1 then @player2 else @player1 end end |
#play_again? ⇒ Boolean
60 61 62 63 64 65 66 67 68 |
# File 'lib/game_controller.rb', line 60 def play_again? response = @console.query_user_for_new_game if response then true else @console.say_goodbye false end end |
#present_game_result ⇒ Object
56 57 58 |
# File 'lib/game_controller.rb', line 56 def present_game_result @console.present_game_result(@board.check_board_status) end |
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/game_controller.rb', line 19 def run @console.greet_user new_game = true while new_game setup_game player = @player1 while @board.check_board_status == :continue_game display_board move = player.make_move(@board) @console.print_player_move(move,player) player = opponent(player) end display_board present_game_result new_game = play_again? end end |
#set_players ⇒ Object
46 47 48 49 50 |
# File 'lib/game_controller.rb', line 46 def set_players players = @config.get_players @player1 = players[:player1] @player2 = players[:player2] end |
#setup_game ⇒ Object
40 41 42 43 44 |
# File 'lib/game_controller.rb', line 40 def setup_game set_players @board = @config.get_board @board_printer = @config.get_board_printer(@board) end |