Class: Hand
- Inherits:
-
Object
- Object
- Hand
- Defined in:
- lib/99_game.rb
Overview
Creates an object that holds and can play cards
Instance Attribute Summary collapse
-
#hand ⇒ Object
readonly
Returns the value of attribute hand.
Instance Method Summary collapse
-
#initialize ⇒ Hand
constructor
Creates a new Hand.
-
#play(card) ⇒ Object
Gameplay method.
-
#view ⇒ Object
Allows you to see your cards.
Constructor Details
#initialize ⇒ Hand
Creates a new Hand
52 |
# File 'lib/99_game.rb', line 52 def initialize; @hand = [$deck.shift, $deck.shift, $deck.shift]; end |
Instance Attribute Details
#hand ⇒ Object (readonly)
Returns the value of attribute hand.
50 51 52 |
# File 'lib/99_game.rb', line 50 def hand @hand end |
Instance Method Details
#play(card) ⇒ Object
Gameplay method
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/99_game.rb', line 54 def play(card) if card.num == "King"; $value = 99 elsif card.num == "Joker"; $value = 0 else; $value += card.value end i, done = 0, false for index in @hand if index.num == card.num and not done discard = @hand[i] @hand.delete_at(i) draw = $deck.shift @hand.push(draw) $deck.push(discard) done = true end i += 1 end end |
#view ⇒ Object
Allows you to see your cards.
73 74 75 76 |
# File 'lib/99_game.rb', line 73 def view print "\tThese are your cards: " @hand.each {|card| print "\t#{card.num}"} end |