Class: GameState

Inherits:
Object
  • Object
show all
Defined in:
lib/game_state.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_playerObject

Returns the value of attribute active_player.



2
3
4
# File 'lib/game_state.rb', line 2

def active_player
  @active_player
end

#boardObject

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_classObject



21
22
23
# File 'lib/game_state.rb', line 21

def active_player_class
  @active_player.class.inspect
end

#check_winObject



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