Skip to content
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

Finished Word-Guess Game.--by Erika & Ari #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

arrriiii
Copy link

Word Guess

Congratulations! You're submitting your assignment.

Comprehension Questions

Feature Feedback
How do you feel you and your partner did in sharing responsibilities? Initially, we didn't delegate responsibilities which made the process difficult but then when we started to talk out loud "rubberducking" it became easier to complete.
For each partner what parts of the project did you find challenging? Erika- The parts I found most challenging were grasping the concept of classes and what go in them. It makes talking through it much more difficult. Ari- Because I didn't fully understand the concepts, it made it challenging to outline the steps to our program.
Describe an instance where you used a method for something to encapsulate the functionality within your class. What does it do? What are its inputs and outputs? Our promptUser method allowed us to distinguish the users responds to our conditions -- and could be called after every condition.
Describe an instance where you used a local variable instead of an instance variable. Why did you make that choice? We have the local variable 'level' instead of an instance variable because we wanted to determine the difficulty of the Game class--
What code, if any, did you feel like you were duplicating more than necessary? Our pedal_remove method could have be consolidated with possible another method to remove petals-- instead of manually printing the flower design.
Is there a specific piece of code you'd like feedback on? line 96-- we would like to know if there is an alternative format as our code can be confusing.

Fixed loop on level option
missing color code--
Removed extra instance variable @correct_word
@droberts-sea
Copy link

Word-Guess Game

What We're Looking For

Feature Feedback
Baseline
Regular Commits with meaningful commit messages. N/A - looks like you used the old way of copy/paste code into GitHub instead of git push, so I cannot see your commit history
Readable code with consistent indentation. your indentation could use some work, but variable names are descriptive and the flow is understandable
Answered comprehension questions yes
Product Functionalities
Created a Class to encapsulate game functionality. yes
Used methods to DRY up your code. yes - would like to see a little more division of responsibility - see inline
Created instance variables & local variables where appropriate. yes
Used Arrays to store lists of letters guessed. yes
Used variables & random numbers to allow the game to function with multiple words, no hard-coded answers. yes
Programmed "defensively" to detect errors in user input. yes - good work

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!


# make sure to not use the same word twice in game
def dont_repeat(array)
array.delete_at(rand(array.length))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Watch your indentation here

_\|/_
|_____|
| |
|___|'''.red]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect this is where your indentation gets messed up - Atom will want you to end the array on a new line.

             |___|'''.red
    ]
  end

# let the user know if they can't have more than one letter
if (guess.length > 1)
puts "\nYOU HAVE TO GUESS ONE LETTER AT A TIME.".red
return promptUser

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This portion, between lines 75 and 91, might be good to break out as a separate method, something like validate_guess.

if (@correct_word_array.include?(guess)) #from index [0] to last index of word
0.upto(@correct_word_array.length-1) { |index|
if (@correct_word_array[index] == guess)
@correct_guess[index] = guess

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use do...end for loops, rather than curly braces.


def promptUser
unless (@correct_guess.include?("_") )
puts "\nYOU WIN! THE WORD WAS: #{@correct_word_array.join("")}".green

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruby methods should be named using snake_case, so this one would be prompt_user.

end
}
puts "SECERT WORD: #{@correct_guess.join(' ')}"
promptUser # return to the prompt method to guess another letter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, promptUser calls itself, creating a sort of loop. A method calling itself is 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.

puts "SECERT WORD: #{@correct_guess.join(' ')}"
promptUser # return to the prompt method to guess another letter
pedal_remove # remove petals from the picture
else

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this call to pedal_remove is actually doing anything.

# if the users letter is in the word
if (@correct_word_array.include?(guess)) #from index [0] to last index of word
0.upto(@correct_word_array.length-1) { |index|
if (@correct_word_array[index] == guess)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this logic is a little dense. One observation is that we don't need the check on line 96, because if the correct word does not include the guess, then the if statement on line 98 will never go off.

We could simplify the whole section by rewriting it as:

letter_found = false
@correct_word_array.each_with_index do |letter, index|
  if letter == guess
    @correct_guess[index] = guess
    letter_found = true
  end
end

if letter_found
  puts "SECERT WORD: #{@correct_guess.join('  ')}"
  promptUser # return to the prompt method to guess another letter
else
  # ... the rest of this method, starting on line 105 ...
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants