Rock Paper Scissors

Challenge

In this game, we’ll learn one way to implement the Rock Paper Scissors game for the micro:bit. We’ll draw images for each of the objects, react to a gesture from the play then use the python random function to pick one of the objects. In this version the micro:bits are not aware of each other’s selection so it is up to the players to decide who wins.

Notes

Extensions

Example Solution


from microbit import *
import random

rock     = Image("00000:09990:90009:92229:29992")
paper    = Image("99950:90992:90092:90092:99992")
scissors = Image("90009:09090:00900:55055:55055")
rock_paper_scissors = [ rock, paper, scissors ]

display.show(rock_paper_scissors, delay = 500)

display.clear()

while True:

  if accelerometer.was_gesture("shake"):   
	  one_of_them = random.choice(rock_paper_scissors)
		display.show(one_of_them)
		sleep (3000)
    display.clear()