Cara Brennan & Anne Watson - Octos - Word Guess#8
Cara Brennan & Anne Watson - Octos - Word Guess#8MississippiBrenn wants to merge 1 commit intoAda-C9:masterfrom
Conversation
Word-Guess GameWhat We're Looking For
Great job overall! There are a couple of places where the structure of this code could be improved (see inline comments below), but in general your code is clean and readable, and I feel you've definitely hit the learning goals for this assignment. Keep up the hard work! |
| end | ||
| print "#{@change_split_word.join}\n" | ||
| if @change_split_word.include?("_") | ||
| user_input |
There was a problem hiding this comment.
Here, user_input calls guess, which calls display_word, which in turn calls user_input again. this is an example of a programming technique called recursion, which you'll learn about in CS Fun in a few months.
Recursion is a powerful tool that can elegantly solve many problems. However, in this case I think a while loop might be a better choice, if only because it makes it immediately obvious to the reader that this code might execute many times. Something like:
def run_game
while @change_split_word.include?("_") && @bad_array.length < 5
user_input
guess
display_anchor
display_word
end
# ... figure out if the user won or lost, and tell them
end| # input | ||
| def user_input | ||
| puts 'Choose a letter please' | ||
| @user_choice = gets.chomp.downcase |
There was a problem hiding this comment.
I don't know that I agree with the decision to make @user_choice an instance variable. This value is transient, since it will change whenever the user makes another guess, and this is usually a good indicator that an instance variable is not the right choice.
Instead, you could store the letter as a local variable, and pass it to guess as a parameter.
| # guess | ||
| def guess | ||
| if @word.include?(@user_choice) | ||
| print "Good guess that letter is in the word!\n" |
There was a problem hiding this comment.
You've done a very good job of functional decomposition here - each function has one clear job, and they're neither too big nor too small.
Word Guess
Congratulations! You're submitting your assignment.
Comprehension Questions