Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from microbit import *
- import radio
- from random import randint
- radio.on()
- A = Image('00900:09000:90000:09000:00900:')
- B = Image('00900:00090:00009:00090:00900:')
- AB = Image('00900:09090:09990:09090:00900:')
- S = Image('09090:00909:09090:90900:09090:')
- my_player_num = "2"
- game_over = False
- def choose_action():
- pick = randint(1, 4)
- if pick == 1:
- display.show(A)
- elif pick == 2:
- display.show(B)
- elif pick == 3:
- display.show(AB)
- else:
- display.show(S)
- return pick
- def choose_next():
- next_player = str(randint(1, 3))
- display.scroll("next" + next_player)
- return next_player
- def check_response(action):
- start_timer = running_time()
- while running_time - start_timer < 5000:
- if action == 1 and button_a.was_pressed():
- return True
- if action == 2 and button_b.was_pressed():
- return True
- if action == 3 and button_a.was_pressed() and button_b.was_pressed():
- return True
- if action == 4 and accelerometer.was_gesture("shake"):
- return True
- return False
- while True:
- display.show(my_player_num)
- if button_a.was_pressed():
- while not game_over:
- next_player = my_player_num
- incoming = radio.receive()
- display.show(Image.TARGET)
- if incoming == my_player_num:
- choice = choose_action()
- correct = check_response(choice)
- if correct:
- display.show(Image.HAPPY)
- else:
- display.show(Image.SAD)
- sleep(2000)
- while next_player == my_player_num:
- next_player = choose_next()
- radio.send(next_player)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement