Class: RpgTools::PlayingCardDeck

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ PlayingCardDeck

Returns a new instance of PlayingCardDeck.



5
6
7
8
9
10
# File 'lib/rpg_tools/playing_card_deck.rb', line 5

def initialize(type)
  @type = type
  type_check
  @card_picks = 0
  @value = nil
end

Instance Attribute Details

#card_picksObject

Returns the value of attribute card_picks.



3
4
5
# File 'lib/rpg_tools/playing_card_deck.rb', line 3

def card_picks
  @card_picks
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/rpg_tools/playing_card_deck.rb', line 3

def type
  @type
end

#valueObject

Returns the value of attribute value.



3
4
5
# File 'lib/rpg_tools/playing_card_deck.rb', line 3

def value
  @value
end

Instance Method Details

#cardObject



12
13
14
15
16
17
18
19
20
21
# File 'lib/rpg_tools/playing_card_deck.rb', line 12

def card
  @card_picks += 1

  @value =
    if @type == 52
      joker_picked? ? 'Joker' : standard_card
    else
      standard_card
    end
end

#handObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rpg_tools/playing_card_deck.rb', line 23

def hand
  [].tap do |hand|
    until hand.count == 5
      card = standard_card

      unless hand.include?(card) || hand.count('Joker') == 2
        hand << card
        @card_picks += 1
      end
    end
  end
end