Class: Hand

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

Overview

Creates a object that holds and can play cards

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHand

Returns a new instance of Hand.



33
# File 'lib/99_game.rb', line 33

def initialize; @hand = [$deck.shift, $deck.shift, $deck.shift]; end

Instance Attribute Details

#handObject (readonly)

Returns the value of attribute hand.



32
33
34
# File 'lib/99_game.rb', line 32

def hand
  @hand
end

Instance Method Details

#play(card) ⇒ Object

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/99_game.rb', line 34

def play(card)
	legal = false
	for cards in @hand; legal = true if cards.num == card.num; end
	raise CardError, "\aCard not allowed\a" unless legal
	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



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