Class: Hand
- Inherits:
-
Object
- Object
- Hand
- Defined in:
- lib/99_game.rb
Overview
Creates a 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
A new instance of Hand.
- #play(card) ⇒ Object
- #view ⇒ Object
Constructor Details
#initialize ⇒ Hand
Returns a new instance of Hand.
36 |
# File 'lib/99_game.rb', line 36 def initialize; @hand = [$deck.shift, $deck.shift, $deck.shift]; end |
Instance Attribute Details
#hand ⇒ Object (readonly)
Returns the value of attribute hand.
35 36 37 |
# File 'lib/99_game.rb', line 35 def hand @hand end |
Instance Method Details
#play(card) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/99_game.rb', line 37 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
55 56 57 58 |
# File 'lib/99_game.rb', line 55 def view print "\tThese are your cards: " @hand.each {|card| print "\t#{card.num}"} end |