Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from gpiozero import Button,LED
- from time import sleep,time
- from random import randint
- from sys import exit
- from math import trunc
- def speed_time():
- if float(speed) > 1:
- print("That's more than",speed,"seconds")
- elif float(speed) <= 1:
- print("That's more than",speed,"second")
- def game_start():
- print("Let's begin")
- print("Look at the LED")
- print("When it turns on, press the button quickly\n")
- btn = Button(17)
- led = LED(16)
- lives = input("How many lives do you want?")
- game_lives = trunc(float(lives))
- if game_lives > 1 and game_lives < 5:
- print("You have",game_lives,"lives")
- elif game_lives >=5:
- print(game_lives,"is too much")
- print("Maximum allowed is 4")
- game_lives = 4
- print("You have",game_lives,"lives")
- elif game_lives <= 0:
- print("Haha, game over then!")
- exit()
- else:
- print("You have",game_lives,"life\nYou like living on the edge I see")
- speed = input("How fast in seconds do you think you can press the button?")
- if float(speed) > 1:
- print("\nYou have to press the button in less than",speed,"seconds from when it turns on")
- print("Otherwise, it is game over")
- game_start()
- elif float(speed) == 0:
- print("\nReally, 0 second. Be my guest. You'll lose")
- game_start()
- else:
- print("\nYou have to press the button in less than",speed,"second from when it turns on")
- print("Otherwise, it is game over")
- game_start()
- while game_lives > 0:
- sleep(randint(1,10))
- start = time()
- led.on()
- btn.wait_for_press()
- end = time()
- led.off()
- rct_time = end - start
- if rct_time >=float(speed):
- game_lives = game_lives - 1
- if rct_time > 1:
- print("It took you",rct_time,"seconds to press the button")
- speed_time()
- elif rct_time <= 1:
- print("It took you",rct_time,"second to press the button")
- speed_time()
- if game_lives > 1:
- print("You have",game_lives,"lives left\n")
- elif game_lives == 1:
- print("You have 1 life left, be careful\n")
- else:
- print("You have 0 lives left.\nGame over!")
- else:
- if rct_time > 1:
- print("It took you", rct_time, "seconds to press the button")
- elif rct_time < 1:
- print("It took you", rct_time, "second to press the button")
- else:
- print("It took you", rct_time, "second to press the button")
- speed_time()
- print("Well done!")
- if game_lives > 1:
- print("You still have",game_lives,"lives left\n")
- elif game_lives == 1:
- print("You still have 1 life left\n")
- else:
- print("You have 0 lives left.\nGame over!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement