Class: Table

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

Overview

A Table is where players come to play a game (possibly as part of a match as part of a tournament if required) Essentially a Table is a Game Controller

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game, players) ⇒ Table

Returns a new instance of Table.



7
8
9
10
# File 'lib/table.rb', line 7

def initialize game, players
  @game = game
  @players = players
end

Instance Attribute Details

#gamesObject (readonly)

Returns the value of attribute games.



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

def games
  @games
end

#playersObject (readonly)

Returns the value of attribute players.



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

def players
  @players
end

#quietObject

Returns the value of attribute quiet.



5
6
7
# File 'lib/table.rb', line 5

def quiet
  @quiet
end

Instance Method Details

#play_gameObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/table.rb', line 12

def play_game
  until @game.won? || @game.drawn?
    next_player = @players[@game.next_player]
    move = next_player.get_move @game.current_position, @game.move_list
    unless @quiet
      p "player #{@game.next_player} plays move #{move }"
    end
    @game.play_move @game.next_player, move
  end
end