Class: Hand
- Inherits:
-
Object
- Object
- Hand
- Defined in:
- lib/ninety_eight.rb
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.
- #list ⇒ Object
- #play(card) ⇒ Object
Constructor Details
#initialize ⇒ Hand
Returns a new instance of Hand.
24 25 26 27 28 |
# File 'lib/ninety_eight.rb', line 24 def initialize $deck.shuffle! @hand = [$deck.shift, $deck.shift, $deck.shift, $deck.shift] $deck.shuffle! end |
Instance Attribute Details
#hand ⇒ Object (readonly)
Returns the value of attribute hand.
23 24 25 |
# File 'lib/ninety_eight.rb', line 23 def hand @hand end |
Instance Method Details
#list ⇒ Object
29 |
# File 'lib/ninety_eight.rb', line 29 def list; @hand.each {|card| print "\t#{card.num}"}; end |
#play(card) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ninety_eight.rb', line 30 def play(card) $legal, i, done = false, 0, false for cards in @hand if cards.num == card.num and done == false done = true $legal = true $deck.shuffle! draw = $deck.shift discard = @hand[i] @hand.delete_at(i) $deck.push(discard) $deck.shuffle! @hand.push(draw) end i += 1 end raise CardError, "\aCard not Allowed\a" unless $legal if card.num == "King"; $value = 98 else; $value += card.value end end |