Class: Hand

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHand

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

#handObject (readonly)

Returns the value of attribute hand.



23
24
25
# File 'lib/ninety_eight.rb', line 23

def hand
  @hand
end

Instance Method Details

#listObject



29
# File 'lib/ninety_eight.rb', line 29

def list; @hand.each {|card| print "\t#{card.num}"}; end

#play(card) ⇒ Object

Raises:



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