Class: Shithead::Deck
- Inherits:
-
Object
- Object
- Shithead::Deck
- Defined in:
- lib/shithead/deck.rb
Constant Summary collapse
- SUITES =
%w[ Clubs Diamonds Hearts Spades ].freeze
- VALUES =
%w[ A 2 3 4 5 6 7 8 9 10 J Q K ].freeze
- PLAYERS_PER_DECK_RATIO =
3.5
Instance Method Summary collapse
- #card_count ⇒ Object
- #draw ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(player_count = 1) ⇒ Deck
constructor
A new instance of Deck.
Constructor Details
#initialize(player_count = 1) ⇒ Deck
Returns a new instance of Deck.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/shithead/deck.rb', line 6 def initialize(player_count = 1) @cards = [] (player_count / PLAYERS_PER_DECK_RATIO).ceil.times do SUITES.each do |suite| VALUES.each do |value| @cards << Shithead::Card.new(suite, value) end end end @cards.shuffle! end |
Instance Method Details
#card_count ⇒ Object
20 21 22 |
# File 'lib/shithead/deck.rb', line 20 def card_count cards.length end |
#draw ⇒ Object
24 25 26 |
# File 'lib/shithead/deck.rb', line 24 def draw cards.shift end |
#empty? ⇒ Boolean
28 29 30 |
# File 'lib/shithead/deck.rb', line 28 def empty? cards.empty? end |