AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Term 3 review

Week 30 · Review: Term 3 · 3 lessons
2

Games and debugging

Computing 3: Units 9–12, pp. 135–193
GoalReview how to break a game into sub-tasks, and how to test and debug it.
New words
sub-task · a smaller job that is part of a bigger jobdebug · to find and fix errors in a programevaluate · to check that the program matches the plan
Explanation

A game developer breaks a game into sub-tasks, such as what happens when the game starts, when a key is pressed and when a sprite is clicked. Each sub-task gets its own algorithm and its own script. We test the program and compare it with the algorithms. If something is wrong, we find which sprite and which block does not match, we fix it and we test again. Common errors are an empty number box, a wrong number, a wrong key and blocks in the wrong order. At the end we evaluate the game: does the program match the plan?

When the gamestartsWhen an arrowkey is pressedWhen the floweris clickedBee game
Worked examples
whenright arrowkey pressedchange x by200
The algorithm says: when the right arrow key is pressed, change x by 20. The program has 200, so the bee leaps far across the stage with one press instead of taking a small step. The bug is the wrong number. We change 200 to 20 and test again.
What we seeSprite to check
the bee does not movethe bee
the flower does not change when clickedthe flower
The symptom tells us which sprite to check. Then we compare its script with its algorithm.
PressesBee x
0−150
2−110
4−70
6−30
Test with numbers. The bee starts at x: −150. Each press of the right arrow adds 20. After 6 presses the bee is at −150 + 120 = −30.
Class activity

Game doctor (in pairs): one of you draws a small plan for a two-sprite game with two algorithms. The other builds the program on paper, with the blocks on cards, and one card is wrong on purpose. The doctor tests the paper program, finds the wrong card, fixes it and tests again. Say the four debugging steps out loud as you go: run, spot, fix, run again. Then swap.

Practice
1
The bee game is split into three sub-tasks. How would you name the sub-tasks for a new game with a duck and a fish?
duckfish
2
The algorithm says: when the bee is clicked, say “Buzz!” for 2 seconds. What is the bug?
whenclickedsayBuzz!for2seconds
3
A sprite starts at x: −60. Each press of the space key changes x by 15. Where is it after 4 presses?
Startwhenclickedgo to x:-60y:0Presswhenspacekey pressedchange x by15
4
Put the steps of debugging in the right order: spot the line that does not match · run it again to check · fix that line · run the program and watch.