Class: GameState
- Inherits:
-
Object
- Object
- GameState
- Defined in:
- lib/game_state.rb
Instance Attribute Summary collapse
-
#active_player ⇒ Object
Returns the value of attribute active_player.
-
#board ⇒ Object
Returns the value of attribute board.
Instance Method Summary collapse
- #active_player_class ⇒ Object
- #check_win ⇒ Object
-
#initialize(board = Board.new, active_player) ⇒ GameState
constructor
A new instance of GameState.
- #perform_move(move) ⇒ Object
- #update(move) ⇒ Object
Constructor Details
#initialize(board = Board.new, active_player) ⇒ GameState
Returns a new instance of GameState.
4 5 6 7 |
# File 'lib/game_state.rb', line 4 def initialize(board=Board.new, active_player) @board = board @active_player = active_player end |
Instance Attribute Details
#active_player ⇒ Object
Returns the value of attribute active_player.
2 3 4 |
# File 'lib/game_state.rb', line 2 def active_player @active_player end |
#board ⇒ Object
Returns the value of attribute board.
2 3 4 |
# File 'lib/game_state.rb', line 2 def board @board end |
Instance Method Details
#active_player_class ⇒ Object
21 22 23 |
# File 'lib/game_state.rb', line 21 def active_player_class @active_player.class.inspect end |
#check_win ⇒ Object
17 18 19 |
# File 'lib/game_state.rb', line 17 def check_win @board.calculate_win end |
#perform_move(move) ⇒ Object
9 10 11 |
# File 'lib/game_state.rb', line 9 def perform_move(move) @active_player.perform_move(self, move) end |
#update(move) ⇒ Object
13 14 15 |
# File 'lib/game_state.rb', line 13 def update(move) return @board.add_piece(@active_player.token, move) end |