WEBVTT

0
00:00.470 --> 00:06.050
All right, guys, so before we get started with our project, it's really important that we're all

1
00:06.050 --> 00:13.820
on the same page and we understand how the code is going to work because we know how the game works.

2
00:14.180 --> 00:19.880
So I recommend that if you've never heard of this game, Hangman, then before you continue to just head

3
00:19.880 --> 00:22.700
over to the Wikipedia article on Hangman.

4
00:22.700 --> 00:27.950
And it might be even easier if you select your own language, because I know that it has a different

5
00:27.950 --> 00:29.810
name in different languages.

6
00:29.840 --> 00:35.390
Now, if you've never played this game, I also recommend just to go and give it a go online.

7
00:35.390 --> 00:37.460
So a link to this address.

8
00:37.460 --> 00:43.610
And if you click on Single player - Untimed, you can see that you have a word that you have to guess.

9
00:43.610 --> 00:46.040
And then you start picking some letters.

10
00:46.040 --> 00:48.320
And if it's right then it goes in,

11
00:48.320 --> 00:56.640
and if it's wrong then the hangman gallows start being drawn and our little man is at risk of being

12
00:56.640 --> 00:57.300
hung.

13
00:57.570 --> 01:02.910
Once you understand how the game works, it's time for us to examine what the logic for our program

14
01:02.910 --> 01:04.140
is going to look like.

15
01:04.140 --> 01:07.500
And to do that, we're going to use flowchart programming.

16
01:07.500 --> 01:09.120
So it's very simple.

17
01:09.120 --> 01:15.180
It just means that we can draw out a flowchart to represent the logic of our game.

18
01:15.600 --> 01:21.900
At this point, I want you to pause the video and have a quick think about how you would program Hangman.

19
01:21.930 --> 01:25.890
Try and come up with a flowchart that represents the logic of this game.

20
01:25.890 --> 01:27.990
Break it down into little steps.

21
01:27.990 --> 01:29.490
What needs to happen first?

22
01:29.490 --> 01:34.320
What needs to happen when the user makes a guess, and what should happen when the guess is incorrect?

23
01:34.320 --> 01:36.030
When should the game end?

24
01:36.420 --> 01:37.200
Pause the video

25
01:37.200 --> 01:42.360
now, take a pencil and a piece of paper or use Draw.io to create your flowchart.

26
01:45.720 --> 01:47.250
So how did that go?

27
01:47.280 --> 01:49.050
Did you break down the problem?

28
01:49.080 --> 01:52.800
It's really important to say that there's no single right answer here.

29
01:52.800 --> 01:55.920
And there's loads of ways that you could have done this.

30
01:55.920 --> 02:01.200
But let me show you my approach, which is how we'll write our program over the next couple of lessons.

31
02:02.280 --> 02:05.700
So this is what it looks like from start to end.

32
02:05.700 --> 02:10.350
And if we zoom in a bit, let's go through this flowchart step by step

33
02:10.350 --> 02:16.500
so we're all on the same page. At the start of the game, the first thing we do is to generate a random

34
02:16.500 --> 02:16.950
word.

35
02:16.950 --> 02:19.950
Let's say in this case it was the word mouse.

36
02:19.950 --> 02:25.620
Now the next step is to generate as many blanks as the letters in the word.

37
02:25.620 --> 02:31.980
So we have these blanks to show the user how many letters are in this word that they need to guess.

38
02:32.040 --> 02:35.010
They don't get to see this, but they get to see this.

39
02:35.010 --> 02:38.550
And the next step they get to guess a letter.

40
02:38.560 --> 02:42.430
So let's say the user in this case guessed the letter O,

41
02:42.520 --> 02:48.130
well, the next thing we have to check is, is the guessed letter actually in the word.

42
02:48.130 --> 02:51.010
Well, in this case O is indeed in mouse.

43
02:51.010 --> 02:53.020
It's the one at the second position.

44
02:53.020 --> 02:58.180
And so we go down this path and we answer yes to that question.

45
02:58.180 --> 03:02.530
So now we get to replace that blank with the letter O.

46
03:03.670 --> 03:06.400
Now the next stage is we have to check,

47
03:06.400 --> 03:08.170
are all the blanks filled?

48
03:08.170 --> 03:10.120
Are all of these blanks removed?

49
03:10.120 --> 03:14.470
Because in that case, it means the user has guessed all of the letters correctly.

50
03:14.470 --> 03:19.390
Well, at the moment it's definitely a no because we've only guessed one letter.

51
03:19.390 --> 03:24.940
So then we go all the way back to the beginning and we ask the user to guess another letter.

52
03:24.970 --> 03:31.180
Now, at some stage of the game, all the letters will be guessed and then we can answer yes to this

53
03:31.180 --> 03:34.180
question, which means it's game over.

54
03:34.180 --> 03:38.260
The user has won because they've guessed all the letters correctly.

55
03:38.410 --> 03:45.070
Now, if we go back to the part where we asked the user to guess a letter and they guessed a letter,

56
03:45.070 --> 03:49.600
say the letter Z, which doesn't actually exist in this word mouse.

57
03:49.690 --> 03:57.280
Well then, in this case, we go down this right path to answer No, and the user loses a life, which means

58
03:57.280 --> 03:59.920
we start drawing out our hangman figure.

59
04:00.880 --> 04:06.970
Now, depending on whether if they have run out of lives, if the hangman has been drawn completely,

60
04:06.970 --> 04:08.530
then they would go down this path.

61
04:08.530 --> 04:13.150
But at the moment they've only lost one life and this figure is not complete.

62
04:13.150 --> 04:14.920
So the answer is No.

63
04:14.920 --> 04:19.120
And that means we go back to the beginning and we get them to guess the next letter.

64
04:19.150 --> 04:25.880
Now, if at the stage where they've exhausted all of their lives and the hangman figure is complete,

65
04:25.880 --> 04:28.100
well then it's the end of the game,

66
04:28.100 --> 04:34.160
and they've basically just lost without having guessed all of the letters in the word.

67
04:34.280 --> 04:39.980
So this is the logic, and you might need to come back to this video a few times if you get stuck along

68
04:39.980 --> 04:43.490
the way just to review how the programme flows.

69
04:43.490 --> 04:49.760
But it might also be worth creating your own flowchart chart or simply downloading this completed flow

70
04:49.760 --> 04:52.490
chart I have here in the Course Resources.

71
04:52.490 --> 04:58.940
It's a really useful tool to come back to and refer to as you're writing the code, because this will

72
04:58.940 --> 05:04.550
give you an overview of what you're trying to get your code to do, and hopefully this is going to make

73
05:04.550 --> 05:08.720
it easier for you to complete the upcoming challenges in this project.

74
05:08.720 --> 05:12.620
Once you're ready, head over to the next lesson, and let's get started.