Class: Blackjack::Dealer
Instance Attribute Summary
Attributes inherited from Player
#amount, #cards, #finished, #game, #position, #splitted
Instance Method Summary
collapse
Methods inherited from Player
#blackjack?, #busted?, #can_hit?, #double!, #enough_balance_available?, #finished?, #his_turn?, #hit!, #playing?, #points, #possible_actions, #previous_players, #result, #split!, #splitted?, #splitted_aces?, #stand!, #status, #take_card!, #won_with_blackjack?
Constructor Details
#initialize(game, options = {}) ⇒ Dealer
Returns a new instance of Dealer.
3
4
5
6
7
8
|
# File 'lib/blackjack/dealer.rb', line 3
def initialize(game, options={})
self.game = game
self.cards = []
self.finished = false
self.splitted = options.fetch(:splitted, false)
end
|
Instance Method Details
#can_double? ⇒ Boolean
20
21
22
|
# File 'lib/blackjack/dealer.rb', line 20
def can_double?
false
end
|
#can_play? ⇒ Boolean
32
33
34
|
# File 'lib/blackjack/dealer.rb', line 32
def can_play?
game.players.all?(&:finished?)
end
|
#can_split? ⇒ Boolean
16
17
18
|
# File 'lib/blackjack/dealer.rb', line 16
def can_split?
false
end
|
#can_stand? ⇒ Boolean
24
25
26
|
# File 'lib/blackjack/dealer.rb', line 24
def can_stand?
false
end
|
#finish! ⇒ Object
36
37
38
39
|
# File 'lib/blackjack/dealer.rb', line 36
def finish!
super
game.finish!
end
|
#inspect ⇒ Object
11
12
13
|
# File 'lib/blackjack/dealer.rb', line 11
def inspect
"<Dealer# (#{finished? ? points: "?"}): #{cards.collect(&:inspect).join(" ")} >"
end
|
#must_hit? ⇒ Boolean
28
29
30
|
# File 'lib/blackjack/dealer.rb', line 28
def must_hit?
points < 17 || (points == 17 && cards.one?(&:ace?))
end
|
#play! ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/blackjack/dealer.rb', line 41
def play!
raise "players haven't finished" unless can_play?
while(must_hit?) do
self.cards << game.deck.draw
if blackjack? || points==21 || busted?
return finish!
end
end
finish!
true
end
|