-
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
Emilce & Maria - Octos - C9 #22
base: master
Are you sure you want to change the base?
Conversation
…nt for storing the incorrect guesses in an array
Word-Guess GameWhat We're Looking For
This is a good start, but it feels like there's quite a lot of work still to be done here. The core functionality of the game (guess letters in a loop) is there, but there's no artwork, no way to loose, and much of the user interaction still feels very unpolished. I've left a number of inline comments below, which you should spend time reviewing. Feel free to reach out with questions about them, or if you want to talk through the project. One impression that I get is that you had trouble getting started, and ended up running out of time. This is a common pattern with novice programmers: when confronted with an empty file, they freeze up and don't know where to start. One way to practice this is through the Benjamin Franklin method, where you take an existing resource (say a ruby file I wrote in lecture, like |
attr_accessor :art | ||
|
||
def initialize | ||
@art = art |
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.
Here you have an instance variable @art
, but I don't see that it's ever used. You're also setting a value for it, but your constructor does not take a art
parameter.
# randomly grabbing a word from body_parts array | ||
random_word = words.sample | ||
|
||
end |
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.
You should have an explicit return here:
return random_word
|
||
def initialize | ||
@word = selection_of_word | ||
@replaced_underscore = create_underscore_array |
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 like that you split initialization out into small, manageable methods.
class Word | ||
attr_accessor :guess_letter | ||
attr_reader :selection_of_word, :create_underscore_array | ||
|
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.
The attr_reader
s you've made on line 33 are both for methods. attr_readers
give access to instance variables, for methods they don't make any sense.
|
||
if letter_of_random_word != guess | ||
incorrect_guesses << guess | ||
end |
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'm not sure this if
statement makes sense here. At this point letter_of_random_word
should point to the last letter in the word that's being guessed, so checking whether that is what the user guessed isn't very meaningful.
If you do need to track incorrect guesses separately, you would need a separate boolean variable, maybe called correct_guess
, that is set to false
before you loop through the letters in the word, and updated to true if the letter ever matches.
end | ||
end | ||
|
||
@guesses_available -= 1 |
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.
You decrease the number of guesses available even if the guess was correct.
# COMPARE user guess to the split array | ||
word_characters.each_index do |index| | ||
# putting the current index equal to letter so we can use a conditional | ||
letter_of_random_word = word_characters[index] |
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 would be a good thing to pull into its own instance method. The signature might look like:
def check_guess(letter)
end | ||
|
||
puts "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's no way to loose this game!
|
||
def guess_letter | ||
art = Art.new | ||
# breaking up the word into separate letters so we can loop thru them |
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.
Calling this method guess_letter
is a little misleading - this method plays the entire game, top to bottom. Realizing when your method is getting away from you and becoming bigger than you intended is an important skill to practice.
One way to combat this tendency is to plan out how your code will be called before you start writing the class. You might start by building a driver loop down below:
game = Word.new
while !game.is_over?
game.print_state
puts "Letter please"
letter = gets.chomp
game.guess_letter(letter)
end
This can serve as a sort of road map, limiting how big your methods need to be and keeping you on the right track.
end | ||
|
||
class Word | ||
attr_accessor :guess_letter |
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 is another place where the name of the class, Word
, indicates it will be responsible for some small piece of functionality, but instead you've ended up throwing the whole game in here. You should either rename the class to something like Game
, or move functionality out.
Knowing what your classes and methods are not responsible for is just as important as knowing what they are supposed to do.
Word Guess
Congratulations! You're submitting your assignment.
Comprehension Questions