Year 7 · Summer 2
Raid: Code for a Cause · Lesson 4 of 5
Raid build: poster plus Scratch mini-game
ProjectTopic 11 Algorithms
Year 7 · Raid: Code for a Cause · Lesson 4 of 5
You will learn to
- Create a success list with your guild before anyone starts building.
- Use decomposition to split the game into parts, and the work between two pairs.
- Create a Scratch mini-game in small steps, testing after each one.
Year 7 · Raid: Code for a Cause · Lesson 4 of 5
Success criteria
You have got it when you can say:
- I can say what 'finished' means, using our success list.
- I can show my part of the project working after each small step.
- I can write a short log of what I did today and what comes next.
Year 7 · Raid: Code for a Cause · Lesson 4 of 5
Retrieval starter
Questions from before. Write your answers, then show them.
- Last lesson
Logging into a friend's account 'just to look' is…
A Fine if you don't change anythingB Against the Computer Misuse Act
B. Against the Computer Misuse Act
- Last unit
word = "Python". What is word[1:4]?
A "Pyth"B "ytho"C "yth"
C. "yth"
- Earlier this year
Every spreadsheet formula starts with…
A #B =C $
B. =
Year 7 · Raid: Code for a Cause · Lesson 4 of 5
Key words (1 of 2)
- Algorithm
- Precise, ordered, finite steps to solve a problem.
- Decomposition
- Breaking a problem into smaller ones.
- Abstraction
- Ignoring detail that doesn't matter for the problem.
- Sequence · selection · iteration
- Steps one after another. First this, then this.
Year 7 · Raid: Code for a Cause · Lesson 4 of 5
Key words (2 of 2)
- Pseudocode
- Code-like writing for algorithms, without strict rules.
- Trace table
- Records variable values step by step to check logic.
- Variable
- A named place in memory that holds a value.
The explanation · step 1 of 4 · part 1 of 2
Start with a success list
A success list says what 'finished' looks like. The guild agrees it before anyone builds.
Each line must be something you can check: yes, it does that, or no, it does not.
Cause: keep our beaches clean. Here is that guild's success list.
The explanation · step 1 of 4 · part 2 of 2
Start with a success list (continued)
- The poster has one clear message.
- Every image has a credit line.
- The player moves with the arrow keys.
- The game has a score and an ending.
- The game tells the player one fact about the cause.
- Another guild has tested the poster and the game.
The explanation · step 2 of 4 · part 1 of 2
Split the game into parts
Two people make the poster. Two people make the game. Both pairs follow the same success list.
The game pair uses decomposition: they break the game into parts, one job each.
The explanation · step 2 of 4 · part 2 of 2
Split the game into parts (continued)
| Part | What it does |
|---|---|
| Bin (the player) | Moves left and right with the arrow keys |
| Litter | Falls from a random place at the top of the stage |
| Score | Goes up by 1 when the bin catches the litter |
| Lives | Go down by 1 when the litter reaches the sand |
| Ending | At 0 lives, says 'Game over' and one fact about the cause |
The explanation · step 3 of 4 · part 1 of 3
Build in small steps
Build the bin first and test it. Then the falling litter. Then the score, then the lives. Test after every part.
Here is the litter script once the score and lives parts are added:
The explanation · step 3 of 4 · part 2 of 3
Build in small steps (continued)
when green flag clicked
go to x: (pick random (-200) to (200)) y: (170)
forever
change y by (-5)
if <touching (Bin v)?> then
change [score v] by (1)
go to x: (pick random (-200) to (200)) y: (170)
end
if <(y position) < (-170)> then
change [lives v] by (-1)
go to x: (pick random (-200) to (200)) y: (170)
end
endThe explanation · step 3 of 4 · part 3 of 3
Build in small steps (continued)
- The litter starts at a random spot along the top.
- Each time round the loop, it falls 5 steps.
- Caught by the bin? Score goes up and the litter jumps back to the top.
- Reached the bottom? Lives go down and the litter jumps back to the top.
The Scratch stage runs from x = -240 to 240 and y = -180 to 180. So y = 170 is near the top.
The explanation · step 4 of 4
Keep a log
A log is a short diary of the project. Write two or three lines at the end of each lesson.
Lesson 4: the bin moves and the litter falls. Problem: the litter falls too fast. Next: slow it down, then add lives.
Why keep a log?
Next lesson you know where to start. And in the presentation you can say what you fixed.
Year 7 · Raid: Code for a Cause · Lesson 4 of 5
Worked example
Your game has five parts: bin, litter, score, lives and ending. In what order do you build them?
- Bin first: you need a player to test everything else. Test that the arrow keys move it.
- Litter next: test that it falls from a new random place each time.
- Score: test that catching the litter adds exactly 1.
- Lives: test that a miss takes away exactly 1.
- Ending last: it needs the lives to work. Test that the game stops at 0 lives.
Year 7 · Raid: Code for a Cause · Lesson 4 of 5
Quick quiz · 1 of 3
Which shape is used for OUTPUT total?
- A Rectangle
- B Parallelogram
- C Diamond
B. Parallelogram
Input and output are always parallelograms.
Year 7 · Raid: Code for a Cause · Lesson 4 of 5
Quick quiz · 2 of 3
Breaking a problem into smaller parts is…
- A Decomposition
- B Iteration
- C Abstraction
A. Decomposition
De-compose = take apart.
Year 7 · Raid: Code for a Cause · Lesson 4 of 5
Quick quiz · 3 of 3
An 'if… else…' is…
- A Iteration
- B Selection
- C Sequence
B. Selection
It selects one path.
Year 7 · Raid: Code for a Cause · Lesson 4 of 5
Exit ticket
Answer on paper before you go. Then check.
In a flowchart, a decision is a…
A OvalB RectangleC Diamond
C. Diamond Diamonds have yes/no arrows coming out.
The Tube map leaves out real distances. That's…
A DecompositionB AbstractionC Pattern recognition
B. Abstraction Abstraction removes detail that doesn't matter for the problem.