So let's do the top down design for a hangman.
So like I said before you really should just start with the highest level possible.
So
basically do while you want to play again just like we had in number guess or this and is play the game
in this.
And this is kind of the high level.
Step one let's say of the top down design.
So now we should be breaking down play a game and want to play again.
We might skip want to play again because we've kind of already done that before so we'll just kind of
copy what you have for.
So let's just go to Step 2.
Play a game
for all or main Maybe this will be your main
play game.
So how do you play the game.
Well the first thing you should do is get.
It's the secret word right.
That's it.
It's
an and then you should probably want to make
the hidden word right.
That's using probably using secret word or
and maybe set the number of guesses.
Laughs It should be six.
In this case.
Right.
And we didn't talk about this but maybe draw rob again.
Draw the gallows or the word say and here we should say do
and while not game is over.
OK we will get the guess so that's a guess.
So let's actually let's formalize it a little bit more so it's a secret word is get the secret word
secret word.
So now see that's a function let's say and the hidden word or phrase may be phrase in phrase should
be.
Maybe have a function for making hidden raise using the secret phrase
say and setting the number of guesses left it should just be number guesses.
Wow.
Six.
OK so we're kind of sort of making this into code but you know again high level let's just say draw
and say draw the board.
Somehow
ants actually probably need the phrase is because you should be drawing not only the let's just put
it up here.
So it would be something like this
somehow right.
It's
OK.
And then you'd have that guy if you had any bad guesses and then you kind of say you know dash dash
dash dash dash and all your secret word there's something revealed there any say like this.
So it's going to look something like this.
And this will be the draw board part.
So then we'll get to yes.
Yes.
Somehow.
And we will date the board somehow.
UPDATE This part and this part
with the gas and probably the secret phrase and maybe even the hidden phrase because maybe we need to
change it somehow.
OK.
Something like this.
And maybe we will draw the board again.
Phrase
and we should check to see if it was a good guess or not.
So if it's if it wasn't a good guess
and I guess the we'll know if it's a good guess maybe will return
TRUE TRUE for the update.
Right.
Because this is where we would check an update or this is where we check to see if it should be revealed
or not.
Right.
If one of the letters for guess would be revealed.
So maybe this will return true if it was a good guess was guess is this if it wasn't and we'll say no
it's just the number guesses is this guesses left minus minus right or equals two or minus equals 1
or something like.
And while the game's not over.
And then at the end we should display results again as we did with that number guesser.
So I will say it provided the secret word or phrase an.
Maybe the number of guesses Laughs Because
guess in it's because
if it if we still have if it's a positive number of yeses then we want right.
And if it's zero and last Ok so this is kind of the high level I'm just you know again I don't know
how to do any of this stuff yet but I'm just sort of kind of working my way through what makes sense.
OK.
So I just said OK you know you have to get this in the first place.
You have to make the hidden phrase right.
Set this set.
How many guesses we have left.
This is all just kind of initialization and a game.
This whole thing is just initialization and then you know draw the board somehow.
So they know you know what two or how many dashes there are in the whole phrase and then we just go
through the game.
So we just kind of get the input as just getting the input and then we update the board.
And then we draw the board.
And then we
in fact we can even like we don't even need to have this part here we could even pass in the number
of guesses.
Right here you don't even need this.
Maybe it'll update.
Maybe it will update itself.
Right.
Things just made a change.
So good pass by reference right.
So now we just get the yes we update the board with the guess.
We draw the board and then we do this while the game's not there.
So and then when this game is over we just you know say how many are safe.
You got it or not.
And that's it.
That's kind of how you play the game.
So let's go through some of these.
So again we're going to skip I want to play again.
Does it matter.
You know how that works.
We're going to break down getting the secret word.
It's the secret word.
So please stick to us.
Or is it threes or
so.
Step three get the secret word right.
So you should probably have
well not her how would you do this.
You just prompt the user right prompt user
or the word and used get it just like we did in the practice of the dynamic memory secret phrase or
prompt in get it and get it somehow.
You probably know how to do this and then we just return while we're going we have to turn anything
yet we don't know or return I guess her secret phrase
again this might not be 100 percent correct.
But again this is just an outline for us to understand how things are working and the next one so says
make hidden phrase.
You don't do that let's say me.
Reads took the secret phrase right.
So how would this work.
OK well we need to
somehow copy
the or new Maybe New
meet new C string.
Given the length of the secret phrase
gates if you remember in the dynamic memory how to do this or and so need to do that.
And let's just set it to.
It's called The Hidden phrase that somehow.
OK.
And then for the length of secret phrase we set them all three dashes Kings hidden phrase
whatever the current one is should be a dash and hide it.
So when we try it they all look like dashes.
So we just do that for every letter and the secret phrase and then we return.
Phrase
in that's kind of it.
That's one the date the board.
So I think we know how to get the gas.
We've done this before.
So let's kind of skip that
and we'll say update each
board.
It's
and took all this stuff.
So let's take this
space in here.
So how do you update the board.
What do you do here.
Well basically we're going to take a guess and check every letter in the secret phrase right.
And see if that gas matches one of those letters.
And if we do match then we just kind of reveal the those letters in the hidden phrase.
So for however many ones that exist in the secret phrase we'll just reveal it all in the hidden phrase.
And if we didn't find one then we will decrement the number of guesses left.
So we will basically say Savo like a.
And this is sort of use code and sort and I can use code.
So I found was false right.
And Riskin save for
the link of the secret phrase right.
We will.
So if the secret phrase is guess OK.
So if it is that letter then we'll say no hidden
phrase as to the guess.
Right.
So we just reveal it in that spot.
So you either spot is that guess we just reveal it in a hidden friezes spot.
Remember these are the same length.
So this works.
And then we'll say we found it
and maybe even here we should say I like and not found something so we can observe her.
Well actually we shouldn't touch we shouldn't do that because we need to go through the entire type
thing.
So if it wasn't found then the number of guesses left or right minus minus.
Right.
Dickerman that.
And that's kind of it.
So the last one
because again I think we do this display results we did this in the last game.
So we know I do this maybe I should say game do the it's game over.
So is it over.
Probably give it.
It's anything here yet but we'll probably need to know the number of guesses left because it'll be over
if the number of guesses left is zero.
Or if the
in phrase is completely trivial.
Right.
So Scott is
peace here.
So the game is over if all the dashes are gone right.
The hidden phrase right.
Because that would mean that the whole word is revealed.
So let's do that.
So if I have a dash has dash.
Would you say it's false right away for the length of the hidden phrase.
If I didn't raise of I say is equal to the Jash that means we haven't found it right.
Dash holds true.
And in this case now say and not as Dasch.
And then we could just say return the number of guesses left is zero or we have a dash
and that's it.
This one.
So
again we're going to skip the display result.
We're going to skip drawing board because we we do know how to do this but this will be this would be
one of the first things we actually do.
It's just a lot of typing.
So it's not hard.
All
so we've kind of done everything we really need to think.
So we skipped get gas we skipped display results because we've done this in the last games innings we
can't know that works.
And Skip I want to play again.
But other than that this whole thing is kind of solved and we basically have all the code for it already.
So in the next lecture we will actually implement everything.