Class: Game
- Inherits:
-
Object
- Object
- Game
- Defined in:
- lib/game.rb
Instance Attribute Summary collapse
-
#board ⇒ Object
readonly
Returns the value of attribute board.
-
#current_player ⇒ Object
readonly
Returns the value of attribute current_player.
-
#player_o ⇒ Object
readonly
Returns the value of attribute player_o.
-
#player_x ⇒ Object
readonly
Returns the value of attribute player_x.
Instance Method Summary collapse
- #change_turns ⇒ Object
- #game_over? ⇒ Boolean
-
#initialize(board, player_x, player_o) ⇒ Game
constructor
A new instance of Game.
- #take_turn ⇒ Object
Constructor Details
#initialize(board, player_x, player_o) ⇒ Game
Returns a new instance of Game.
5 6 7 8 9 10 |
# File 'lib/game.rb', line 5 def initialize(board, player_x, player_o) @board = board @player_x = player_x @player_o = player_o @current_player = player_x end |
Instance Attribute Details
#board ⇒ Object (readonly)
Returns the value of attribute board.
3 4 5 |
# File 'lib/game.rb', line 3 def board @board end |
#current_player ⇒ Object (readonly)
Returns the value of attribute current_player.
3 4 5 |
# File 'lib/game.rb', line 3 def current_player @current_player end |
#player_o ⇒ Object (readonly)
Returns the value of attribute player_o.
3 4 5 |
# File 'lib/game.rb', line 3 def player_o @player_o end |
#player_x ⇒ Object (readonly)
Returns the value of attribute player_x.
3 4 5 |
# File 'lib/game.rb', line 3 def player_x @player_x end |
Instance Method Details
#change_turns ⇒ Object
17 18 19 |
# File 'lib/game.rb', line 17 def change_turns @current_player = @board.current_player_marker == "X" ? @player_x : @player_o end |
#game_over? ⇒ Boolean
21 22 23 |
# File 'lib/game.rb', line 21 def game_over? @board.game_over? end |
#take_turn ⇒ Object
12 13 14 15 |
# File 'lib/game.rb', line 12 def take_turn @board = @board.place_marker(@current_player.choose_space(@board)) change_turns end |