Class: Hand
- Inherits:
-
Object
- Object
- Hand
- Defined in:
- lib/99_game.rb
Overview
Creates an object that holds and can play cards. Interacts with Deck objects.
Instance Attribute Summary collapse
-
#hand ⇒ Object
(also: #inspect)
The actual hand.
Instance Method Summary collapse
-
#initialize(deck_in_use) ⇒ Hand
constructor
Creates a new Hand.
-
#play(card) ⇒ Object
Gameplay method.
-
#view ⇒ Object
Allows you to see your cards.
Constructor Details
#initialize(deck_in_use) ⇒ Hand
Creates a new Hand. The deck argument tells the object which deck to use in Hand#play
60 61 62 |
# File 'lib/99_game.rb', line 60 def initialize(deck_in_use) @hand, @deck = [deck_in_use.draw, deck_in_use.draw, deck_in_use.draw], deck_in_use end |
Instance Attribute Details
#hand ⇒ Object Also known as: inspect
The actual hand
58 59 60 |
# File 'lib/99_game.rb', line 58 def hand @hand end |
Instance Method Details
#play(card) ⇒ Object
Gameplay method. The parameter ‘card’ is the card being played.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/99_game.rb', line 64 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 @hand.push @deck.draw @deck.discard discard done = true end i += 1 end end |
#view ⇒ Object
Allows you to see your cards.
82 83 84 85 |
# File 'lib/99_game.rb', line 82 def view print "\tThese are your cards: " @hand.each {|card| print "\t#{card.num}"} end |