Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 85 lines (65 sloc) 1.382 kb
4e52863 @eladmeidar Initial commit\
authored
1 class Game
2
3 def initialize(decks_count = 2, jokers_count = 2)
4 @players = []
5 @last_winner = nil
6 @deck = CardDeck.new
7 @used_cards = []
8
9 (decks_count - 1).times {
10 @deck.merge(CardDeck.new)
11 }
12
13 jokers_in_deck = decks_count * 2
14 jokers = @deck.cards.select {|card| card.rank == "Joker"}
15 while jokers_in_deck > jokers_count
16 joker_to_remove = jokers.shuffle.pop
17 @deck.remove_card(joker_to_remove)
18 jokers_in_deck -= 1
19 end
20
21 @deck.shuffle!
22 end
23
24 def add_to_used_cards(card)
25 @used_cards << card
26 end
27
28 def available_card
29 @used_cards.last
30 end
31
32 def pull_available_card
33 @used_cards.pop
34 end
35
36 def add_player(name)
37 max_score = @players.collect(&:score).max || 0
38 @players << Player.new(name)
39 end
40
41 def start
42 if players.count < 2
43 return false
44 else
45 14.times do
46 players.each do |player|
47 player.add_cards(deck, 1)
48 end
49 end
50
51 if @last_winner.nil?
52 @last_winner = players.first
53 end
54
55 @last_winner.add_cards(deck, 1)
56
57 return true
58 end
59
60 end
61
62 def last_winner
63 @last_winner
64 end
65
66 def visible_card
67 unless @last_winner.nil?
68 @last_winner.cards.last.to_s(:human)
69 end
70 end
71
72 def players
73 @players
74 end
75
76 def score_board
77 @players.sort_by {|p| p.score }
78 end
79
80 def deck
81 @deck
82 end
83 end
84
Something went wrong with that request. Please try again.