Class: Hand

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

Overview

Creates an object that holds and can play cards. Interacts with Deck objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deck_in_use) ⇒ Hand

Creates a new Hand. The deck argument tells the object which deck to use in Hand#play



60
61
62
# File 'lib/99_game.rb', line 60

def initialize(deck_in_use)
	@hand, @deck = [deck_in_use.draw, deck_in_use.draw, deck_in_use.draw], deck_in_use
end

Instance Attribute Details

#handObject Also known as: inspect

The actual hand



58
59
60
# File 'lib/99_game.rb', line 58

def hand
  @hand
end

Instance Method Details

#play(card) ⇒ Object

Gameplay method. The parameter ‘card’ is the card being played.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/99_game.rb', line 64

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
			@hand.push @deck.draw
			@deck.discard discard
			done = true
		end
		i += 1
	end
end

#viewObject

Allows you to see your cards.



82
83
84
85
# File 'lib/99_game.rb', line 82

def view
		print "\tThese are your cards: "
   	@hand.each {|card| print "\t#{card.num}"}
end