Created
February 21, 2014 20:41
-
-
Save laurenkruczyk/9143029 to your computer and use it in GitHub Desktop.
Hangman Challenge (To Be Completed)
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
#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