Class: Game

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

Overview

require ‘board’

Direct Known Subclasses

ConsoleGame, RailsGame

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGame

Returns a new instance of Game.



6
7
8
# File 'lib/game.rb', line 6

def initialize
  @players = {:one => nil, :two => nil}
end

Instance Attribute Details

#game_stateObject

Returns the value of attribute game_state.



4
5
6
# File 'lib/game.rb', line 4

def game_state
  @game_state
end

#playersObject

Returns the value of attribute players.



4
5
6
# File 'lib/game.rb', line 4

def players
  @players
end

Instance Method Details

#active_player_classObject



22
23
24
# File 'lib/game.rb', line 22

def active_player_class
  @game_state.active_player_class
end

#check_winObject



18
19
20
# File 'lib/game.rb', line 18

def check_win
  @game_state.check_win
end

#switch_active_playerObject



10
11
12
13
14
15
16
# File 'lib/game.rb', line 10

def switch_active_player
  if @game_state.active_player == @players[:one]
    @game_state.active_player = @players[:two]
  elsif @game_state.active_player == @players[:two]
    @game_state.active_player = @players[:one]
  end
end