Class: Hand

Inherits:
Object
  • Object
show all
Defined in:
lib/99_game.rb

Overview

Creates an object that holds and can play cards

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHand

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

#handObject (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

#viewObject

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