From 237a13924b655b8c1a2048338cf5c759caf7e505 Mon Sep 17 00:00:00 2001 From: Franziska Gerold Date: Fri, 19 Dec 2025 05:04:04 +1100 Subject: [PATCH] =?UTF-8?q?Funktionalit=C3=A4t=20beim=20Rotationssensor:?= =?UTF-8?q?=20wenn=20eine=20falsche=20Richtung=20ausgew=C3=A4hlt=20wird=20?= =?UTF-8?q?->=20Game=20over?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bop_it_sensors.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/Bop_it_sensors.py b/Bop_it_sensors.py index d8b6283..f330451 100644 --- a/Bop_it_sensors.py +++ b/Bop_it_sensors.py @@ -39,23 +39,19 @@ def command_scream(): else: return -1 -def command_spin_clockwise(): - print("Spin me... clockwise!") - result = rotate.wait_for_rotate_clockwise(timeout=10) - if result: +def command_spin(): + directions = ["clockwise", "counter-clockwise"] + used_direction = random.choice(directions) + print(f"Spin me... {used_direction}!") + rotate.value = 0 # damit jede Runde wieder bei Null anfängt, Werte würden allgemein vom -1 bis 1 reichen + result = rotate.wait_for_rotate(timeout=10) + if result > 0 and used_direction == "clockwise" or result < 0 and used_direction == "counter-clockwise": print(success_message()) return 1 else: + print("You waited too long or used the wrong direction!") 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!"] @@ -69,9 +65,9 @@ def main(): 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] + list_command_choices =[command_tilt, command_spin, 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 + score += result # war zuerst ein paar 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)