alphaPlan · Programming in a Data World · Cheat-sheet 04
Build it
Assemble Turtle, loops, functions, lists and events into one small game that runs and that you can show to someone.
Ideas to remember
- 01The goal is a working game, not a polished one: a turtle that moves when you press a key, something to reach or avoid, and a way to win or lose.
- 02Choose one idea and stick with it; a finished small game beats an unfinished ambitious one.
- 03Build in milestones and run after each one, so you always have something that works.
- 04Every part you have learned is in the scaffold: a turtle stored in a variable, one small function per action, and event listeners that connect a key to a function.
- 05Keep the positions of food or walls in a list so you can add and remove them.
- 06In the presentation, show the game running first, then say what it does in one sentence, what was hardest, and what you would add next.
Words
- player.penup()
- Lifts the pen so the player square moves without leaving a line.
- player.sety(player.ycor() + step)
- Moves the player up by step pixels; setx and xcor do the same sideways.
- step = 20
- How far the player moves on each key press; make it bigger to move faster.
- place_food()
- Drops the food turtle at a random spot with random.randint(-9, 9) * 20.
- player.distance(food) < 20
- True when the player has reached the food; then the score goes up and the next food appears somewhere new.
Do this
- Design it on paper first: one or two sentences on what the game is, what the player does, and how you win or lose.
- Get one turtle moving with the arrow keys before adding anything else.
- Add the goal, then a score and an ending condition, then polish with colours, a title and a start message.
- Add check_food() to the end of each of your four move functions so every move checks for food.
- Change one thing at a time in the scaffold, such as step or the colours, and understand each change before reusing it.
Watch out
- Do not try to write the whole game at once; without small steps you lose the safety of always having something that works.
- It is fine if something is unfinished, but say what you would add next instead of hiding it.
- The showing matters, not only the code: leave time to present, not just to build.
Found something unclear, outdated or improvable? Suggest an improvement