A short lesson to introduce writing functions
a short lesson to introduce writing functions
Event
Activities tracked
7
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:
Full details on the six week course here.
Sessions & talks
Showing 1–7 of 7 · Newest first
a short lesson to introduce writing functions
check if the snake has moved off the screen and end the game if so
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.
a recap and explanation of the current code (as a reminder and a brief introduction for anybody joining the course for the first time)
refactor the code and write a few functions: for example, to draw the snake, and to change the snake's direction
restrict the snake’s movement so that it cannot double-back on itself