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.

  1. 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

  2. Last unit

    word = "Python". What is word[1:4]?

    A "Pyth"B "ytho"C "yth"

    C. "yth"

  3. 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.

e.g.Example

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)

  1. The poster has one clear message.
  2. Every image has a credit line.
  3. The player moves with the arrow keys.
  4. The game has a score and an ending.
  5. The game tells the player one fact about the cause.
  6. 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)

PartWhat it does
Bin (the player)Moves left and right with the arrow keys
LitterFalls from a random place at the top of the stage
ScoreGoes up by 1 when the bin catches the litter
LivesGo down by 1 when the litter reaches the sand
EndingAt 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
end

The explanation · step 3 of 4 · part 3 of 3

Build in small steps (continued)

  1. The litter starts at a random spot along the top.
  2. Each time round the loop, it falls 5 steps.
  3. Caught by the bin? Score goes up and the litter jumps back to the top.
  4. Reached the bottom? Lives go down and the litter jumps back to the top.
★Remember

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.

e.g.Example

Lesson 4: the bin moves and the litter falls. Problem: the litter falls too fast. Next: slow it down, then add lives.

?Why?

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?

  1. Bin first: you need a player to test everything else. Test that the arrow keys move it.
  2. Litter next: test that it falls from a new random place each time.
  3. Score: test that catching the litter adds exactly 1.
  4. Lives: test that a miss takes away exactly 1.
  5. 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?

  1. A Rectangle
  2. B Parallelogram
  3. 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…

  1. A Decomposition
  2. B Iteration
  3. 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…

  1. A Iteration
  2. B Selection
  3. 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.

  1. In a flowchart, a decision is a…

    A OvalB RectangleC Diamond

    C. Diamond Diamonds have yes/no arrows coming out.

  2. 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.