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?
Worked examples
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 see
Sprite to check
the bee does not move
the bee
the flower does not change when clicked
the flower
The symptom tells us which sprite to check. Then we compare its script with its algorithm.
Presses
Bee 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?
Answers vary. For example: when the game starts (the duck goes to its start place), when an arrow key is pressed (the duck moves) and when the fish is clicked (the fish changes).
2
The algorithm says: when the bee is clicked, say “Buzz!” for 2 seconds. What is the bug?
The hat block is wrong. The script starts with the green flag, but it should start with when this sprite clicked.
3
A sprite starts at x: −60. Each press of the space key changes x by 15. Where is it after 4 presses?
−60 + 15 × 4 = −60 + 60 = 0.
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.
Run the program and watch, spot the line that does not match, fix that line, run it again to check.