Top Level Namespace

Defined Under Namespace

Classes: CardError, Hand

Instance Method Summary collapse

Instance Method Details

#card_test(card, actual_value) ⇒ Integer

Note:

Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.

Parameters:

Returns:

  • (Integer)


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/99_game.rb', line 10

def card_test(card, actual_value)
   	if card.num == "King"
			test_value = 99
   	elsif card.num == "Joker"
   		test_value = 0
   	else
   		test_value = actual_value + card.value
	end
	test_value = -100 if test_value > 99
		return test_value
end

#converter(input) ⇒ String, Integer

If parameter input is an abbreviation, input is converted to what it stands for. Otherwise, it simply returns a capitalized version of input.

Parameters:

  • input (String)

Returns:

  • (String, Integer)

Raises:

  • (CardError)

    if input is nil or an emtpy string



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/99_game.rb', line 44

def converter(input)
	abbrev = {"$" => "Joker", "K" => "King", "J" => "Jack", "Q" => "Queen", "A" => "Ace"}
	raise(CardError, "Input cannot be blank") if input == String.new
	if input.to_i.zero?
		case input.capitalize
			when ?$, "Joker" then "Joker"
			when ?K, "King" then "King"
			when ?J, "Jack" then "Jack"
			when ?Q, "Queen" then "Queen"
			when ?A, "Ace" then "Ace"
		end
	else
		input.to_i
	end
end

#not_nil?(obj) ⇒ Boolean

Tests if obj is not nil.

Returns:

  • (Boolean)


22
23
24
# File 'lib/99_game.rb', line 22

def not_nil?(obj)
	!obj.nil?
end

#pause(p) ⇒ void

This method returns an undefined value.

Combines sleep and a newline

Parameters:

  • p (Integer)

    amount of time to sleep



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

def pause(p)
    	sleep p
    	puts
end