import time import random # Global variables krusty_krab_health = 100 chum_bucket_health = 100 # Function for printing text with a delay for better storytelling def print_with_delay(text, delay=0.05): for char in text: print(char, end='', flush=True) time.sleep(delay) print() # Function for presenting choices and getting user input def get_choice(choices): while True: print("\nWhat will you choose?") for index, choice in enumerate(choices, start=1): print(f"{index}. {choice}") choice_num = input("Enter the number of your choice: ") if choice_num.isdigit() and 1 <= int(choice_num) <= len(choices): return int(choice_num) else: print("Invalid choice. Please enter a number corresponding to the choices.") # Function to calculate damage and update health def calculate_damage(health, damage): if health - damage <= 0: return 0 else: return health - damage # Function for handling Chapter 1 def chapter_1(): print_with_delay("Welcome to the Bikini Bottom Rap Battle!") print_with_delay("The stage is set for an epic showdown between the Krusty Krab and the Chum Bucket.") print_with_delay("As a loyal resident of Bikini Bottom, you must choose a side to support.") choice = get_choice(["Join Team Krusty Krab", "Join Team Chum Bucket"]) if choice == 1: print_with_delay("You've joined Team Krusty Krab! Get ready to show off your rap skills.") elif choice == 2: print_with_delay("You've joined Team Chum Bucket! Time to prove your loyalty to Plankton.") return choice # Function for handling Chapter 2 def chapter_2(team_choice): if team_choice == 1: print_with_delay("You arrive at the Krusty Krab, where Mr. Krabs and SpongeBob are preparing for the rap battle.") print_with_delay("They look to you for inspiration and guidance.") choice = get_choice(["Encourage SpongeBob", "Give Mr. Krabs a pep talk"]) else: print_with_delay("You head to the Chum Bucket, where Plankton is plotting his victory.") print_with_delay("He turns to you, expecting support and motivation.") choice = get_choice(["Offer strategic advice", "Boost morale among the team"]) return choice # Function for handling Chapter 3 def chapter_3(team_choice, team_action): if team_choice == 1: if team_action == 1: print_with_delay("SpongeBob's confidence grows as you cheer him on. The team is fired up!") else: print_with_delay("Mr. Krabs appreciates your words of encouragement. The team is ready to give it their all!") else: if team_action == 1: print_with_delay("Your strategic advice helps Plankton refine his tactics. The team is feeling prepared.") else: print_with_delay("Your motivational speech lifts the spirits of the Chum Bucket crew. They're ready to dominate!") # Function for handling Chapter 4 (the rap battle) def chapter_4(team_choice): global krusty_krab_health global chum_bucket_health print_with_delay("The rap battle begins!") time.sleep(1) # Set initial damage for each team krusty_krab_damage = random.randint(5, 15) chum_bucket_damage = random.randint(5, 15) if team_choice == 1: print_with_delay("SpongeBob steps up to the mic and delivers an epic rap, showcasing the talent of Team Krusty Krab!") chum_bucket_health = calculate_damage(chum_bucket_health, krusty_krab_damage) print_with_delay(f"Chum Bucket's health: {chum_bucket_health}") else: print_with_delay("Plankton spits fire with his rap, leading Team Chum Bucket to an impressive performance!") krusty_krab_health = calculate_damage(krusty_krab_health, chum_bucket_damage) print_with_delay(f"Krusty Krab's health: {krusty_krab_health}") # Function for handling Chapter 5 (conclusion) def chapter_5(team_choice): global krusty_krab_health global chum_bucket_health print_with_delay("After a fierce battle of words, the judges announce the winner...") time.sleep(2) if krusty_krab_health <= 0: print_with_delay("Team Chum Bucket emerges victorious! Plankton's plan finally succeeded.") elif chum_bucket_health <= 0: print_with_delay("Team Krusty Krab wins! Victory tastes as sweet as a Krabby Patty.") else: print_with_delay("It's a draw! Both teams fought valiantly.") # Main function to run the story def main(): team_choice = chapter_1() team_action = chapter_2(team_choice) chapter_3(team_choice, team_action) chapter_4(team_choice) chapter_5(team_choice) # Run the story if __name__ == "__main__": main()