Lists Review & Radio Communication

📊 Workshop Slides

Review: Heads Guess! Game Plan

Let’s review what we built last week! The Heads Guess! game:

  1. Create a list of words to guess
  2. Start a 30-second countdown
  3. When tilted up (logo up): show a random word
  4. When tilted down (screen down): add a point (correct!)
  5. When tilted back (screen up): lose a life (pass)

Step 1: Start the Countdown ⏱️

We want 30 seconds to play the game.

game.start_countdown(30000)

Why 30000? Time is in milliseconds! 30 seconds × 1000 = 30,000 milliseconds

Step 2: Create Word List

Let’s make a list of words to guess!

wordList = ["PUPPY", "CLOCK", "NIGHT"]
game.start_countdown(30000)

Try it yourself: Add more words to make the game more fun! Ideas: “DANCE”, “PIZZA”, “OCEAN”, “ROBOT”

Step 3: Get New Word Gesture

When the micro:bit logo points up, we want to show a new word.

def on_logo_up():
    # We'll add code here!

input.on_gesture(Gesture.LOGO_UP, on_logo_up)

This is the gesture for “show me the next word!”

Step 4: Pick Random Index

Inside the function, pick a random word from our list:

def on_logo_up():
    index = randint(0, len(wordList) - 1)

Why len(wordList) - 1? If we have 3 words, valid indices are 0, 1, 2!

Step 5: Show the Random Word

Now display the word at that random index:

def on_logo_up():
    index = randint(0, len(wordList) - 1)
    basic.show_string(wordList[index])

The word will scroll across the screen!

Step 6: Correct Guess! ✓

When the player guesses correctly, they tilt screen down.

def on_screen_down():
    # Add code here!

input.on_gesture(Gesture.SCREEN_DOWN, on_screen_down)

What should happen when they guess correctly?

Step 7: Add a Point! 🎯

When they guess correctly, give them a point!

def on_screen_down():
    game.add_score(1)

The micro:bit will keep track of their score automatically!

Step 8: Pass Gesture

When the player wants to pass (skip a word), they tilt screen up.

def on_screen_up():
    # Add code here!

input.on_gesture(Gesture.SCREEN_UP, on_screen_up)

But passing should have a consequence…

Step 9: Lose a Life 💔

If you pass, you lose a life!

def on_screen_up():
    game.remove_life(1)

This encourages players to keep trying!

Complete Code! 🎉

wordList = ["PUPPY", "CLOCK", "NIGHT", "DANCE", "PIZZA"]

def on_logo_up():
    index = randint(0, len(wordList) - 1)
    basic.show_string(wordList[index])

def on_screen_down():
    game.add_score(1)

def on_screen_up():
    game.remove_life(1)

input.on_gesture(Gesture.LOGO_UP, on_logo_up)
input.on_gesture(Gesture.SCREEN_DOWN, on_screen_down)
input.on_gesture(Gesture.SCREEN_UP, on_screen_up)

game.start_countdown(30000)

Time to Play! 🎮

Download your code to the micro:bit!

How to play:

  1. Partner up - one guesser, one clue-giver
  2. Guesser holds micro:bit on forehead
  3. Tilt logo up to see a new word
  4. Clue-giver gives hints (no saying the word!)
  5. Tilt screen down when guessed correctly
  6. Tilt screen up to pass
  7. You have 30 seconds - go!

Challenge: More Words! 📝

Add at least 10 more words to your list.

Categories to try:

Make the game harder and more fun!


Key Concepts Review ✨

From last week, you learned:

  1. Lists - Collections that hold multiple items
  2. Indexing - Accessing items (starts at 0!)
  3. List length - len(list) tells you how many items
  4. Random selection - randint(0, len(list) - 1)
  5. Gestures - Tilting micro:bit to control games
  6. Game functions - add_score(), remove_life()

Why Lists Matter 💡

Lists let you:

They’re one of the most important tools in programming!

References and Acknowledgements