All right, guys, so before we get started with our project, it's really important that we're all
on the same page and we understand how the code is going to work because we know how the game works.
So I recommend that if you've never heard of this game, Hangman, then before you continue to just head
over to the Wikipedia article on Hangman.
And it might be even easier if you select your own language, because I know that it has a different
name in different languages.
Now, if you've never played this game, I also recommend just to go and give it a go online.
So a link to this address.
And if you click on Single player - Untimed, you can see that you have a word that you have to guess.
And then you start picking some letters.
And if it's right then it goes in,
and if it's wrong then the hangman gallows start being drawn and our little man is at risk of being
hung.
Once you understand how the game works, it's time for us to examine what the logic for our program
is going to look like.
And to do that, we're going to use flowchart programming.
So it's very simple.
It just means that we can draw out a flowchart to represent the logic of our game.
At this point, I want you to pause the video and have a quick think about how you would program Hangman.
Try and come up with a flowchart that represents the logic of this game.
Break it down into little steps.
What needs to happen first?
What needs to happen when the user makes a guess, and what should happen when the guess is incorrect?
When should the game end?
Pause the video
now, take a pencil and a piece of paper or use Draw.io to create your flowchart.
So how did that go?
Did you break down the problem?
It's really important to say that there's no single right answer here.
And there's loads of ways that you could have done this.
But let me show you my approach, which is how we'll write our program over the next couple of lessons.
So this is what it looks like from start to end.
And if we zoom in a bit, let's go through this flowchart step by step
so we're all on the same page. At the start of the game, the first thing we do is to generate a random
word.
Let's say in this case it was the word mouse.
Now the next step is to generate as many blanks as the letters in the word.
So we have these blanks to show the user how many letters are in this word that they need to guess.
They don't get to see this, but they get to see this.
And the next step they get to guess a letter.
So let's say the user in this case guessed the letter O,
well, the next thing we have to check is, is the guessed letter actually in the word.
Well, in this case O is indeed in mouse.
It's the one at the second position.
And so we go down this path and we answer yes to that question.
So now we get to replace that blank with the letter O.
Now the next stage is we have to check,
are all the blanks filled?
Are all of these blanks removed?
Because in that case, it means the user has guessed all of the letters correctly.
Well, at the moment it's definitely a no because we've only guessed one letter.
So then we go all the way back to the beginning and we ask the user to guess another letter.
Now, at some stage of the game, all the letters will be guessed and then we can answer yes to this
question, which means it's game over.
The user has won because they've guessed all the letters correctly.
Now, if we go back to the part where we asked the user to guess a letter and they guessed a letter,
say the letter Z, which doesn't actually exist in this word mouse.
Well then, in this case, we go down this right path to answer No, and the user loses a life, which means
we start drawing out our hangman figure.
Now, depending on whether if they have run out of lives, if the hangman has been drawn completely,
then they would go down this path.
But at the moment they've only lost one life and this figure is not complete.
So the answer is No.
And that means we go back to the beginning and we get them to guess the next letter.
Now, if at the stage where they've exhausted all of their lives and the hangman figure is complete,
well then it's the end of the game,
and they've basically just lost without having guessed all of the letters in the word.
So this is the logic, and you might need to come back to this video a few times if you get stuck along
the way just to review how the programme flows.
But it might also be worth creating your own flowchart chart or simply downloading this completed flow
chart I have here in the Course Resources.
It's a really useful tool to come back to and refer to as you're writing the code, because this will
give you an overview of what you're trying to get your code to do, and hopefully this is going to make
it easier for you to complete the upcoming challenges in this project.
Once you're ready, head over to the next lesson, and let's get started.