Top Level Namespace
Defined Under Namespace
Instance Method Summary collapse
-
#converter(input) ⇒ Object
Converts input to an integer if String#capitalize does something.
-
#not_nil?(obj) ⇒ Boolean
Tests if obj is not nil.
-
#pause(p) ⇒ Object
Combines sleep and a newline.
-
#test(card, actual_value, test_value) ⇒ Object
Used by the CPU to determine which card to play.
Instance Method Details
#converter(input) ⇒ Object
Converts input to an integer if String#capitalize does something. If parameter input is an abbreviation, input is converted to what it stands for. Otherwise, it simply returns a capitalized version of input. If input is nil or an emtpy string, raises a CardError
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/99_game.rb', line 22 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 == 0 case input.capitalize when "$" then "Joker" when "K" then "King" when "J" then "Jack" when "Q" then "Queen" when "A" then "Ace" end else input.to_i end end |
#not_nil?(obj) ⇒ Boolean
Tests if obj is not nil.
14 15 16 17 18 19 20 |
# File 'lib/99_game.rb', line 14 def not_nil?(obj) if obj.nil? return false else return true end end |
#pause(p) ⇒ Object
Combines sleep and a newline. āpā is the amount of time waited.
89 90 91 92 |
# File 'lib/99_game.rb', line 89 def pause(p) sleep p puts end |
#test(card, actual_value, test_value) ⇒ Object
Used by the CPU to determine which card to play. Parameter card needs to be an instance of Card.
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/99_game.rb', line 3 def test(card, actual_value, test_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 |