WEBVTT

00:00.540 --> 00:05.420
So let's do the top down design for a hangman.

00:05.430 --> 00:10.060
So like I said before you really should just start with the highest level possible.

00:10.200 --> 00:10.860
So

00:13.150 --> 00:25.470
basically do while you want to play again just like we had in number guess or this and is play the game

00:27.530 --> 00:29.510
in this.

00:29.660 --> 00:36.480
And this is kind of the high level.

00:36.720 --> 00:41.250
Step one let's say of the top down design.

00:41.760 --> 00:47.060
So now we should be breaking down play a game and want to play again.

00:47.370 --> 00:53.550
We might skip want to play again because we've kind of already done that before so we'll just kind of

00:53.550 --> 00:55.610
copy what you have for.

00:55.620 --> 00:59.750
So let's just go to Step 2.

01:02.610 --> 01:03.530
Play a game

01:12.530 --> 01:17.210
for all or main Maybe this will be your main

01:20.490 --> 01:21.620
play game.

01:23.320 --> 01:25.080
So how do you play the game.

01:25.090 --> 01:28.050
Well the first thing you should do is get.

01:28.100 --> 01:32.050
It's the secret word right.

01:32.320 --> 01:33.820
That's it.

01:33.910 --> 01:34.350
It's

01:38.100 --> 01:43.020
an and then you should probably want to make

01:47.620 --> 01:49.290
the hidden word right.

01:52.470 --> 01:56.850
That's using probably using secret word or

02:00.790 --> 02:06.020
and maybe set the number of guesses.

02:06.170 --> 02:11.150
Laughs It should be six.

02:11.150 --> 02:11.950
In this case.

02:11.950 --> 02:12.500
Right.

02:15.280 --> 02:21.570
And we didn't talk about this but maybe draw rob again.

02:24.210 --> 02:35.530
Draw the gallows or the word say and here we should say do

02:38.010 --> 02:44.290
and while not game is over.

02:49.440 --> 02:55.790
OK we will get the guess so that's a guess.

02:55.790 --> 03:06.970
So let's actually let's formalize it a little bit more so it's a secret word is get the secret word

03:07.900 --> 03:10.790
secret word.

03:10.920 --> 03:26.980
So now see that's a function let's say and the hidden word or phrase may be phrase in phrase should

03:26.980 --> 03:28.780
be.

03:29.300 --> 03:40.580
Maybe have a function for making hidden raise using the secret phrase

03:43.010 --> 03:52.090
say and setting the number of guesses left it should just be number guesses.

03:52.210 --> 03:53.260
Wow.

03:55.090 --> 03:56.430
Six.

03:56.810 --> 04:04.820
OK so we're kind of sort of making this into code but you know again high level let's just say draw

04:05.540 --> 04:07.480
and say draw the board.

04:09.080 --> 04:09.530
Somehow

04:12.920 --> 04:23.460
ants actually probably need the phrase is because you should be drawing not only the let's just put

04:23.460 --> 04:24.600
it up here.

04:24.950 --> 04:29.160
So it would be something like this

04:37.460 --> 04:38.600
somehow right.

04:41.010 --> 04:41.460
It's

04:44.480 --> 04:44.890
OK.

04:44.980 --> 04:55.330
And then you'd have that guy if you had any bad guesses and then you kind of say you know dash dash

04:55.330 --> 05:06.770
dash dash dash and all your secret word there's something revealed there any say like this.

05:06.820 --> 05:09.340
So it's going to look something like this.

05:09.570 --> 05:14.570
And this will be the draw board part.

05:14.630 --> 05:18.070
So then we'll get to yes.

05:18.570 --> 05:19.440
Yes.

05:20.580 --> 05:21.650
Somehow.

05:22.350 --> 05:27.280
And we will date the board somehow.

05:29.130 --> 05:32.540
UPDATE This part and this part

05:35.210 --> 05:46.560
with the gas and probably the secret phrase and maybe even the hidden phrase because maybe we need to

05:46.560 --> 05:48.200
change it somehow.

05:50.480 --> 05:51.040
OK.

05:51.290 --> 05:52.630
Something like this.

05:53.530 --> 05:56.470
And maybe we will draw the board again.

06:01.040 --> 06:01.790
Phrase

06:05.080 --> 06:11.910
and we should check to see if it was a good guess or not.

06:13.050 --> 06:18.130
So if it's if it wasn't a good guess

06:23.290 --> 06:28.150
and I guess the we'll know if it's a good guess maybe will return

06:30.520 --> 06:32.970
TRUE TRUE for the update.

06:33.030 --> 06:33.220
Right.

06:33.250 --> 06:40.150
Because this is where we would check an update or this is where we check to see if it should be revealed

06:40.150 --> 06:40.500
or not.

06:40.500 --> 06:41.040
Right.

06:41.320 --> 06:44.470
If one of the letters for guess would be revealed.

06:44.470 --> 06:58.740
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

06:58.800 --> 07:12.720
it's just the number guesses is this guesses left minus minus right or equals two or minus equals 1

07:12.720 --> 07:16.050
or something like.

07:16.880 --> 07:18.450
And while the game's not over.

07:18.530 --> 07:27.010
And then at the end we should display results again as we did with that number guesser.

07:27.030 --> 07:34.680
So I will say it provided the secret word or phrase an.

07:35.170 --> 07:37.960
Maybe the number of guesses Laughs Because

07:40.690 --> 07:44.340
guess in it's because

07:48.470 --> 07:54.960
if it if we still have if it's a positive number of yeses then we want right.

07:55.290 --> 08:03.910
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

08:03.910 --> 08:11.430
how to do any of this stuff yet but I'm just sort of kind of working my way through what makes sense.

08:11.510 --> 08:11.930
OK.

08:11.950 --> 08:16.030
So I just said OK you know you have to get this in the first place.

08:16.270 --> 08:18.830
You have to make the hidden phrase right.

08:19.000 --> 08:20.260
Set this set.

08:20.260 --> 08:23.740
How many guesses we have left.

08:23.740 --> 08:28.290
This is all just kind of initialization and a game.

08:28.430 --> 08:35.380
This whole thing is just initialization and then you know draw the board somehow.

08:35.380 --> 08:45.100
So they know you know what two or how many dashes there are in the whole phrase and then we just go

08:45.100 --> 08:46.030
through the game.

08:46.030 --> 08:52.060
So we just kind of get the input as just getting the input and then we update the board.

08:52.120 --> 08:55.060
And then we draw the board.

08:55.150 --> 08:56.470
And then we

08:59.410 --> 09:05.470
in fact we can even like we don't even need to have this part here we could even pass in the number

09:05.470 --> 09:06.740
of guesses.

09:07.890 --> 09:16.150
Right here you don't even need this.

09:16.230 --> 09:17.810
Maybe it'll update.

09:18.090 --> 09:19.910
Maybe it will update itself.

09:19.940 --> 09:21.120
Right.

09:24.070 --> 09:26.400
Things just made a change.

09:26.470 --> 09:30.530
So good pass by reference right.

09:31.810 --> 09:37.810
So now we just get the yes we update the board with the guess.

09:38.120 --> 09:42.190
We draw the board and then we do this while the game's not there.

09:42.530 --> 09:48.780
So and then when this game is over we just you know say how many are safe.

09:48.790 --> 09:49.940
You got it or not.

09:50.140 --> 09:52.330
And that's it.

09:52.430 --> 09:54.550
That's kind of how you play the game.

09:54.920 --> 09:59.560
So let's go through some of these.

09:59.570 --> 10:02.080
So again we're going to skip I want to play again.

10:02.120 --> 10:03.590
Does it matter.

10:03.590 --> 10:04.970
You know how that works.

10:06.480 --> 10:12.760
We're going to break down getting the secret word.

10:14.240 --> 10:18.170
It's the secret word.

10:18.270 --> 10:20.970
So please stick to us.

10:24.400 --> 10:25.680
Or is it threes or

10:31.940 --> 10:32.560
so.

10:32.580 --> 10:34.570
Step three get the secret word right.

10:34.790 --> 10:37.250
So you should probably have

10:41.890 --> 10:45.030
well not her how would you do this.

10:45.030 --> 10:48.160
You just prompt the user right prompt user

10:51.960 --> 11:07.100
or the word and used get it just like we did in the practice of the dynamic memory secret phrase or

11:20.830 --> 11:26.260
prompt in get it and get it somehow.

11:30.950 --> 11:37.160
You probably know how to do this and then we just return while we're going we have to turn anything

11:37.160 --> 11:42.540
yet we don't know or return I guess her secret phrase

11:47.620 --> 11:49.260
again this might not be 100 percent correct.

11:49.270 --> 11:57.970
But again this is just an outline for us to understand how things are working and the next one so says

11:57.970 --> 11:59.430
make hidden phrase.

11:59.560 --> 12:02.670
You don't do that let's say me.

12:03.310 --> 12:08.810
Reads took the secret phrase right.

12:15.710 --> 12:18.180
So how would this work.

12:18.570 --> 12:20.300
OK well we need to

12:22.780 --> 12:24.040
somehow copy

12:26.380 --> 12:33.120
the or new Maybe New

12:38.100 --> 12:44.850
meet new C string.

12:45.080 --> 12:50.150
Given the length of the secret phrase

12:53.220 --> 13:01.140
gates if you remember in the dynamic memory how to do this or and so need to do that.

13:01.150 --> 13:03.370
And let's just set it to.

13:03.620 --> 13:07.860
It's called The Hidden phrase that somehow.

13:08.450 --> 13:09.550
OK.

13:09.580 --> 13:26.380
And then for the length of secret phrase we set them all three dashes Kings hidden phrase

13:28.820 --> 13:33.800
whatever the current one is should be a dash and hide it.

13:33.800 --> 13:37.980
So when we try it they all look like dashes.

13:39.150 --> 13:46.190
So we just do that for every letter and the secret phrase and then we return.

13:47.930 --> 13:48.410
Phrase

13:53.380 --> 13:55.220
in that's kind of it.

13:55.320 --> 14:01.080
That's one the date the board.

14:01.190 --> 14:04.300
So I think we know how to get the gas.

14:04.300 --> 14:06.020
We've done this before.

14:06.050 --> 14:07.540
So let's kind of skip that

14:10.340 --> 14:12.450
and we'll say update each

14:15.530 --> 14:16.370
board.

14:20.210 --> 14:20.500
It's

14:24.620 --> 14:26.580
and took all this stuff.

14:26.580 --> 14:29.510
So let's take this

14:37.110 --> 14:38.540
space in here.

14:40.740 --> 14:42.570
So how do you update the board.

14:42.570 --> 14:44.250
What do you do here.

14:44.250 --> 14:52.230
Well basically we're going to take a guess and check every letter in the secret phrase right.

14:53.510 --> 14:58.050
And see if that gas matches one of those letters.

14:58.240 --> 15:11.250
And if we do match then we just kind of reveal the those letters in the hidden phrase.

15:11.270 --> 15:18.060
So for however many ones that exist in the secret phrase we'll just reveal it all in the hidden phrase.

15:18.560 --> 15:29.400
And if we didn't find one then we will decrement the number of guesses left.

15:29.900 --> 15:36.520
So we will basically say Savo like a.

15:37.240 --> 15:41.160
And this is sort of use code and sort and I can use code.

15:41.160 --> 15:44.440
So I found was false right.

15:44.480 --> 15:46.310
And Riskin save for

15:49.340 --> 15:59.010
the link of the secret phrase right.

16:02.330 --> 16:05.310
We will.

16:05.380 --> 16:17.310
So if the secret phrase is guess OK.

16:17.680 --> 16:26.690
So if it is that letter then we'll say no hidden

16:29.470 --> 16:33.540
phrase as to the guess.

16:33.670 --> 16:34.190
Right.

16:34.210 --> 16:36.790
So we just reveal it in that spot.

16:36.820 --> 16:42.780
So you either spot is that guess we just reveal it in a hidden friezes spot.

16:42.800 --> 16:44.190
Remember these are the same length.

16:44.200 --> 16:47.560
So this works.

16:48.720 --> 16:51.180
And then we'll say we found it

16:54.810 --> 17:02.600
and maybe even here we should say I like and not found something so we can observe her.

17:02.610 --> 17:07.260
Well actually we shouldn't touch we shouldn't do that because we need to go through the entire type

17:07.290 --> 17:08.910
thing.

17:09.040 --> 17:22.510
So if it wasn't found then the number of guesses left or right minus minus.

17:22.610 --> 17:22.880
Right.

17:22.920 --> 17:25.100
Dickerman that.

17:26.150 --> 17:29.560
And that's kind of it.

17:29.590 --> 17:33.840
So the last one

17:38.050 --> 17:44.110
because again I think we do this display results we did this in the last game.

17:44.500 --> 17:50.490
So we know I do this maybe I should say game do the it's game over.

17:50.500 --> 18:00.520
So is it over.

18:00.550 --> 18:02.420
Probably give it.

18:02.480 --> 18:11.640
It's anything here yet but we'll probably need to know the number of guesses left because it'll be over

18:11.650 --> 18:14.820
if the number of guesses left is zero.

18:15.670 --> 18:17.560
Or if the

18:21.620 --> 18:27.280
in phrase is completely trivial.

18:27.280 --> 18:27.700
Right.

18:27.910 --> 18:31.910
So Scott is

18:39.670 --> 18:41.160
peace here.

18:47.160 --> 18:57.260
So the game is over if all the dashes are gone right.

18:57.300 --> 18:58.430
The hidden phrase right.

18:58.470 --> 19:02.230
Because that would mean that the whole word is revealed.

19:02.530 --> 19:06.540
So let's do that.

19:07.190 --> 19:14.020
So if I have a dash has dash.

19:14.050 --> 19:20.900
Would you say it's false right away for the length of the hidden phrase.

19:23.240 --> 19:38.700
If I didn't raise of I say is equal to the Jash that means we haven't found it right.

19:40.440 --> 19:43.830
Dash holds true.

19:45.730 --> 19:54.020
And in this case now say and not as Dasch.

19:54.130 --> 20:04.800
And then we could just say return the number of guesses left is zero or we have a dash

20:10.100 --> 20:11.200
and that's it.

20:11.240 --> 20:13.960
This one.

20:14.070 --> 20:14.730
So

20:17.300 --> 20:18.970
again we're going to skip the display result.

20:18.970 --> 20:24.610
We're going to skip drawing board because we we do know how to do this but this will be this would be

20:24.620 --> 20:26.760
one of the first things we actually do.

20:26.870 --> 20:28.950
It's just a lot of typing.

20:29.330 --> 20:31.970
So it's not hard.

20:32.060 --> 20:32.330
All

20:36.010 --> 20:39.740
so we've kind of done everything we really need to think.

20:39.800 --> 20:44.900
So we skipped get gas we skipped display results because we've done this in the last games innings we

20:44.900 --> 20:46.930
can't know that works.

20:46.960 --> 20:51.050
And Skip I want to play again.

20:51.800 --> 20:58.690
But other than that this whole thing is kind of solved and we basically have all the code for it already.

20:59.580 --> 21:04.800
So in the next lecture we will actually implement everything.
