1
00:00:00,610 --> 00:00:04,150
All right guys. So before we get started with our project,

2
00:00:04,420 --> 00:00:09,420
it's really important that we're all on the same page and we understand how the

3
00:00:09,550 --> 00:00:13,660
code is going to work because we know how the game works.

4
00:00:14,290 --> 00:00:17,440
So I recommend that if you've never heard of this game hangman,

5
00:00:17,740 --> 00:00:22,600
then before you continue to just head over to the Wikipedia article on hangman,

6
00:00:22,960 --> 00:00:26,290
and it might be even easier if you select your own language

7
00:00:26,560 --> 00:00:30,340
because I know that it has a different name in different languages. Now,

8
00:00:30,340 --> 00:00:31,840
if you've never played this game,

9
00:00:31,840 --> 00:00:35,350
I always recommend just go and give it a go online.

10
00:00:35,590 --> 00:00:39,910
So a link to this address, and if you click on single player untimed,

11
00:00:40,390 --> 00:00:43,480
you can see that you have a word that you have to guess,

12
00:00:43,810 --> 00:00:47,410
and then you start picking some letters. And if it's right,

13
00:00:47,410 --> 00:00:49,930
then it goes in and if it's wrong,

14
00:00:49,960 --> 00:00:54,960
then the hangman gallows start being drawn and our little man is at risk of

15
00:00:56,380 --> 00:00:59,740
being hung. Once you understand how the game works,

16
00:00:59,770 --> 00:01:03,610
it's time for us to examine what the logic for our program is going to look

17
00:01:03,610 --> 00:01:07,540
like. And to do that, we're going to use flow chart programming.

18
00:01:07,570 --> 00:01:08,980
So it's very simple.

19
00:01:09,280 --> 00:01:14,280
It just means that we can draw out a flow chart to represent the logic of our

20
00:01:14,500 --> 00:01:16,690
game. At this point,

21
00:01:16,750 --> 00:01:21,190
I want you to pause the video and have a quick think about how you would program

22
00:01:21,190 --> 00:01:22,023
hangman.

23
00:01:22,210 --> 00:01:25,690
Try and come up with a flow chart that represents the logic of this game.

24
00:01:26,230 --> 00:01:29,470
Break it down into little steps. What needs to happen first,

25
00:01:29,710 --> 00:01:33,250
what needs to happen when the user makes a guess, and what should happen when the

26
00:01:33,250 --> 00:01:37,240
guest is incorrect, when should the game end? Pause the video

27
00:01:37,240 --> 00:01:42,130
now, take a pencil and a piece of paper, or use draw.io to create your flowchart.

28
00:01:42,480 --> 00:01:43,313
Right?

29
00:01:46,010 --> 00:01:48,860
So how did that go? Did you break down the problem?

30
00:01:49,400 --> 00:01:52,640
It's really important to say that there's no single right answer here.

31
00:01:53,030 --> 00:01:55,820
And there's loads of ways that you could have done this,

32
00:01:56,180 --> 00:01:57,800
but let me show you my approach,

33
00:01:57,920 --> 00:02:01,070
which is how we'll write our program over the next couple of lessons.

34
00:02:02,570 --> 00:02:05,570
So this is what it looks like from start to end.

35
00:02:05,990 --> 00:02:09,530
And if we zoom in a bit, let's go through this flow chart

36
00:02:09,530 --> 00:02:13,580
step-by-step so we're all on the same page. At the start of the game

37
00:02:13,580 --> 00:02:18,410
the first thing we do is to generate a random word. Let's say, in this case

38
00:02:18,410 --> 00:02:19,760
it was the word mouse.

39
00:02:20,270 --> 00:02:25,270
Now the next step is to generate as many blanks as the letters in the word.

40
00:02:25,910 --> 00:02:28,610
So we have these blanks to show the user

41
00:02:28,790 --> 00:02:33,140
how many letters are in this word that they need to guess. They don't get to see

42
00:02:33,140 --> 00:02:37,100
this, but they get to see this. And the next step they get to 

43
00:02:37,130 --> 00:02:38,360
guess a letter.

44
00:02:38,900 --> 00:02:43,130
So let's say the user in this case guessed the letter O. Well,

45
00:02:43,130 --> 00:02:47,960
the next thing we have to check is, is the guessed letter actually in the word?

46
00:02:48,440 --> 00:02:51,050
Well, in this case, o it is indeed in mouse.

47
00:02:51,050 --> 00:02:52,790
It's the one at the second position.

48
00:02:53,330 --> 00:02:58,070
And so we go down this path and we answer yes to that question.

49
00:02:58,430 --> 00:03:02,350
So now we to replace that blank with the letter O.

50
00:03:03,940 --> 00:03:08,940
Now the next stage is we have to check are the blanks filled, are all of these

51
00:03:09,160 --> 00:03:11,260
blanks removed because in that case,

52
00:03:11,260 --> 00:03:15,820
it means the user is guessed all of the letters correctly? Well at the moment,

53
00:03:16,060 --> 00:03:19,300
it's definitely a no, cause we've only guessed one letter.

54
00:03:19,690 --> 00:03:23,800
So then we go all the way back to the beginning and we ask the user to guess

55
00:03:23,860 --> 00:03:27,040
another letter. Now at some stage of the game,

56
00:03:27,070 --> 00:03:31,840
all the letters will be guessed. And then we can answer yes to this question,

57
00:03:32,320 --> 00:03:36,940
which means it's game over. The user has won because they've guessed all the

58
00:03:36,940 --> 00:03:39,100
letters correctly. Now,

59
00:03:39,250 --> 00:03:43,180
if we go back to the part where we ask the user to guess a letter,

60
00:03:43,570 --> 00:03:46,510
and they guessed a letter, say the letter z

61
00:03:46,630 --> 00:03:51,250
which doesn't actually exist in this word mouse, while then in this case,

62
00:03:51,280 --> 00:03:54,160
we go down this right path to answer no

63
00:03:54,730 --> 00:03:56,650
and the user loses a life,

64
00:03:56,800 --> 00:04:01,630
which means we start drawing out a hangman figure. Now,

65
00:04:01,870 --> 00:04:04,690
depending on whether if they have run out of lives,

66
00:04:04,750 --> 00:04:08,620
if the hangman man has been drawn completely, then they would go down this path.

67
00:04:08,650 --> 00:04:13,180
But at the moment they've only lost one life and this figure is not complete

68
00:04:13,210 --> 00:04:14,710
so the answer is no.

69
00:04:15,250 --> 00:04:18,430
And that means we go back to the beginning and we get them to guess the next

70
00:04:18,430 --> 00:04:19,779
letter. Now,

71
00:04:19,839 --> 00:04:24,400
if at the stage where they've exhausted all of their lives and the hangman

72
00:04:24,400 --> 00:04:28,120
figure is complete, well, then it's the end of the game

73
00:04:28,330 --> 00:04:32,140
and they've basically just lost without having guessed

74
00:04:32,230 --> 00:04:35,950
all of the letters in the word. So this is the logic,

75
00:04:35,980 --> 00:04:38,500
and you might need to come back to this video a few times

76
00:04:38,830 --> 00:04:43,270
if you get stuck along the way just to review how the program flows.

77
00:04:43,690 --> 00:04:48,690
But it might also be worth creating your own flow chart or simply downloading

78
00:04:48,820 --> 00:04:52,270
this completed flowchart I have here in the course resources.

79
00:04:52,810 --> 00:04:57,640
It's a really useful tool to come back to and refer to as you're writing the

80
00:04:57,640 --> 00:04:58,390
code,

81
00:04:58,390 --> 00:05:02,170
because this will give you an overview of what you're trying to get your code to

82
00:05:02,170 --> 00:05:03,003
do.

83
00:05:03,010 --> 00:05:06,700
And hopefully this is going to make it easier for you to complete the upcoming

84
00:05:06,700 --> 00:05:11,350
challenges in this project. Once you are ready, head over to the next lesson,

85
00:05:11,500 --> 00:05:12,520
and let's get started.

