WEBVTT

00:01.040 --> 00:07.310
In this lecture we're going to build on what we've learned in the last lecture and really start to design

00:07.310 --> 00:08.660
our game.

00:08.740 --> 00:14.600
I can write any code in this lecture but we will solve the entire problem.

00:15.410 --> 00:22.430
So we know that the players should be prompted to play again once the game is over.

00:22.430 --> 00:30.310
So how would we in just a few kind of lines really solve this problem.

00:30.350 --> 00:38.310
So how I would go about it is say I'm going to write some pseudo code here.

00:39.300 --> 00:51.320
So I say do you know play the game.

00:51.550 --> 00:52.920
And then while

00:56.390 --> 01:00.390
we want us to play again.

01:00.520 --> 01:00.940
Right.

01:03.530 --> 01:10.030
It's a very simple kind of way to solve the problem.

01:10.230 --> 01:18.690
And you may think I'm being a bit cheeky here by just kind of really solving a very high level but you're

01:18.690 --> 01:23.310
going to see in a second why I'm why I'm doing this.

01:23.310 --> 01:30.920
So we've kind of Virdi solve the entire problem but we've really glossed over the real meat of it.

01:30.960 --> 01:37.010
So let's actually break down how we played the game.

01:37.170 --> 01:37.680
Skinner right.

01:37.680 --> 01:39.280
Play the game here.

01:43.300 --> 01:52.690
So we know from the description that we have to set the secret number at the start.

01:52.780 --> 02:04.300
So maybe the very first thing to do one set secret number.

02:04.730 --> 02:14.900
And since we don't know how to kind of choose it or change it every time we're just going to set it

02:14.900 --> 02:19.120
to a known value.

02:19.140 --> 02:19.710
For now

02:27.880 --> 02:35.050
because at least then we'll be able to play the game and make any changes we need to make in order to

02:35.230 --> 02:35.970
play the game.

02:36.000 --> 02:48.060
For so the next step is to watch when we have to actually set the number of guesses.

02:49.630 --> 02:50.120
Right.

02:50.270 --> 02:56.880
And thanks to our understanding of the problem the last lecture we know exactly what to set it to.

02:56.910 --> 03:03.930
So the the log is going to be two of the upper.

03:04.370 --> 03:05.830
Well we know the range.

03:05.840 --> 03:08.600
So is this going to be 100.

03:09.080 --> 03:16.310
And it's probably going to be like this maybe maybe the ceiling of it or something.

03:16.310 --> 03:21.670
If you remember that function in math and go to the next highest integer.

03:21.960 --> 03:22.750
OK.

03:23.000 --> 03:28.940
So that will be that.

03:29.110 --> 03:34.290
And the next thing is to get the yes from where.

03:34.570 --> 03:34.990
Right.

03:35.200 --> 03:37.270
So I start guessing.

03:37.270 --> 03:42.610
So get the yes from the player.

03:43.080 --> 04:01.950
Well really what we need to do is prompt these for really prompt three four prompts the user to make

04:02.130 --> 04:03.160
a guess.

04:03.180 --> 04:11.700
And remember we should output the number of guesses left.

04:12.000 --> 04:12.260
K.

04:15.980 --> 04:33.270
so the next thing is once we get it we should Shak see if the guess is equal to the secret number or.

04:36.870 --> 04:37.620
K.

04:38.110 --> 04:52.750
And this might have a few cases so this is the case where if the guess is not equal to the secret number

04:55.360 --> 05:00.510
and then kind of 5 a 1

05:03.430 --> 05:11.420
it we should decrement each number of guesses left

05:16.470 --> 05:21.720
and then the next thing we should do is

05:24.150 --> 05:36.340
check to see if the class was higher or lower.

05:38.750 --> 05:39.580
And

05:42.730 --> 05:49.060
the secret number 8.

05:49.200 --> 05:51.930
So if it was

05:55.200 --> 06:00.840
OK so safe skewing it silly but

06:04.040 --> 06:08.750
her it's five today OK.

06:08.910 --> 06:19.870
So if it was higher and we print at the guess is too high right.

06:20.960 --> 06:29.650
Otherwise a to b if the guess is lower

06:33.050 --> 06:33.890
than

06:38.640 --> 06:47.030
right that I guess was two.

06:47.130 --> 06:55.620
And if it was exact then it's actually doesn't that doesn't matter too much.

06:56.100 --> 07:00.480
You'll see why in a second so we have to do this multiple times right because what if they didn't guess

07:00.480 --> 07:00.980
the numbers.

07:00.980 --> 07:08.480
So this actually has to be all in the big.

07:08.610 --> 07:10.950
So again use to do while loops.

07:10.960 --> 07:14.600
Notice her using the do while here.

07:15.010 --> 07:17.500
Because we want to do this at least once right.

07:17.710 --> 07:24.880
We want to at least get get to see her number and then make the player guess at least once.

07:25.000 --> 07:25.430
OK.

07:26.610 --> 07:31.350
So while wow wow.

07:31.680 --> 07:32.970
While the game is over

07:36.880 --> 07:37.330
OK.

07:37.400 --> 07:48.430
So and as I'm using English and and sort of a little bit of code so you sort of do our pseudo code here.

07:48.820 --> 07:51.540
So this is really what I call solving the problem.

07:51.590 --> 07:55.880
So let's go through this one more time and see if this really solves the problem.

07:55.880 --> 08:01.350
So we do play the game wow.

08:01.360 --> 08:02.750
We want to play again.

08:02.760 --> 08:03.100
Right.

08:03.130 --> 08:06.290
So we just keep doing this while we keep wanting to play.

08:06.750 --> 08:07.230
OK.

08:07.360 --> 08:18.130
So playing the game then is we have to again loop because it might take multiple tries for the user

08:18.130 --> 08:21.570
to actually get the secret number.

08:21.640 --> 08:27.990
So we set the secret number although this should be not inside.

08:28.140 --> 08:28.700
Right.

08:30.710 --> 08:35.190
So in fact these first steps should not be inside it.

08:39.980 --> 08:45.840
So these steps should be this.

08:46.070 --> 08:47.630
We only want to loop

08:50.740 --> 08:53.360
wow they haven't gotten Yes.

08:56.270 --> 08:57.300
So this

09:02.700 --> 09:11.840
so what we do is we prompt the user to make a guess get guess from the player check to see if that guess

09:11.840 --> 09:13.510
is equal to the secret number.

09:13.640 --> 09:20.870
If it's not equal then more decrement How many guesses we have left and then check to see if it's higher

09:20.870 --> 09:22.700
or lower than the secret number.

09:22.700 --> 09:25.880
And then if it's higher will print that the guess is too high.

09:26.150 --> 09:30.620
And if it's lower the print that the guess is too low.

09:30.620 --> 09:33.250
And while the game is not over.

09:33.300 --> 09:33.840
OK.

09:33.890 --> 09:42.700
And then if the game is over we should then display results of the game.

09:42.710 --> 09:43.100
Right.

09:43.100 --> 09:44.930
So say if he

09:47.510 --> 09:53.100
tell the player if he got it or not.

09:53.190 --> 09:53.630
Right.

09:57.750 --> 10:00.210
So hopefully that makes sense.

10:00.210 --> 10:08.750
So see how it kind of went through a few iterations before before we've even like actually coded anything.

10:08.780 --> 10:15.400
We're solving the problem or make all our mistakes right here so we don't have to have so many mistakes

10:15.580 --> 10:18.230
later when we actually implement the code.

10:18.230 --> 10:25.400
And so I made that mistake of having these two inside that do while loop in me and take it out because

10:25.420 --> 10:27.760
that didn't make any sense.

10:27.920 --> 10:35.970
K so now what do we do.

10:35.990 --> 10:36.370
Right.

10:36.370 --> 10:38.880
Does this solve the entire problem.

10:38.920 --> 10:41.300
I would kind of think so right.

10:41.320 --> 10:51.070
It seems like it does but there are a few things that kind of seem a little bit too big.

10:51.060 --> 10:51.840
Great.

10:51.950 --> 10:54.910
So for example like this.

10:54.920 --> 10:57.150
Play the game thing here right.

10:57.940 --> 11:06.740
And any anything that seems kind of too big we should actually think about making that function.

11:06.740 --> 11:11.390
So play the game.

11:11.590 --> 11:14.680
So to say functions

11:18.160 --> 11:23.390
so play the game will become you know play a game.

11:23.410 --> 11:24.000
Right.

11:25.010 --> 11:31.290
So it's become a play game function so any anything that's really big will make into a function.

11:31.280 --> 11:40.730
So play game is one maybe want to play again should be another one to play again or she's got some thing

11:41.900 --> 11:44.280
to play again.

11:46.460 --> 11:48.950
They will be a function.

11:49.430 --> 11:50.480
You know how to do this.

11:50.480 --> 11:52.700
The secret number is just terrible.

11:52.730 --> 11:53.650
Same with this.

11:53.650 --> 11:55.780
It's going to be almost literally this.

11:55.790 --> 12:01.900
In fact he prompt the user to make a guess and then I'll put them up.

12:01.950 --> 12:08.370
Guesses left and they get the guess from the player could be one function.

12:08.580 --> 12:16.760
So you say get the guess from the player because we've actually made that function before remember we

12:16.760 --> 12:22.030
had the we actually got an integer as a function.

12:22.050 --> 12:24.880
So so sad to say.

12:24.920 --> 12:25.770
Yes.

12:27.600 --> 12:27.960
OK.

12:28.120 --> 12:28.960
That would be a function

12:31.810 --> 12:33.660
and is there any other ones.

12:33.680 --> 12:36.340
Well maybe the game is not over.

12:36.340 --> 12:44.440
So none of these after 5 onwards I think we know how to do that.

12:44.440 --> 12:47.700
These will just be kind of if statements.

12:47.990 --> 12:51.680
And we know how to compare numbers to numbers.

12:51.770 --> 12:57.250
We know how to output whether it's too high or too low and we have to compare.

12:57.320 --> 13:00.200
If you think so we know how do that.

13:00.200 --> 13:08.040
So really this is game is not over.

13:09.870 --> 13:12.770
Just make that into is game over.

13:15.750 --> 13:16.230
OK.

13:16.460 --> 13:20.260
So that be a function and maybe display results

13:23.880 --> 13:29.190
it functions well let's call it like that.

13:32.260 --> 13:32.880
OK.

13:33.400 --> 13:43.290
So we've already done the kind of solving of the play game that's really the core of the game itself

13:43.290 --> 13:44.380
right.

13:44.560 --> 13:50.150
But let's solve the rest of the functions before we even start coding them.

13:50.290 --> 13:55.380
So we again we've done we actually solve these two before.

13:57.020 --> 14:03.550
In one of our input examples is like looping with input and then that function that we did in the practice.

14:03.710 --> 14:10.630
So let's just skip these K because we don't really we don't need to go over that again we're just kind

14:10.630 --> 14:14.250
of do what we did before only maybe slightly modified.

14:14.770 --> 14:20.250
And we were so people trying to solve the is game over.

14:20.270 --> 14:24.770
So it is game over.

14:25.850 --> 14:27.000
When is it over.

14:27.020 --> 14:27.930
Really.

14:27.980 --> 14:36.650
So the game is over when the number of tries left is zero or if the player's gas was equal to the secret

14:36.650 --> 14:37.290
number right.

14:37.340 --> 14:49.480
So really it's just number of guesses left zero or where.

14:49.560 --> 14:50.520
Yes.

14:51.460 --> 14:56.000
Is equal to the seeker number ain't.

14:56.150 --> 15:01.520
That's really there's no nothing else really magical about it.

15:02.850 --> 15:06.450
And so let's move on to the players.

15:06.520 --> 15:09.900
This should be pretty simple to.

15:09.950 --> 15:17.840
So we want to tell the player that they got it if it did tell them they didn't get it if they didn't.

15:17.850 --> 15:18.100
Right.

15:18.140 --> 15:28.240
So even saying like if this pseudocode If player got it then

15:32.190 --> 15:37.100
you know that they got it.

15:37.250 --> 15:46.640
And also when the secret number again just in case that was it was one of our

15:50.380 --> 15:52.290
requirements here.

15:53.690 --> 16:00.340
So as the game ends by saying what the secret number was it rightless if the player gets the right number.

16:00.340 --> 16:00.990
OK.

16:01.250 --> 16:03.790
So when you say it otherwise

16:06.730 --> 16:07.630
we'll say

16:14.240 --> 16:18.420
French.

16:18.600 --> 16:19.750
They didn't get

16:22.500 --> 16:24.970
and also French secret name.

16:30.570 --> 16:33.540
So that's kind of it.

16:33.550 --> 16:37.870
I think we've really solve the problem here.

16:38.810 --> 16:48.240
So in the next lecture we'll actually implement this whole thing and we'll see how well we've really

16:48.300 --> 16:51.550
broken down the problem and understood the problem.

16:51.600 --> 16:55.530
So hopefully we can implement it quite quickly.

16:55.530 --> 16:57.270
So I'll see you in the next lecture.
