Class: Match
- Inherits:
-
Object
- Object
- Match
- Defined in:
- lib/match.rb
Instance Method Summary collapse
-
#initialize(players, first_to, game) ⇒ Match
constructor
A new instance of Match.
- #play ⇒ Object
- #result ⇒ Object
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
#play ⇒ Object
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 |
#result ⇒ Object
35 36 |
# File 'lib/match.rb', line 35 def result end |