Skip to content

Instantly share code, notes, and snippets.

@justuseapen
Created November 19, 2013 16:30
Show Gist options
  • Save justuseapen/7548162 to your computer and use it in GitHub Desktop.
Save justuseapen/7548162 to your computer and use it in GitHub Desktop.
word_bank = ["Array", "Hash", "Ruby", "Rails", "Framework", "Werewolf", "Mafia", "Koans", "Launch", "Class", "Object", "Database", "Schema", "Spock", "Method", "Constant", "Higgs-Boson", "Regulatory Capture", "git", "Gist", "Github", "Gem", "Directory", "Binary", "Backchannel", "Socket", "Bootstrap", "Javascript", "CSS", "HTML", "Markdown", "initialize", "attribute", "Airplay", "User Story", "Acceptance Criteria", "Batman", "Java", "Language", "Mirepoix", "Perl", "Python", "Recursive Loop",]
secret_word = word_bank[rand(word_bank.length)]
secret_word = secret_word.downcase
blanked_word = ""
array_word = secret_word.each_char.to_a
array_word.each do |char|
if char == " "
blanked_word << " "
else
blanked_word << "-"
end
end
puts blanked_word
blanked_word_array = blanked_word.split""
array_word = secret_word.split ""
chances = 8
while chances > 0 do
puts "Please guess a letter or the word"
puts "You have #{chances} chance(s) remaining."
guess = gets.chomp
if guess.length == 1
if array_word.include?(guess)
array_word.each_with_index do |letter, index|
if guess == letter
blanked_word_array[index] = guess
puts blanked_word_array.join""
if blanked_word_array.join == secret_word
puts "You win! BAHNG!"
abort
end
end
end
else
puts "That letter is not present!"
chances -= 1
puts blanked_word_array.join""
end
else
if guess == secret_word
puts "Congrats! You win!"
break
else
"You're wrong! You suck!"
chances -= 1
puts blanked_word_array.join""
end
end
end
if chances == 0
puts "You're out of chances. You lose and suck."
puts "The word was #{secret_word}, loser."
end
#Select a word
#Blank the word, display the blanked word
#request guess
#if guess is letter, check for letter in word
#if letter is present, replace respective blank with
#guessed letter
#if guess is word, compare guess to secret word
#if incorrect, let em know!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment