Advertisement
jn_wp

mrtg - mini reaction time game

Apr 11th, 2020
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. from gpiozero import LED, Button
  2. from random import randint
  3. from time import sleep, time, gmtime
  4.  
  5. red_led = LED(17)
  6. button = Button(4)
  7. reset_button = Button(3)
  8.  
  9. highscore = 100 #inital highscore as time to beat
  10. reset_button_state = 0
  11.  
  12. def highscore_reset():
  13.     global reset_button_state
  14.     global highscore
  15.    
  16.     highscore = 100
  17.    
  18.  
  19. while True:
  20.     sleep(randint(1,10))
  21.     red_led.on()
  22.     start = time()
  23.     button.wait_for_press()
  24.     red_led.off()
  25.     end = time()
  26.    
  27.     react = end - start
  28.     print('highscore is: ' + str(highscore))
  29.     print('your time is : ' + str(react))  
  30.    
  31.     if react < highscore:
  32.         print('congrats new highscore! well done!')
  33.         highscore = react
  34.     else:
  35.         print('try again!')
  36.    
  37.     reset_button.when_pressed = highscore_reset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement