Class: Match

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

Instance Method Summary collapse

Constructor Details

#initialize(players, first_to, game) ⇒ Match

Returns a new instance of Match.



7
8
9
10
11
12
13
14
15
# File 'lib/match.rb', line 7

def initialize players, first_to, game
  @game = game
  @players = players
  @first_to = first_to
  @player_wins = {}
  players.each do |player|
    @player_wins[player.id] = 0
  end
end

Instance Method Details

#playObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/match.rb', line 17

def play
 while leading_player[1] < @first_to 
  game = @game.class.new
  table = Table.new game, @players
  table.play_game
  if game.winner
    @player_wins[@players[game.winner].id] += 2
    p "#{game.winner} won that game and has #{ @player_wins[@players[game.winner].id] } wins"
    p "leading player is #{leading_player[0]} with #{leading_player[1]} wins"
  elsif game.drawn?
    @players.each do |player|
      @player_wins[player.id] += 1
    end
  end
  gets
 end
end

#resultObject



35
36
# File 'lib/match.rb', line 35

def result
end