-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dikla and Brenda - Word_Guess - Octos #18
base: master
Are you sure you want to change the base?
Conversation
Word-Guess GameWhat We're Looking For
Good job overall! There's definitely some places where this code could be cleaned up, but in general this is a solid submission that meets the learning goals for this assignment. Let me know about questions on any of my comments below, and keep up the hard work! |
|
||
attempt = 0 | ||
while !levels.include?(level) | ||
if attempt < 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this loop within a loop is more complicated that it needs to be. We could simplify things as follows:
def selection_level
valid_levels = %w(low medium high)
level = nil
attempts = 0
until valid_levels.include?(level) || attempts > 3
puts "Please enter a level: low, medium or high?"
level = gets.chomp.downcase
attempts += 1
end
if valid_levels.include?(level)
if level == "low"
@word_array = @words_low
elsif level == "medium"
@word_array = @words_medium
else
@word_array = @words_high
end
else
puts "Too many attempts..start the program again"
exit
end
end
|
||
# This conditional checks in case the user enters the whole word | ||
if letter.length > 1 | ||
if letter == @word |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments should be indented the same as the rest of your code.
#This loop helps the user to don't be penalized for guessing the same letter more than once. | ||
while @letters_guessed.include? letter do | ||
puts "You have already tried this letter, try another one: " | ||
letter = gets.chomp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to add this loop to the validate_input_letter
function.
end | ||
if @word.split(//) == @letters_correct | ||
you_win | ||
exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are several places in your code where you exit
. This is fine for this assignment, but it means your program is limited to only playing the game once. An interesting exercise is to think about how you would have to change it for the user to be able to play again.
# We did this to don't count inputs as wrong guesses if the user inputs numbers, symbols etc. | ||
def validate_input_letter(input) | ||
until !input.match(/[^a-z]/) | ||
puts "\nPlease return a valid letters from A to Z.\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This loop conditional is a little confusing, since you have three negations: until
(backwards while
), the !
, and the ^
in the regex.
Instead, you might say while input.match(/[^a-z]/)
.
def initialize | ||
@words_low = %w[minnie mickey daisy donald pluto goofy anna elsa alice] | ||
@words_medium = %w[tigger cinderella bambi pocahontas eeyor rabbit mulan belle dumbo] | ||
@words_high = %w[esmeralda quasimodo anastasia mowgli anastasia drizella kocoum maleficent] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These arrays are only used in one place, in selection_level
. That means that making them instance variables might not be appropriate, you could make them local variables in selection_level
instead.
Word Guess
Congratulations! You're submitting your assignment.
Comprehension Questions