In this assignment you and a partner will program two micro:bits to play the rock paper scissors game against each another.
Like the previous teleporting duck program, this one uses the micro:bit’s radio function to send data from one micro:bit to another when the accelerometer detects a shake gesture. The program first truns on the radio and sets its group. It doesn’t matter what group you pick as long as your partner’s micro:bit is using the same group number, and no-one else nearby is using the same group. When you shake your microbit, it randomly chooses rock, paper or scissors and sends it's choice on that radio group and clears. It compares it's choice with the other micro:bit's choice and displays whether it won, lost or tied.
Since both micro:bits send and receive, the code for both micro:bits will be the same.
- Your program will need at least three images that represent rock, paper and scissors
- Your program must use the micro:bit's accelerometer and radio features
- Each person will submit the Python code for their program and an animated gif showing the two programs running to Google Classroom
- Add code to import random, import the radio library, turn the radio on and set the group number
- Create three different images to represent rock, paper and scissors
- Create a variable
num
and initialize it to3
- Inside of the
while True:
write anif
statement that checks if the micro:bit was shaken. If the microbit has been shaken, clear the display and set thenum
variable to a random integer from 0 to 2. For each of the 3 random numbers from 0 to 2, display a different image. Useradio.send()
to send a message that indicates which of the three images was chosen. - Create a message variable, and store the received radio message
message = radio.receive()
- Inside of the
while True:
write anotherif
statementif message and num!=3:
Compare the received message with random number innum
and display whether the player won, lost or tied