import random import time from gpiozero import Button from gpiozero import RotaryEncoder laser = Button(17) #Die Zahl entspricht dem Pin auf dem ARPI600 Board sound = Button(18, pull_up=True) rotate = RotaryEncoder(20, 21) tilt = Button(23) def command_tilt(): print("Tilt me!") result = tilt.wait_for_press(timeout=10) if result: time.sleep(0.3) # soll verhindern, dass die vorherige Runde die jetzige beeinflusst print(success_message()) return 1 else: return -1 def command_blind(): print('Blind me!') result = laser.wait_for_press(timeout=10) if result: print(success_message()) return 1 else: return -1 def command_scream(): print('Make noise at me!') result = sound.wait_for_press(timeout=10) if result: time.sleep(0.3) #soll verhindern, dass dasGeräuschsignal aus der vorherigen Runde gezählt wird print(success_message()) return 1 else: return -1 def command_spin_clockwise(): print("Spin me... clockwise!") result = rotate.wait_for_rotate_clockwise(timeout=10) if result: print(success_message()) return 1 else: return -1 def command_spin_counter_clockwise(): print("Spin me... counter clockwise!") result = rotate.wait_for_rotate_counter_clockwise(timeout=10) if result: print(success_message()) return 1 else: return -1 def success_message(): list_of_messages = ["Great job!", "Correct!", "Nice!", "You know it!", "That's what I'm talking about", "Perfect!"] message = random.choice(list_of_messages) return message def main(): score = 0 result = 0 print("Raspberry will now tell you what to do.") print("Every correct action will give you a point.") print("How many can you get?") print("Let's go!") list_command_choices =[command_tilt, command_spin_clockwise, command_spin_counter_clockwise, command_blind, command_scream] while result != -1: score += result # war zuerst zwei Zeilen weiter unten, hat dann aber nach einer falschen Runde den Score erhöht time.sleep(0.5) print("Get ready for the next round!") round = random.choice(list_command_choices) result = round() print(f"Game over! Your Score is {score}") main()