65 lines
1.3 KiB
Python
65 lines
1.3 KiB
Python
import random
|
|
import time
|
|
from gpiozero import Button
|
|
|
|
laser = Button(17)
|
|
sound = Button(18, pull_up=True)
|
|
|
|
def score(x):
|
|
pass
|
|
|
|
def command_tilt():
|
|
action = input()
|
|
if action == "0":
|
|
return 1
|
|
else:
|
|
return -1
|
|
|
|
|
|
|
|
def command_blind():
|
|
print('waiting for eye problems...')
|
|
result = laser.wait_for_press(timeout=10)
|
|
print(f"Result: {result}")
|
|
if result:
|
|
return 1
|
|
else:
|
|
return -1
|
|
|
|
def command_scream():
|
|
print('waiting for sound...')
|
|
result = sound.wait_for_press(timeout=10)
|
|
print(f"Result: {result}")
|
|
if result:
|
|
time.sleep(0.3)
|
|
return 1
|
|
else:
|
|
return -1
|
|
|
|
def command_spin():
|
|
action = input()
|
|
if action == "0":
|
|
return 1
|
|
else:
|
|
return -1
|
|
|
|
def sound_was_held():
|
|
print('You screamed long enough!')
|
|
|
|
def main():
|
|
score = 0
|
|
result = 0
|
|
sound.when_held = sound_was_held
|
|
print("Let's play a Round of 'Raspberry says'!")
|
|
list_command_choices = [command_scream, command_blind]# command_blind, command_spin, command_tilt
|
|
while result != -1:
|
|
score += result # war zuerst zwei Zeilen weiter unten, hat dann aber nach einer falschen Runde den Score erhöht
|
|
round = random.choice(list_command_choices)
|
|
result = round()
|
|
print(f"Game over! Your Score is {score}")
|
|
|
|
|
|
|
|
|
|
main()
|