So now let's actually start implementing hangman.
So start with step 1 and mean here.
So we have
here is going to do exactly what we did with number gassers.
While I want to play again don't have those functions yet but we make them in.
OK.
That is our step.
One of our top down design right here.
So do it again.
While I want to play again just like we had with number Yassar.
So let's though or declare those functions top here.
What do you say with the name and would want to play an.
There you go.
So next thing I want to do is want to define plaguing
k.
Phew.
Remember what we need to do is have the get the secret phrase make the hidden phrase right.
The one that dashes in and set the number of guesses left and so on.
So let's do this do these three steps first.
So going to need some kind of a C string for the secret where secret phrase
that and it's going to be an array because Raffa read this from the user or from the player self.
So I need to have some kind of like Max link.
It's great.
Us.
And again to set it to some some number do too much just make it long enough.
Why.
CH
reas this way.
And we're also going to have a C string but this is going to be a character pointer to the hidden phrase
because we're going to make this from heap memory.
So with that.
And we have
in this number of guess it's life.
And we are we make this into a constant and smacks
guess's.
Six is
simple so far so we just all we've done is made the variables that we need so we need to actually get
the secret phrase and make the hidden phrase and so on.
So let's do that.
So say
secret or sorry get secret phrase
this and will pass in the secret phrase
and the wink.
Or the maximum number of characters you know great great.
This
care.
So this function will be exactly the same as what we did in the dynamic memory practice.
So are at least very similar.
So let's rate this once.
You're point to it's not going to turn anything right because we're passing in a an array so that will
actually change the array rates raise is passed by reference.
So we're going to change this phrase by adding all the characters in here.
So it's phrase
phrased like this and we're passing a character.
Ray
is this and passed back the maximum way.
Max link back
to find it here
right now.
Yes it's phrase
XBLA.
Hey
And essentially all we're going to do is exactly what we did before
say bhool aliar.
Right.
Just like regular input.
This do
while there's failure which should seem all too familiar.
An failure
to false.
Out.
These enter the Secret Ch phrase we're not using the functions we had we made before in the erate practice.
But we will not for this one anyway but we will be using it.
Get ch as it is and the maximum
Just like we had in the practice day.
If you fail rate
then we should it's clear C nor in need
our constants appear.
Nor are as many and just enough
are
char's this
and once actually have a number constant that's going to be like an integer constants going to be a
star constant.
It's going to be the inputs air string when you use that
input error.
Please try again.
You can also have césarine constants too.
So it doesn't have to be just integers or floats or anything like that can actually have this small
in space.
It's
here.
String all this and we failed here in this case write failure.
It's true.
Otherwise.
So what happened.
What would happen if the length of what the input zero.
Right.
So what if they said Please enter a phrase.
But then they just press enter.
And this would still work.
However it would be there would be nothing.
So we want to make sure that doesn't happen.
So we're going to actually get the length of this phrase and check to see if it's zero and if it is
then we're going to print out something and then make sure they do it again.
So what some say to that.
So for this I need this string to be able to get the link that says doing this.
There And here we're going to say have the link.
All right here a link to us for Lion
of secret is
this and so if the link is zero then we're going to output.
Just put something directly here so I'm not going to say it's an input air I'm going to say you must
enter a word that's longer 0 do it's
Please try
this.
And this was failure to this case
and
we should also pass back the link of the secret phrase actually.
So let's actually change this.
It
or know how long it is not to do this every time.
It's just that.
Turn the
we know it has to be greater than zero.
Otherwise it will be looped again.
So that's this one so we need a variable for the length.
Here
secret phrase length is get that from here.
So next we should.
One thing you want to do is actually paste in the functions we made from the array lecture or from the
array practice lecture.
So we had that those two functions called Get character and use these already have them in my clipboard.
So we had these ones of good character which you could have a prompt in error.
These are directly from that array lecture.
I didn't change them in any way.
So if you remember this you can get them at the prompt in the air and it checks to see if it's an alpha
you need to.
And also check to see if it's lower case.
Well this won't really matter too much after we fix this so.
And he could also give the give it's some valid input too.
And like what.
OK so let's we have to include CC type because otherwise it will work clewed
type this way.
And this is just so we have it and can use it.
So for the next one is
hidden word so are hidden phrase hidden phrase because to say make hidden.
We're going to pass the secret phrase
and the secret free.
And this is why I have the secret phrase like just as for this function.
So it's copy this and declare it of
and this will pass back a character pointer of the new memory that we make.
So this would be Comte's shore star
and
it's this
and put it it's and these will be the last.
It's right here.
Make hidden free.
It's
so
do it is.
Let's take a look at the key phrase here.
Right.
So making news E-string given the length of the phrase and then set all the dashes this should exclude
actually the
spaces.
So we haven't taken that into account.
We will in the function itself so this
char star also a hidden phrase called new char secret phrase link was one always plus one seed in all
character.
So it's wrong.
So for int i zero I's less than Lenk secret reads like
Spross.
And so if the secret were a secret phrase is not equal to a space then we will set the hidden or hidden
spell phrase hidden phrase of will be the dash and
otherwise if it is then we'll just kind of set it to be the same thing as in phrase.
I
just say dash or space here Gaelic that and again remember didn't phrase
of the last one.
The secret
fragrance link should be
the null character.
Remember
turn the hidden phrase and in fact in the game you should do instead is a pointer right.
Point
like that because we own it.
So play game owns the hidden phrase memory.
So you have to remember this so we know that we we as in play game has to delete it later.
So what's next.
So now that we have all of that we shifted to rob the poor to using the number of guesses left and the
hidden phrase.
So you're saying Gironde board and we're going to use
yes is laugh.
And you'll see why raising a number of guests is left his second and the
pointer
phrase.
Copy this
peer to set it.
And Sarber venture I think because we're just drawing stuff and there say in here and Charsadda Star
year.
And we don't need the link for this because then we could just use sterling césarine and probably don't
want to change it either.
All right.
So you put Konst year.
So this
and it's
your
like that's so we didn't actually do a top down design for the DRob board at all but we should be able
to easily figure this out right.
So what we want to do is check to see how many guesses we have left.
And then based on that we want to draw the gallows and the guy if there is if it's not six guesses say
so what.
Start doing that and we're going to use a switch statement actually and switch on the number of guesses
lasht
and for this case zero will be
the break.
OK.
So caesura will be they have 0 guesses left so we should draw the entire Gallo's with the guy.
So that so put a space in between.
And there should be three dashes and two different signs that the whole copy what I'm doing.
Hope you're following along anyway.
It's boring to watch.
I think
so for the head to use an Oh.
I don't know maybe a capital
better
body stick that and of course Actually since this is this is going to be the case where we're showing
the whole body of the arm like here and then need two two dashes here because this is the escape character
and we have to escape the arm so it'll actually look like this when it draws but you need to do it like
that.
Just like we have like Dash or slash.
And for a new line we have to do slash slash slash for this backslash.
So
it's just this
and slash slash leg.
Dasch in Los
dash OK.
So we should be copying this whole thing and we have to do this for each case now.
So Case 1 and will remove one part of it.
So remove the leg in this case the leg will be the last thing you see.
Case to
move the
speed the body and the hands her arms case three
it will be
the his left arm is gone.
Here this
is right here.
The key is for
he will remove his other arm which is body that
and Caze five
move the body.
This is the head.
He's 6
ye
yes the gallows
so we understand what's happening here.
We're just switching based off the number of guesses and then we're going to do the output for.
For that value.
That's really it and so it defaults.
Deif all we have nothing.
And we should also output it's
we should also have to analyze here.
Actually we want another space after Jawan
you don't have to use just kind of a formatting thing.
I'm going
in next
mishit.
I put the secret word here secret phrase
or hidden phrase.
Yes.
Pointer
is like that.
And again on two different ch or two and those.