Hey! Well done for getting to the final step of the hangman project.
Now in step five,
we're going to complete the project by improving the user experience of our
game. Pretty much up until now, we've already got the game functioning,
but we were working with just three words, right? Ardvark, baboon,
and camel. And at some point,
the game gets pretty tiring when you're only guessing these three words.
And in fact,
the words were chosen so that if you see seven characters and you know
it's ardvark,
six is baboon, five is camel to make it easier for you to debug the code as
you're creating it. And very often when we're writing code, it really,
really important to help yourself when you're creating the code.
And only once you've got all the logic down and everything's working as expected
then to actually add the full functionality.
So inside this step five starting code,
if you take a look at the files over here, you'll notice two extra files.
One is hangman_art.py,
and here I've moved the hangman stages and all the drawings as well as a logo in
ASCII art. So when we actually launch our game this time,
then we're going to get the high man logo printed out like this at the beginning
of the game.
Now the second file here it is hangman_words.py.
And this word list now expands on what we had before.
And it's now a huge list of words, sorted alphabetically
which we're going to draw upon and replace this previous very simple word list.
The first to-do is to update the word list
to use the one from here instead of this one.
So deleting this line and replacing it with that. And to do this,
you might have to look up on previous lessons where
we talked about how to use modules in Python and how to import different files.
Now, if you get stuck on how to do that,
take a look inside the course resources
and there's hints that take you towards documentation on how to do this.
Now, once you've tackled to-do number one, scroll all the way down to find
to-do number two, where we're going to import the stages from hangman_art.py
and this is the same thing using modules and import. To-do
number three is to import the logo.
So one, two, three are all to do with modules and import.
And then once you get to to-do number four,
we're basically going to improve the user experience to let the user know that
they've entered a letter that they've already guessed before.
And when that happens, we're going to print the letter and just let them know.
You don't have to punish them and
you don't have to take away a life and you don't have to restart the game.
It's just the gentle nudge and let them know that they've really guessed that
letter. Now on to-do number five and the final to-do, we're going to let the user
know if the letter that they guessed is not in the chosen word.
So in this case,
we're going print out the letter that they guessed and let them know that it's
not in the word,
just a little bit of feedback to make the game a little bit easier on the user.
So once you've done all of that,
then you should end up with a game that's like this. So,
because there's so many words, I think it's really,
really important that you actually have this line of testing code to tell you
what the solution actually is
so you can test all parts of your game because you know what the word actually
should be. So let's guess a letter that's not in that word.
Let's try a, and you can see the game tells us "You guessed the letter a,
that's not in the word. You lose a life."
And we end up with the head already drawn in the hangman.
So now let's guess a different letter. Let's guess a t.
Then you can see that works as expected. But what if we try guessing T again?
Well, then it tells us you've already guessed t and it shows us the blanks
including the t. Now if they guess a letter
that's actually not in the word, so say a, well, in this case,
they're gonna lose a life because it's actually not in the word and we're going
to take away a life.
So have a play around with the end version of the game. And as always,
all the links are in the course resources. And once you're ready,
then go ahead and fork the starting file and give this a go.