Last active
August 29, 2015 13:57
-
-
Save jmscholen/9906725 to your computer and use it in GitHub Desktop.
Guessing Game HW
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Guessing Game for user to guess the items in the array by Jeff Scholen with user feedback. Iron Yard Rails Engineering 3/31/2014 | |
@n = 0 | |
@atv_values = ["Be Nice.", "Dream Big.", "Pay It Forward.", "Work Hard. Play Hard."] | |
@atv_guess = ["Be ----.", "----- Big.", "Pay It -------.", "Work-------Play Hard."] | |
@atv_hints = ["---- guys finish last.", "I have a -----.", "Kevin Spacey, Haley Joel Osment Movie", | |
"A serious and fun work culture motto." ] | |
@atv_missing_values = ["nice", "dream", "forward", "hard"] | |
def match_answer(user_input) | |
case user_input | |
when "phrase" | |
puts "#{@atv_guess}" | |
when "nice" | |
@atv_guess[0]= ("Be Nice.") | |
puts "#{@atv_guess}" | |
@atv_hints.delete("---- guys finish last.") | |
@atv_missing_values.delete("nice") | |
when "dream" | |
@atv_guess[1]=("Dream Big.") | |
puts "#{@atv_guess}" | |
@atv_hints.delete("I have a -----.") | |
@atv_missing_values.delete("dream") | |
when "forward" | |
@atv_guess[2]=("Pay It Forward.") | |
puts "#{@atv_guess}" | |
@atv_hints.delete("Kevin Spacey, Haley Joel Osment Movie") | |
@atv_missing_values.delete("forward") | |
when "hard" | |
@atv_guess[3]=("Work Hard. Play Hard.") | |
puts "#{@atv_guess}" | |
@atv_hints.delete("A serious and fun work culture motto.") | |
@atv_missing_values.delete("hard") | |
when "hint" | |
give_a_hint(user_input) | |
else | |
puts "I think you need a hint." | |
puts "Please type in hint:" | |
answer = gets.chomp.downcase | |
if @answer == "hint" | |
give_a_hint(@answer) | |
else | |
puts "I REALLY think you need a hint." | |
puts "Please type in hint:(Last Chance!)" | |
@answer = gets.chomp.downcase | |
if @answer == "hint" | |
give_a_hint(@answer) | |
else | |
puts "Bye-Bye." | |
exit | |
end | |
end | |
end | |
end | |
def give_a_hint(answer) | |
# @n = 0 if @n > 3 | |
current_value_of_missing_value = @atv_missing_values[0] | |
while @answer != current_value_of_missing_value | |
puts "#{@atv_hints[0]}" | |
puts "Guess?" | |
#puts "#{@atv_missing_values[0]}" for debugging | |
@answer = gets.chomp.downcase | |
if @answer != current_value_of_missing_value | |
puts "Try again!" | |
length_of_answer = @answer.length | |
missing_value = current_value_of_missing_value | |
length_of_missing_value = missing_value.length | |
if length_of_answer == length_of_missing_value | |
puts "You have the right number of letters!" | |
else | |
puts "You dont have the right number of letters!" | |
end | |
end | |
end | |
match_answer(@answer) | |
# @n += 1 | |
end | |
puts "It's time to start the Phrase GUESSING GAME!" | |
sleep 1 | |
puts "Go ahead and guess a word to see if it works in the phrase." | |
while @atv_guess != @atv_values | |
print "Word?, type 'hint' if you want a hint, type 'phrase' to see where you are:" | |
@answer = gets.chomp.downcase | |
match_answer(@answer) | |
end | |
puts "You guessed the WHOLE phrase correctly!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I left off the good stuff! Sorry about that. I'll look at refactoring it with regard to your comments.