Class: Blackjack::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/blackjack/player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Player

Returns a new instance of Player.



4
5
6
7
8
9
# File 'lib/blackjack/player.rb', line 4

def initialize(args)
  @name = args[:name]
  @hand = args[:hand]
  @human = args[:human] || false
  @stand = false
end

Instance Attribute Details

#handObject

Returns the value of attribute hand.



3
4
5
# File 'lib/blackjack/player.rb', line 3

def hand
  @hand
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/blackjack/player.rb', line 3

def name
  @name
end

Instance Method Details

#bust?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/blackjack/player.rb', line 32

def bust?
  hand.bust?
end

#formatted_scoreObject



28
29
30
# File 'lib/blackjack/player.rb', line 28

def formatted_score
  "#{name}'s score: #{score}\n\n"
end

#human?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/blackjack/player.rb', line 16

def human?
  @human
end

#scoreObject



24
25
26
# File 'lib/blackjack/player.rb', line 24

def score
  hand.cards_value
end

#stand!Object



11
12
13
14
# File 'lib/blackjack/player.rb', line 11

def stand!
  @stand = true
  "#{name} stands!\n\n"
end

#stand?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/blackjack/player.rb', line 20

def stand?
  @stand
end

#wants_to_hit?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/blackjack/player.rb', line 36

def wants_to_hit?
  score < 17
end

#wins!Object



40
41
42
# File 'lib/blackjack/player.rb', line 40

def wins!
  "#{name} wins!"
end