Python Foundation Course (Session 4 of 6) - Writing Functions
Details
Our snake moves at a constant speed, and cannot turn back on itself like the classic snake in the game. The game stops if the snake moves off the screen.
This covers these Python topics: writing functions and refactoring code. We start preparing to make the snake into a class rather than a list.
This is the agenda:
- a recap and explanation of the current code (as a reminder and a brief introduction for anybody joining the course for the first time)
- a short lesson to introduce writing functions
- improve the geometry to think of the snake as moving over squares on a board, rather than pixels. This makes the subsequent tasks easier.
- make our snake move at constant speed in the direction of the latest arrow key pressed.
- restrict the snake’s movement so that it cannot double-back on itself
- check if the snake has moved off the screen and end the game if so
- refactor the code and write a few functions: for example, to draw the snake, and to change the snake's direction
Full details on the six week course here.
Python
