Class: Blackjack::Player
- Inherits:
-
Object
- Object
- Blackjack::Player
- Defined in:
- lib/blackjack/player.rb
Instance Attribute Summary collapse
-
#hand ⇒ Object
Returns the value of attribute hand.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
- #bust? ⇒ Boolean
- #formatted_score ⇒ Object
- #human? ⇒ Boolean
-
#initialize(args) ⇒ Player
constructor
A new instance of Player.
- #score ⇒ Object
- #stand! ⇒ Object
- #stand? ⇒ Boolean
- #wants_to_hit? ⇒ Boolean
- #wins! ⇒ Object
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
#hand ⇒ Object
Returns the value of attribute hand.
3 4 5 |
# File 'lib/blackjack/player.rb', line 3 def hand @hand end |
#name ⇒ Object
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
32 33 34 |
# File 'lib/blackjack/player.rb', line 32 def bust? hand.bust? end |
#formatted_score ⇒ Object
28 29 30 |
# File 'lib/blackjack/player.rb', line 28 def formatted_score "#{name}'s score: #{score}\n\n" end |
#human? ⇒ Boolean
16 17 18 |
# File 'lib/blackjack/player.rb', line 16 def human? @human end |
#score ⇒ Object
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
20 21 22 |
# File 'lib/blackjack/player.rb', line 20 def stand? @stand end |
#wants_to_hit? ⇒ 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 |