Advertisement
EpicShardGamingYT

RCP multiplayer

Mar 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.94 KB | None | 0 0
  1. from microbit import *
  2. import radio
  3. HasSent = False
  4. OponentVal = 0
  5. rock = Image("00000:"
  6.              "09990:"
  7.              "99999:"
  8.              "09990:"
  9.              "00000")
  10.              
  11. paper = Image("99999:"
  12.             "99999:"
  13.             "99999:"
  14.             "99999:"
  15.             "99999")
  16. scissors = Image("09090:"
  17.             "09090:"
  18.             "00900:"
  19.             "09090:"
  20.             "90009")
  21.  
  22. #Functions and code
  23. def printStr( str ):
  24.    "This prints a passed string into this function"
  25.    display.scroll (str)
  26.    return
  27.    
  28.    
  29.    
  30. def run():
  31.     radio.on()
  32.     ShowRock(1000)
  33.     ShowPaper(1000)
  34.     ShowScissors(1000)
  35.    
  36. def ShowRock( time ):
  37.     display.show(rock)
  38.     sleep(time)
  39.     display.clear()
  40.    
  41. def ShowPaper( time ):
  42.     display.show(paper)
  43.     sleep(time)
  44.     display.clear()
  45.    
  46. def ShowScissors( time ):
  47.     display.show(scissors)
  48.     sleep(time)
  49.     display.clear()
  50.    
  51.    
  52.    
  53. def ShowOponent():
  54.     if OponentVal == "1" or OponentVal == "2" or OponentVal == "3":
  55.         if OponentVal == "1":
  56.             ShowRock(1000)
  57.         if OponentVal == "2":
  58.             ShowPaper(1000)
  59.         if OponentVal == "3":
  60.             ShowScissors(1000)
  61.    
  62.    
  63. #loop
  64. def loop():
  65.     global HasSent
  66.     global OponentVal
  67.     inputPin = radio.receive()
  68.     #Anti signal block/DDos
  69.     if str(inputPin) == "0" or str(inputPin) == "1" or str(inputPin) == "3":
  70.         ConInput = str(inputPin)
  71.         if conInput == "0":
  72.             if HasSent == True:
  73.                 #Display stuff
  74.                 OponentVal = ConInput
  75.                 ShowOponent()
  76.                 return
  77.             else:
  78.                 OponentVal = ConInput
  79.         elif conInput == "1":
  80.             if HasSent == True:
  81.                 #Display stuff
  82.                 OponentVal = ConInput
  83.                 ShowOponent()
  84.                 return
  85.             else:
  86.                 OponentVal = ConInput
  87.         elif conInput == "2":
  88.             if HasSent == True:
  89.                 #Display stuff
  90.                 OponentVal = ConInput
  91.                 ShowOponent()
  92.                 return
  93.             else:
  94.                 OponentVal = ConInput
  95.         elif conInput == "3":
  96.             if HasSent == True:
  97.                 #Display stuff
  98.                 OponentVal = ConInput
  99.                 ShowOponent()
  100.                 return
  101.             else:
  102.                 OponentVal = ConInput
  103.        
  104.        
  105.    
  106.     if button_a.is_pressed() and button_b.is_pressed():
  107.         #Both buttons
  108.         radio.send("3")
  109.         HasSent = True
  110.         ShowOponent()
  111.        
  112.     elif button_a.is_pressed():
  113.         #button 1
  114.         radio.send("1")
  115.         HasSent = True
  116.         ShowOponent()
  117.        
  118.     elif button_b.is_pressed():
  119.         #button 2
  120.         radio.send("2")
  121.         HasSent = True
  122.         ShowOponent()
  123.     else:
  124.         radio.send("0")
  125.  
  126.  
  127.  
  128. #RunningStuff
  129. run()
  130. while True:
  131.     loop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement