import random import time import threading # Function to handle customer orders def customer_order(): global score global game_over while not game_over: # Randomly choose the customer's order order = random.choice(["burger", "drink", "fries"]) # Print customer's order and start time print(f"Customer wants {order}. Start typing now!") start_time = time.time() time_remaining = time_limit # Loop until the time limit is reached while time_remaining > 0: # Calculate time remaining time_remaining = max(0, time_limit - (time.time() - start_time)) # Print time remaining print(f"Time remaining: {time_remaining:.1f}s", end="\r") # Read user input if time_remaining > 0: user_input = input("\033[K").strip().lower() # Clear the line and read input else: break # Break the loop if time's up # Check if the input matches the order if user_input == order: earning = int(time_remaining * 10) # Calculate earnings based on time remaining score += earning print(f"Order correct! You earned ${earning}. Total score: ${score}") break else: print("Time's up! Order failed.") score -= 10 # Penalty for time's up print(f"Total score: ${score}") # Global variables score = 0 game_over = False time_limit = 10 # Time limit for typing order # Function to handle game time def game_time(): global game_over time.sleep(30) # Game duration game_over = True # Main function def main(): global score global game_over print("Welcome to the Burger Shop Game!") print("You have 30 seconds to earn as much money as possible.") print("Type 'burger', 'drink', or 'fries' to fulfill customer orders.") print("Ready? Go!") # Start customer order thread order_thread = threading.Thread(target=customer_order) order_thread.start() # Start game time thread time_thread = threading.Thread(target=game_time) time_thread.start() # Wait for game to finish order_thread.join() time_thread.join() # Game over print("Game over! Final score:", score) if __name__ == "__main__": main()