Treasure Hunt

Challenge

This game uses several microbits to create a treasure hunt game. Create a number of clues to the treasure and put them in the all_clues list. Program all but one of the microbits with the beacon code and set each one to a different number. Program the final microbit with the receiver code.

You might find that the transmitter beacons have their radio power set too high so that it’s too easy to find them. You can make it the hunt harder by reducing the power (see the example solution).

Requirements

Extensions

Adjust the power from each beacon to make it more challenging. If you are playing with more than one group in an area, consider changing the radio channel so the groups don’t interfere with each other.

Example Solution

Beacon


# Treasure Hunt beacon, broadcasts a text clue to be picked up by the
# treasure hunter.
# Change the clue by pressing the up or down (a or b) buttons

from microbit import *
import radio

all_clues = [
    "Walk Fifteen paces east",
    "Ten paces north",
    "Walk forwards",
    "Look under the seat",
    "Hooray, you win!"
]

clue_count = len(all_clues)
clue = 1

radio.on()
radio.config(power=4) # power is 0 -> 7
radio.config(channel=19) # customise the channel and match on the reciever

while True:
    # decrease clue number
    if button_a.was_pressed():
        clue = max(clue - 1, 1)
   # increase clue number
    elif button_b.was_pressed():
        clue = min(clue +  1, clue_count)

    # broadcast the current clue
    else:
        clue_text = str(clue) + ":" + all_clues[clue - 1]
        radio.send(clue_text)

    display.show(str(clue))
    sleep(1000)


Receiver


from microbit import *
import radio

# starting clue
clue = "hint: Walk around to find the first clue"
display.scroll(clue)
next_clue = 1

radio.on()

while True:
    display.show("?")

    # are we near any clue beacons?
    message = radio.receive()

    if message:
        # picked up a clue !
        number, text = message.split(":")
        # is it the one we want?
        if int(number) == next_clue:
            clue = "clue " + str(number) + ":" + text
            next_clue += 1
            display.scroll(clue)

    sleep(250)