This tutorial shows you how to make a rock paper scissors game in Scratch, with a player who chooses using the keyboard, a computer opponent that picks at random, and a judge that announces the result. By the end you’ll have a working two-sprite game that uses variables, selection and broadcast messages, which makes it a useful worked example for upper Key Stage 2 computing.

The game takes around 20 to 30 minutes to build the first time. You’ll need a free Scratch account at scratch.mit.edu, or the Scratch desktop app.

What the game does

When the green flag is clicked, both sprites cycle through rock, paper and scissors. The player can press any key to stop on a random choice, or press R, P or S to pick rock, paper or scissors. At the same moment the computer stops on its own choice. A judge script compares the two and broadcasts one of three messages: win, lose or draw. A results sprite picks up that message and shows it on screen.

In National Curriculum terms, the project covers working with variables and keyboard input, using selection (the “if” blocks) and repetition, and debugging a program with several sprites talking to each other.

Before you start: the sprites

You need one sprite with three costumes, in this order:

1. Rock

2. Paper

3. Scissors

The order matters, because the game uses the costume number (1, 2 or 3) to decide what has been picked. I made my sprite from Canva clip art, and here’s a separate video showing how to do that`. You can also draw the three costumes in Scratch’s own paint editor.

You’ll also need a results sprite with three costumes named win, lose and draw. Mine is simply text in a white box: “You win”, “You lose” and “Draw”.

Step 1: Set up the stage and sprites

1. Start a new project. Right-click the Scratch Cat and choose delete.

2. Click Choose a Backdrop and pick something suitable. I used the playing field backdrop

3. Hover over Choose a Sprite and click Upload Sprite. Choose your rock paper scissors sprite. Rename it Player 1.

4. Right-click the sprite and choose duplicate. Rename the copy Computer.

5. Position the sprites either side of the centre. I set Player 1 to x: -110, y: -60 and Computer to x: 105, y: -60, so they sit level.

Step 2: Create the variables and messages

1. Open the Variables category and click Make a Variable. Call it player one.

2. Make a second variable called computer. Untick the box next to it so its value doesn’t appear on the stage; otherwise the player can see the computer’s choice.

You’ll create four broadcast messages as you go: judge, win, lose and draw. To make a new message, click the drop-down on a broadcast block and choose New message.

Step 3: Code the player

Select the Player 1 sprite and build this script:

The key pressed? block is in Sensing, pick random is in Operators and costume number is in Looks. While no key is pressed, the sprite flicks between costumes. As soon as any key is pressed, it stops, records which costume it landed on, and tells the judge.

Next, give the player a proper choice. Build three short scripts:

The quickest way is to build the R script, then right-click it and choose duplicate twice, changing the key and costume each time.

Click the green flag to test. The sprite should cycle, stop on a random choice when you press a key, and show the right picture when you press R, P or S.

Step 4: Code the computer

Select the Computer sprite and build:

Both sprites listen for the same key press, so they stop at the same moment.

Step 5: Build the judge

This is the fiddliest part, because it uses if blocks inside if blocks. Once the first set is done, the other two are copies with different numbers.

On the Computer sprite, start with when I receive judge. The logic for when the player picks rock (player one = 1) looks like this:

– if < player one = 1 > then

  – if < computer = 1 > then broadcast draw

  – if < computer = 2 > then broadcast lose

  – if < computer = 3 > then broadcast win

The = block is in Operators. Drag the player one and computer variables into its left-hand side and type the number on the right.

The full set of outcomes:

Duplicate the rock block twice and change it for paper (player one = 2) and scissors (player one = 3), using the table for the results. Snap the three outer if blocks together one after another, put the whole stack inside a forever loop, and attach it under when I receive judge.

Step 6: Add the results sprite

Upload your results sprite and give it four scripts:

The message stays hidden until a result comes in, and disappears again when you click the green flag.

Testing and fixing

Click the green flag and play a few rounds, using both a random key and R, P and S. Check each result against the table.

If the result doesn’t match what the computer sprite is showing, change the computer’s set computer to block so it uses costume number instead of pick random 1 to 3. The variable then always matches the picture on screen. This makes a good debugging task for a class: show them the mismatch and ask them to find the cause.

Getting started

If you’re using this with a class, I’d suggest building it over two lessons: the player and computer sprites in the first, and the judge and results in the second. Pupils who finish early can add a score counter with two more variables, or a sound for each result.

The finished project is on Scratch so you can look inside and compare it with your own.

Next step

To make your own rock, paper and scissors costumes rather than drawing them in Scratch, watch the video on creating Scratch sprites in Canva

How to Make a Rock Paper Scissors Game in Scratch
The Whiteboard Blog – Education, Technology, AI and Science CPD and Support