Class: Shithead::Deck

Inherits:
Object
  • Object
show all
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

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_countObject



20
21
22
# File 'lib/shithead/deck.rb', line 20

def card_count
  cards.length
end

#drawObject



24
25
26
# File 'lib/shithead/deck.rb', line 24

def draw
  cards.shift
end

#empty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/shithead/deck.rb', line 28

def empty?
  cards.empty?
end