-
Notifications
You must be signed in to change notification settings - Fork 9
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
base: master
Are you sure you want to change the base?
Conversation
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.
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 |
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.
seems like self.hit
is already in Boolean data type, you can simply return self.hit
|
||
if not self.miss: | ||
return False | ||
|
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.
similar as above.. you don't need line 24 - 28..
raise InvalidWordException | ||
else: | ||
self.masked = len(word_to_guess)*"*" | ||
|
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.
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] | ||
|
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.
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)) |
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.
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.
No description provided.