Class: XO::GameContext
- Inherits:
-
Struct
- Object
- Struct
- XO::GameContext
- Defined in:
- lib/xo/engine/game_context.rb
Instance Attribute Summary collapse
-
#grid ⇒ Object
Returns the value of attribute grid.
-
#turn ⇒ Object
Returns the value of attribute turn.
Instance Method Summary collapse
- #check_turn(turn) ⇒ Object
- #next_turn ⇒ Object
- #reset ⇒ Object
- #set_turn_and_clear_grid(turn) ⇒ Object
- #switch_turns ⇒ Object
Instance Attribute Details
#grid ⇒ Object
Returns the value of attribute grid
5 6 7 |
# File 'lib/xo/engine/game_context.rb', line 5 def grid @grid end |
#turn ⇒ Object
Returns the value of attribute turn
5 6 7 |
# File 'lib/xo/engine/game_context.rb', line 5 def turn @turn end |
Instance Method Details
#check_turn(turn) ⇒ Object
24 25 26 |
# File 'lib/xo/engine/game_context.rb', line 24 def check_turn(turn) raise ArgumentError, "invalid turn symbol, #{turn}" unless Grid.is_token?(turn) end |
#next_turn ⇒ Object
20 21 22 |
# File 'lib/xo/engine/game_context.rb', line 20 def next_turn Grid.other_token(turn) end |
#reset ⇒ Object
7 8 9 |
# File 'lib/xo/engine/game_context.rb', line 7 def reset set_turn_and_clear_grid(:nobody) end |
#set_turn_and_clear_grid(turn) ⇒ Object
11 12 13 14 |
# File 'lib/xo/engine/game_context.rb', line 11 def set_turn_and_clear_grid(turn) self.turn = turn grid.clear end |
#switch_turns ⇒ Object
16 17 18 |
# File 'lib/xo/engine/game_context.rb', line 16 def switch_turns self.turn = next_turn end |