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

Word Guess - Octos - Jamila & Angelica #10

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

Conversation

amcejamorales
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? We shared driver and navigator roles well and were flexible about switching.
For each partner what parts of the project did you find challenging? Jamila: I found refactoring and logic to update where the letter should go challenging. Angelica: I found using classes within each other challenging.
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? We created a method called print_heart inside of an Image class which uses an instance variable representing the number of remaining attempts a user has to print parts of a heart. The method takes no input, but rather uses an instance variable to determine the number of times to run a "times" loop. It outputs an image with parts of a heart, which represent the user's remaining attempts.
Describe an instance where you used a local variable instead of an instance variable. Why did you make that choice? In the print_heart method we used a local variable called "loser_img" to print parts of a heart corresponding to the user's remaining attempts. This did not need to be an instance variable because it didn't need to be used outside of the print_heart method.
What code, if any, did you feel like you were duplicating more than necessary? We repeatedly use our instance variables and wonder if we could have been more concise.
Is there a specific piece of code you'd like feedback on? How could we have gotten the functionality of lines 88 - 110 using classes?

@droberts-sea
Copy link

Word-Guess Game

What We're Looking For

Feature Feedback
Baseline
Regular Commits with meaningful commit messages. Your commit messages are good, but I would like to see more frequent commits.
Readable code with consistent indentation. yes
Answered comprehension questions yes
Product Functionalities
Created a Class to encapsulate game functionality. yes
Used methods to DRY up your code. yes
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

Great work overall! I've left some nitpicks down below for you to review, but in general this code is clean and easy to read, and I am quite happy with this submission. Keep up the hard work!

attr_writer :num_attempts
def initialize
@num_attempts = 5
@heart_parts = [" ,d88b.d88b, ", " 88888888888 ", " `Y8888888Y' ", " `Y888Y' ", " `Y' "]

Choose a reason for hiding this comment

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

This line is a little hard to understand as is - you could make it more readable by moving things around:

@heart_parts = [
  "  ,d88b.d88b,  ",
  "  88888888888  ",
  "  `Y8888888Y'  ",
  "    `Y888Y'    ",
  "      `Y'      "
]


case user_choice
when "yes","y"
play_game

Choose a reason for hiding this comment

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

Here play_game calls play_again which in turn calls play_game, creating a kind of loop. 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. Re-writing this code with a while loop might look like:

def play_game
  user_choice = 'y'
  while ['yes', 'y'].include?(user_choice)
    game = Game.new
    game.round
    puts "Would you like to play again?"
    user_choice = gets.chomp.downcase
  end
  puts "Goodbye!"
end

def round
# get word length
# loop through word length and puts "_" that many times
while @attempts != 0 && @word_split != @word_in_progress

Choose a reason for hiding this comment

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

This method feels a little long to me. Could you break it up into several smaller methods? For example, you might make one that gets a letter from the user and validates it, and another to update the game state based on the user's guess.

# allows user to play multiple times
def play_game
game = Game.new
puts game.round

Choose a reason for hiding this comment

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

Regarding your question, I don't think this code does need to be inside of a class. To me it feels well-organized as is.

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