Class: Hand
- Inherits:
-
Object
- Object
- Hand
- Defined in:
- lib/ninety_eight.rb
Overview
The gameplay happens here. Holds four cards and interacts with $deck.
Instance Attribute Summary collapse
-
#hand ⇒ Object
readonly
The player’s actual hand.
Instance Method Summary collapse
-
#initialize ⇒ Hand
constructor
Creates a new Hand.
-
#list ⇒ Object
Lists the cards in attribute :hand.
-
#play(card) ⇒ Object
Gameplay method.
Constructor Details
#initialize ⇒ Hand
Creates a new Hand. Takes four cards from $deck and shuffles $deck.
40 41 42 43 44 |
# File 'lib/ninety_eight.rb', line 40 def initialize # Creates a new Hand. Takes four cards from $deck and shuffles $deck. $deck.shuffle! @hand = [$deck.shift, $deck.shift, $deck.shift, $deck.shift] $deck.shuffle! end |
Instance Attribute Details
#hand ⇒ Object (readonly)
The player’s actual hand
39 40 41 |
# File 'lib/ninety_eight.rb', line 39 def hand @hand end |
Instance Method Details
#list ⇒ Object
Lists the cards in attribute :hand.
46 |
# File 'lib/ninety_eight.rb', line 46 def list; @hand.each {|card| print "\t#{card.num}"}; end |
#play(card) ⇒ Object
Gameplay method
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/ninety_eight.rb', line 47 def play(card) # Gameplay method $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 << 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 |