1
Break the task into parts
Computing 2: Unit 1, pp. 8–23
GoalBreak a task into smaller parts: a background, a character and an action.
New words
task · a job that you want to get donebackground · the picture behind the characterscharacter · a person or animal in a program
Explanation
Before we write code, we break the task into smaller parts. Here is a task: a duck spins when you tap it. Part 1 is the background. Part 2 is one character, the duck. Part 3 is one action, the spin. Small parts are easier to plan than one big job. Then we can write the algorithm.
Worked examples
Task: a frog hops across the screen. The parts are a pond background, one frog character and one action, which is hop.
Task: a bus drives along a road and says hello. This task has two actions: drive and say hello. We plan one action at a time and test each one.
A big game is made of many small parts, such as backgrounds, characters and actions. A programmer builds and tests one part at a time.
Class activity
Paper theatre: draw a background on a sheet of paper, for example a garden. Cut out one character from another piece of paper and write one action for it on a card, such as hop 3 or spin around. Slide the character over the background and act out the action. Swap with a friend. Can they say which part is the background, which is the character and which is the action?
Practice
1
A programmer wants a bird to fly to the right when you tap it. Name the background, the character and the action.
For example: the background is the sky, the character is the bird and the action is move right.
2
Task: a kite spins around in the sky. Which picture card is the background, which is the character and which is the action?
A is the background, B is the character, C is the action.
3
Why do programmers break a task into parts?
Small parts are easier to plan and test than one big job.
4
Look at the blocks for a cat. How many actions does the cat do?
One. It hops 2 and then the program ends.