if user_word == 'quit': print("Game ended.") break
def bomb_timer(seconds, player_name): """Timer thread that waits and then explodes.""" time.sleep(seconds) print(f"\nš£ BOOM! {player_name} took too long! š£") print(f"Required letters were: {required_letters}") exit(0) GAME SETUP ------------------------------ print("\nš„š„š„ WORD BOMB š„š„š„") print("Players take turns. You must say a word containing the given letters.") print("You have 5 seconds before the bomb explodes!") print("Type 'quit' to exit.\n")
print("\n" + "="*50) print(f"š£ {current_player}'s turn! Bomb is ticking...") print(f"š¤ Required letters: {required_letters.upper()}") print("ā±ļø You have 5 seconds!") Word Bomb Script
def get_random_letters(): """Return a string of 2-3 random letters (e.g., 'ap', 'cat').""" length = random.choice([2, 3]) letters = ''.join(random.choices('abcdefghijklmnopqrstuvwxyz', k=length)) return letters
================================================== š£ Alex's turn! Bomb is ticking... š¤ Required letters: AP ā±ļø You have 5 seconds! š Your word: apple ā Correct! 'apple' contains 'ap'. šŖ Bomb defused! Passing to next player... if user_word == 'quit': print("Game ended
# Start bomb timer timer = threading.Thread(target=bomb_timer, args=(5, current_player)) timer.daemon = True timer.start()
def is_valid_word(word, required_letters): """Check if word contains the required letters as a substring.""" return required_letters.lower() in word.lower() You must say a word containing the given letters
# Get player's answer start_time = time.time() user_word = input("š Your word: ").strip().lower() elapsed = time.time() - start_time
================================================== š£ Jamie's turn! Bomb is ticking... š¤ Required letters: ZE ā±ļø You have 5 seconds! š Your word: zebra ā Correct! 'zebra' contains 'ze'. šŖ Bomb defused! Passing to next player...
if not is_valid_word(user_word, required_letters): print(f"\nā WRONG! '{user_word}' does not contain '{required_letters}'.") print(f"{current_player} loses!") break