1
00:00:00,510 --> 00:00:04,010
Hey guys, welcome to Day 20 of 100

2
00:00:04,010 --> 00:00:05,560
Days of Code. Today

3
00:00:05,680 --> 00:00:09,200
is really exciting because we're going to be using the knowledge that we've

4
00:00:09,200 --> 00:00:11,630
gained about Object Oriented Programming

5
00:00:11,990 --> 00:00:16,370
as well as what we learned about how to use the turtle module to build the

6
00:00:16,370 --> 00:00:18,830
famous snake game. Now,

7
00:00:18,830 --> 00:00:22,430
this is probably one of the most famous mobile games that ever was,

8
00:00:22,490 --> 00:00:27,490
and it's definitely one of my favorite. And my history with it goes back all the

9
00:00:28,760 --> 00:00:32,390
way to my very first mobile phone,

10
00:00:32,420 --> 00:00:37,280
the Nokia 3310. It might be showing my age a little bit here,

11
00:00:37,340 --> 00:00:40,580
but this was my first ever mobile phone.

12
00:00:40,890 --> 00:00:45,830
I remember loving it so much that I actually had it next to my pillow when I

13
00:00:45,830 --> 00:00:50,180
went to sleep. And this was probably one of the first affordable mobile phones.

14
00:00:50,270 --> 00:00:55,270
And it was endlessly customizable with different cases and different keys.

15
00:00:56,360 --> 00:00:58,640
But the most exciting thing about it

16
00:00:58,880 --> 00:01:01,090
was the snake game. I would compare

17
00:01:01,190 --> 00:01:04,489
with my friends and see who got the highest score in snake

18
00:01:04,730 --> 00:01:09,590
and we would spend days and days playing this game. And compared to the iPhone

19
00:01:09,590 --> 00:01:14,060
games of today, of course, this was very, very simple, but nonetheless,

20
00:01:14,060 --> 00:01:17,990
it is still super addictive. Over the next two days

21
00:01:18,110 --> 00:01:22,700
this is the game that we're going to build. A snake game that has,

22
00:01:22,760 --> 00:01:26,180
um, a moving snake, which you control using your keyboard,

23
00:01:26,630 --> 00:01:29,030
and you can go and get food,

24
00:01:29,300 --> 00:01:31,910
and then it grows in length as it eats more food.

25
00:01:32,240 --> 00:01:35,480
And you have to make sure that you don't end up getting tangled or hitting the

26
00:01:35,480 --> 00:01:36,170
wall.

27
00:01:36,170 --> 00:01:40,940
And the goal is to eat as much food as you can while staying alive.

28
00:01:41,600 --> 00:01:45,350
There are some people who are truly masters at this game, um,

29
00:01:45,410 --> 00:01:47,420
which I personally am not,

30
00:01:47,780 --> 00:01:52,430
but they managed to get their snakes to crazy lengths and start having these

31
00:01:52,430 --> 00:01:57,430
strategies for how you can avoid hitting your tail and how you can keep going.

32
00:01:58,100 --> 00:02:01,400
So once you've built your snake game, you'll be able to play with it,

33
00:02:01,550 --> 00:02:04,700
and you'll be able to show off your high scores to the rest of us,

34
00:02:04,910 --> 00:02:07,310
but I'm sure you're going to do a lot better than me.

35
00:02:07,700 --> 00:02:10,850
It's not that hard to beat me at snake. As always,

36
00:02:10,850 --> 00:02:13,040
when we're thinking about a complex problem

37
00:02:13,070 --> 00:02:16,340
the first step is to break down the problem.

38
00:02:16,940 --> 00:02:21,940
And I'm going to break down this problem of building the snake game into seven

39
00:02:22,040 --> 00:02:23,150
separate steps.

40
00:02:23,420 --> 00:02:26,660
And the way we're going to do it is we're going to tackle the first three steps

41
00:02:26,660 --> 00:02:30,470
on Day 1 and the last four steps on Day 2.

42
00:02:30,950 --> 00:02:34,730
So we're going to split up this game into two parts and we're going to tackle it

43
00:02:34,760 --> 00:02:39,680
over two days. The first step is to create a snake body,

44
00:02:40,070 --> 00:02:43,880
and we're going to do that by creating three squares on the screen,

45
00:02:44,270 --> 00:02:45,950
all lined up next to each other.

46
00:02:46,760 --> 00:02:51,290
And then we're going to figure out how to move the snake so that it continuously

47
00:02:51,290 --> 00:02:52,250
moves forward

48
00:02:52,460 --> 00:02:57,170
and all we have to do is tell it to change direction. Afterwards,

49
00:02:57,230 --> 00:03:01,300
we're going to figure out how to control the snake using keyboard controls.

50
00:03:01,570 --> 00:03:06,570
So we're going to be using the up, left, down, and right arrow keys to move our

51
00:03:07,240 --> 00:03:08,680
snake across the screen.

52
00:03:09,070 --> 00:03:12,520
And that is what we're aiming for by the end of today,

53
00:03:12,520 --> 00:03:14,920
Day 20. On Day 21,

54
00:03:15,070 --> 00:03:18,340
we're going to continue and we're going to build out the last four steps of the

55
00:03:18,340 --> 00:03:19,173
snake game.

56
00:03:19,630 --> 00:03:24,100
Then we'll need to start putting some food onto the screen and started to detect

57
00:03:24,100 --> 00:03:28,210
the collision with the food so that once the snake hits the food,

58
00:03:28,450 --> 00:03:33,400
then a new piece of food gets created randomly on the screen at some sort of

59
00:03:33,520 --> 00:03:34,570
random location.

60
00:03:35,410 --> 00:03:40,240
And then it's a matter of keeping track of the score and creating a scoreboard.

61
00:03:40,510 --> 00:03:45,430
So we're going to learn how to write text in our program so that once the snake

62
00:03:45,430 --> 00:03:48,970
hits a piece of food, the score automatically updates.

63
00:03:49,480 --> 00:03:52,870
And then next we're going to figure out when the game should end.

64
00:03:53,020 --> 00:03:58,020
So one of the cases when the game should end is when the snake has collided with

65
00:03:58,480 --> 00:04:02,470
the wall. And at this point we should see game over,

66
00:04:02,470 --> 00:04:06,430
show up on screen and the snake should no longer move.

67
00:04:06,910 --> 00:04:08,140
And then finally,

68
00:04:08,200 --> 00:04:12,880
the other reason why our game could end is when the snake has collided with its

69
00:04:12,880 --> 00:04:17,470
own tail. So the snake basically can't chase his own tail.

70
00:04:17,740 --> 00:04:21,610
And as the snake gets longer, this problem is more likely to occur.

71
00:04:22,060 --> 00:04:26,500
And when their head hits any part of the body of the snake, then it's again,

72
00:04:26,560 --> 00:04:29,860
game over. So these are the seven steps

73
00:04:29,890 --> 00:04:32,040
that it takes to create the snake game.

74
00:04:32,670 --> 00:04:37,440
And once you're ready, we're gonna get started with step one on the next lesson.

75
00:04:37,650 --> 00:04:38,340
So I'll see you there.

