Class: DealerHand
- Inherits:
-
Hand
show all
- Defined in:
- lib/blackjack/dealer_hand.rb
Instance Attribute Summary collapse
Attributes inherited from Hand
#cards, #played
Instance Method Summary
collapse
Methods inherited from Hand
#blackjack?, #busted?, #deal_card, #value
Constructor Details
#initialize(blackjack) ⇒ DealerHand
Returns a new instance of DealerHand.
8
9
10
11
|
# File 'lib/blackjack/dealer_hand.rb', line 8
def initialize(blackjack)
super
@hide_first_card = true
end
|
Instance Attribute Details
#blackjack ⇒ Object
Returns the value of attribute blackjack.
6
7
8
|
# File 'lib/blackjack/dealer_hand.rb', line 6
def blackjack
@blackjack
end
|
#hide_first_card ⇒ Object
Returns the value of attribute hide_first_card.
6
7
8
|
# File 'lib/blackjack/dealer_hand.rb', line 6
def hide_first_card
@hide_first_card
end
|
Instance Method Details
#both_values ⇒ Object
34
35
36
|
# File 'lib/blackjack/dealer_hand.rb', line 34
def both_values
[value(:soft, hide_first_card:), value(:hard, hide_first_card:)]
end
|
#deal_required_cards ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/blackjack/dealer_hand.rb', line 26
def deal_required_cards
soft, hard = both_values
while soft < 18 && hard < 17
deal_card
soft, hard = both_values
end
end
|
#draw ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/blackjack/dealer_hand.rb', line 17
def draw
out = String.new(' ')
cards.each_with_index do |card, index|
out << (index.zero? && hide_first_card ? Card.new(blackjack, 13, 0) : card).to_s
out << ' '
end
out << ' ⇒ ' << value(:soft, hide_first_card:).to_s
end
|
#play ⇒ Object
38
39
40
41
42
43
44
|
# File 'lib/blackjack/dealer_hand.rb', line 38
def play
playing = blackjack.need_to_play_dealer_hand?
self.hide_first_card = false if blackjack? || playing
deal_required_cards if playing
self.played = true
blackjack.pay_hands
end
|
#upcard_is_ace? ⇒ Boolean
13
14
15
|
# File 'lib/blackjack/dealer_hand.rb', line 13
def upcard_is_ace?
cards.first.ace?
end
|