← Code

Objects with turtles

Build a falling-stars game with lots of turtles.

Start1. Many turtles
For teachers Usually Years 9–10 · 5 lessons

Build a falling-stars game with many turtles, and tidy it step by step: from separate variables to lists, dictionaries and classes.

  • Usually Years 9–10
  • Lessons 5
  • Do first Console bridge: text in, text out
Teacher guide

Standards, in general: main focus: Trace algorithms for errors (8P06), Model structured data (8P03), Implement modular programs with OOP (10P09); touches on: Model and query entities and relationships (10P03). What this means

Many things on screen

Many turtles at once, then lists and dictionaries to keep track of them.

1Many turtlesNot started

Make more turtles with Turtle(), give each one its own commands, and find out what a game with several stars costs in code.

  1. Predict
  2. Run
  3. Investigate › Match the lines
  4. Investigate › Count the cost
  5. Investigate › Spot the bug
  6. Modify › A blue star
  7. Modify › A fourth star
  8. Make a rock
  9. Where this leads
Start lesson
2Lists of starsNot started

Keep the stars in a list and their speeds and points in lists beside it, so one loop moves them all, and find out why lists side by side are fragile.

  1. Predict
  2. Run
  3. Investigate › Eight stars
  4. Investigate › Same place, same star
  5. Investigate › Spot the bug
  6. Modify › Six stars
  7. Modify › Different points
  8. Make a bad star
  9. Where this leads
Start lesson
3One dictionary per starNot started

Classes

Make your own kind of object with class, then give it methods: one line adds another star.

4A Star classNot started
5Stars that move themselvesNot started

Progress is saved in this browser only. Nothing is sent anywhere.

For teachers: Teacher guide (notes, answers, solutions, slides and worksheets)