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

Hangman OOP assignment #2

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

Hangman OOP assignment #2

wants to merge 2 commits into from

Conversation

jescht
Copy link

@jescht jescht commented Jun 26, 2018

No description provided.

Copy link

@cheeyim cheeyim left a comment

Choose a reason for hiding this comment

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

Really nice work done Jessica! The code this time is so much cleaner and you it's so pleasing to the eye to read them .. Great stuff!

return True

if not self.hit:
return False
Copy link

Choose a reason for hiding this comment

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

seems like self.hit is already in Boolean data type, you can simply return self.hit


if not self.miss:
return False

Copy link

Choose a reason for hiding this comment

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

similar as above.. you don't need line 24 - 28..

raise InvalidWordException
else:
self.masked = len(word_to_guess)*"*"

Copy link

Choose a reason for hiding this comment

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

we can consider shifting all exceptions at the top and initialization of variables after that for readability.. so something like :

if not word_to_guess:
   raise InvalidWordException

self.answer = word_to_guess.lower() 
self.masked = len(word_to_guess)*"*"

masked_word += character
else:
masked_word += self.masked[index]

Copy link

Choose a reason for hiding this comment

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

try not to meddle with "index" if you can.. leave it to python for to handle it for you.. for example:

for letter in self.answer:
   if character is letter:
      masked_word += character
   else:
      masked_word += letter

self.remaining_misses = number_of_guesses
self.previous_guesses =[]
# self.word= GuessWord(HangmanGame.select_random_word(self.word_list))
self.word = GuessWord(self.select_random_word(word_list))
Copy link

Choose a reason for hiding this comment

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

since select_random_word(word_list) is a class method, you don't need to use self. Can call it with HangmanGame.select_random_word(word_list) ...

One of the advantage of class method is you do not need an instance to call it.

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