Advertisement
ForrisHilier

Untitled

Mar 22nd, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.81 KB | None | 0 0
  1. from microbit import *
  2. import radio
  3. from random import randint
  4.  
  5. radio.on()
  6.  
  7. A = Image('00900:09000:90000:09000:00900:')
  8. B = Image('00900:00090:00009:00090:00900:')
  9. AB = Image('00900:09090:09990:09090:00900:')
  10. S = Image('09090:00909:09090:90900:09090:')
  11.  
  12. my_player_num = "2"
  13. game_over = False
  14.  
  15.  
  16. def choose_action():
  17.     pick = randint(1, 4)
  18.     if pick == 1:
  19.         display.show(A)
  20.     elif pick == 2:
  21.         display.show(B)
  22.     elif pick == 3:
  23.         display.show(AB)
  24.     else:
  25.         display.show(S)
  26.     return pick
  27.  
  28.  
  29. def choose_next():
  30.     next_player = str(randint(1, 3))
  31.     display.scroll("next" + next_player)
  32.     return next_player
  33.  
  34.  
  35. def check_response(action):
  36.     start_timer = running_time()
  37.     while running_time - start_timer < 5000:
  38.         if action == 1 and button_a.was_pressed():
  39.             return True
  40.         if action == 2 and button_b.was_pressed():
  41.             return True
  42.         if action == 3 and button_a.was_pressed() and button_b.was_pressed():
  43.             return True
  44.         if action == 4 and accelerometer.was_gesture("shake"):
  45.             return True
  46.     return False
  47.  
  48.  
  49. while True:
  50.     display.show(my_player_num)
  51.     if button_a.was_pressed():
  52.         while not game_over:
  53.             next_player = my_player_num
  54.             incoming = radio.receive()
  55.  
  56.             display.show(Image.TARGET)
  57.  
  58.             if incoming == my_player_num:
  59.                 choice = choose_action()
  60.                 correct = check_response(choice)
  61.  
  62.                 if correct:
  63.                     display.show(Image.HAPPY)
  64.                 else:
  65.                     display.show(Image.SAD)
  66.  
  67.                 sleep(2000)
  68.  
  69.                 while next_player == my_player_num:
  70.                     next_player = choose_next()
  71.  
  72.                 radio.send(next_player)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement