Skip to content

Instantly share code, notes, and snippets.

@laurenkruczyk
Last active August 29, 2015 13:56
Show Gist options
  • Save laurenkruczyk/9339614 to your computer and use it in GitHub Desktop.
Save laurenkruczyk/9339614 to your computer and use it in GitHub Desktop.
#INCOMPLETE
#TO DO LIST OF THING THAT NEED TO BE MADE
#1- count function
#2 - make it look pretty
#3- make it lose
def update_the_user_facing_word(hidden_word, guess, user_facing_word)
postion_in_the_word_hidden_word = 0
hidden_word.each_char do |letter|
#start loop
if letter == guess
#sub the guess at the position of THIS letter into the user_facing_word
user_facing_word[postion_in_the_word_hidden_word] = guess
end
#End of loop update the position
postion_in_the_word_hidden_word += 1 #
end
user_facing_word
end
#gets the user to guess
def get_guess
puts "Please enter a letter or the word"
gets.chomp
end
#gets the the to guess from wordbank
def get_word
#word bank
#start with 1 word
return "apple"
end
def hangman
hidden_word = get_word()
user_facing_word = "_" * hidden_word.length
#loop to run through the game logic
puts hidden_word
puts user_facing_word
while true
guess = get_guess()
if hidden_word.include?(guess) # check_letter_vs_word()
#1 -NEED TO DEFINE A count FUNCTION FOR THE NUMBER OF OCCURANCES
user_facing_word= update_the_user_facing_word(hidden_word, guess, user_facing_word)
end
puts user_facing_word
end
end
hangman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment