Hey guys, welcome to Day 20 of 100
Days of Code. Today
is really exciting because we're going to be using the knowledge that we've
gained about Object Oriented Programming
as well as what we learned about how to use the turtle module to build the
famous snake game. Now,
this is probably one of the most famous mobile games that ever was,
and it's definitely one of my favorite. And my history with it goes back all the
way to my very first mobile phone,
the Nokia 3310. It might be showing my age a little bit here,
but this was my first ever mobile phone.
I remember loving it so much that I actually had it next to my pillow when I
went to sleep. And this was probably one of the first affordable mobile phones.
And it was endlessly customizable with different cases and different keys.
But the most exciting thing about it
was the snake game. I would compare
with my friends and see who got the highest score in snake
and we would spend days and days playing this game. And compared to the iPhone
games of today, of course, this was very, very simple, but nonetheless,
it is still super addictive. Over the next two days
this is the game that we're going to build. A snake game that has,
um, a moving snake, which you control using your keyboard,
and you can go and get food,
and then it grows in length as it eats more food.
And you have to make sure that you don't end up getting tangled or hitting the
wall.
And the goal is to eat as much food as you can while staying alive.
There are some people who are truly masters at this game, um,
which I personally am not,
but they managed to get their snakes to crazy lengths and start having these
strategies for how you can avoid hitting your tail and how you can keep going.
So once you've built your snake game, you'll be able to play with it,
and you'll be able to show off your high scores to the rest of us,
but I'm sure you're going to do a lot better than me.
It's not that hard to beat me at snake. As always,
when we're thinking about a complex problem
the first step is to break down the problem.
And I'm going to break down this problem of building the snake game into seven
separate steps.
And the way we're going to do it is we're going to tackle the first three steps
on Day 1 and the last four steps on Day 2.
So we're going to split up this game into two parts and we're going to tackle it
over two days. The first step is to create a snake body,
and we're going to do that by creating three squares on the screen,
all lined up next to each other.
And then we're going to figure out how to move the snake so that it continuously
moves forward
and all we have to do is tell it to change direction. Afterwards,
we're going to figure out how to control the snake using keyboard controls.
So we're going to be using the up, left, down, and right arrow keys to move our
snake across the screen.
And that is what we're aiming for by the end of today,
Day 20. On Day 21,
we're going to continue and we're going to build out the last four steps of the
snake game.
Then we'll need to start putting some food onto the screen and started to detect
the collision with the food so that once the snake hits the food,
then a new piece of food gets created randomly on the screen at some sort of
random location.
And then it's a matter of keeping track of the score and creating a scoreboard.
So we're going to learn how to write text in our program so that once the snake
hits a piece of food, the score automatically updates.
And then next we're going to figure out when the game should end.
So one of the cases when the game should end is when the snake has collided with
the wall. And at this point we should see game over,
show up on screen and the snake should no longer move.
And then finally,
the other reason why our game could end is when the snake has collided with its
own tail. So the snake basically can't chase his own tail.
And as the snake gets longer, this problem is more likely to occur.
And when their head hits any part of the body of the snake, then it's again,
game over. So these are the seven steps
that it takes to create the snake game.
And once you're ready, we're gonna get started with step one on the next lesson.
So I'll see you there.