Class: Hand

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

Overview

The gameplay happens here. Holds four cards and interacts with $deck.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHand

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

#handObject (readonly)

The player’s actual hand



39
40
41
# File 'lib/ninety_eight.rb', line 39

def hand
  @hand
end

Instance Method Details

#listObject

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

Raises:



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