|
6 | 6 | print("Watch the sequence and repeat it correctly!") |
7 | 7 | print("Each round, the sequence gets longer!\n") |
8 | 8 |
|
9 | | -# Game setup |
10 | | -emojis = ['🔴', '🔵', '🟢', '🟡'] |
11 | | -emoji_names = ['R', 'B', 'G', 'Y'] |
12 | | -sequence = [] |
13 | | -player_sequence = [] |
14 | | -round_number = 0 |
15 | | -game_over = False |
16 | | - |
17 | | -print("🎯 How to Play:") |
18 | | -print("1. Watch the sequence of colored circles") |
19 | | -print("2. Type the colors in order (e.g., 'R B G Y')") |
20 | | -print("3. Each correct round adds one more color!") |
21 | | -print("4. Make a mistake and the game ends!\n") |
22 | | - |
23 | | -input("Press Enter to start! 👇\n") |
24 | | - |
25 | | - |
26 | | -while not game_over: |
27 | | - round_number += 1 |
28 | | - |
29 | | - # Add new emoji to sequence |
30 | | - new_emoji = random.choice(emojis) |
31 | | - sequence.append(new_emoji) |
32 | | - |
| 9 | +play_again = True |
| 10 | + |
| 11 | +while play_again: |
| 12 | + |
| 13 | + # Game setup |
| 14 | + color_map = { |
| 15 | + 'R': '🔴', |
| 16 | + 'B': '🔵', |
| 17 | + 'G': '🟢', |
| 18 | + 'Y': '🟡' |
| 19 | + } |
| 20 | + |
| 21 | + sequence = [] |
| 22 | + round_number = 0 |
| 23 | + game_over = False |
| 24 | + |
| 25 | + print("🎯 How to Play:") |
| 26 | + print("1. Watch the sequence of colored circles") |
| 27 | + print("2. Type the colors in order (e.g., 'R B G Y')") |
| 28 | + print("3. Each correct round adds one more color!") |
| 29 | + print("4. Make a mistake and the game ends!\n") |
| 30 | + |
| 31 | + input("Press Enter to start! 👇\n") |
| 32 | + |
| 33 | + while not game_over: |
| 34 | + round_number += 1 |
| 35 | + |
| 36 | + # Add new emoji to sequence |
| 37 | + new_emoji = random.choice(list(color_map.values())) |
| 38 | + sequence.append(new_emoji) |
| 39 | + |
| 40 | + print(f"\n{'='*50}") |
| 41 | + print(f"🎯 Round {round_number} | Sequence Length: {len(sequence)}") |
| 42 | + print(f"{'='*50}") |
| 43 | + |
| 44 | + # Dynamic speed increase |
| 45 | + display_speed = max(0.2, 0.6 - (round_number * 0.03)) |
| 46 | + |
| 47 | + # Display sequence with delays |
| 48 | + print("\n🔄 Watch the sequence:\n") |
| 49 | + for i, emoji in enumerate(sequence): |
| 50 | + print(f" {emoji} ", end="", flush=True) |
| 51 | + time.sleep(display_speed) |
| 52 | + print("\b\b\b", end="", flush=True) |
| 53 | + time.sleep(0.3) |
| 54 | + |
| 55 | + print("\n") |
| 56 | + |
| 57 | + # Get player input |
| 58 | + player_input = input("🎯 Enter the sequence (space-separated): ").strip().upper().split() |
| 59 | + |
| 60 | + # Validate input |
| 61 | + valid_input = all(inp in color_map for inp in player_input) |
| 62 | + |
| 63 | + if not valid_input: |
| 64 | + print("❌ Invalid input! Use only R, B, G, Y separated by spaces.\n") |
| 65 | + game_over = True |
| 66 | + break |
| 67 | + |
| 68 | + # Convert player input to emojis |
| 69 | + player_sequence = [color_map[inp] for inp in player_input] |
| 70 | + |
| 71 | + # Check if player's sequence matches |
| 72 | + if player_sequence == sequence: |
| 73 | + print("✅ Correct! You've mastered this sequence!\n") |
| 74 | + else: |
| 75 | + print(f"❌ Wrong! The sequence was: {' '.join(sequence)}") |
| 76 | + print(f"❌ You entered: {' '.join(player_sequence)}\n") |
| 77 | + game_over = True |
| 78 | + |
33 | 79 | print(f"\n{'='*50}") |
34 | | - print(f"🎯 Round {round_number} | Sequence Length: {len(sequence)}") |
| 80 | + print(f"🏁 GAME OVER!") |
35 | 81 | print(f"{'='*50}") |
36 | | - |
37 | | - # Display sequence with delays |
38 | | - print("\n🔄 Watch the sequence:\n") |
39 | | - for i, emoji in enumerate(sequence): |
40 | | - print(f" {emoji} ", end="", flush=True) |
41 | | - time.sleep(0.6) |
42 | | - print("\b\b\b", end="", flush=True) |
43 | | - time.sleep(0.4) |
44 | | - |
45 | | - print("\n") |
46 | | - |
47 | | - # Get player input |
48 | | - player_input = input("🎯 Enter the sequence (space-separated): ").strip().upper().split() |
49 | | - |
50 | | - # Validate input |
51 | | - valid_input = all(inp in emoji_names for inp in player_input) |
52 | | - |
53 | | - if not valid_input: |
54 | | - print("❌ Invalid input! Use only R, B, G, Y separated by spaces.\n") |
55 | | - game_over = True |
56 | | - break |
57 | | - |
58 | | - # Convert player input to emojis |
59 | | - player_sequence = [emojis[emoji_names.index(inp)] for inp in player_input] |
60 | | - |
61 | | - # Check if player's sequence matches |
62 | | - if player_sequence == sequence: |
63 | | - print("✅ Correct! You've mastered this sequence!\n") |
| 82 | + print(f"🎯 Rounds Completed: {round_number - 1}") |
| 83 | + print(f"📊 Sequence Length Reached: {len(sequence)}") |
| 84 | + |
| 85 | + if round_number == 1: |
| 86 | + print(f"💡 Try again to beat the first round!\n") |
64 | 87 | else: |
65 | | - print(f"❌ Wrong! The sequence was: {' '.join(sequence)}") |
66 | | - print(f"❌ You entered: {' '.join(player_sequence)}\n") |
67 | | - game_over = True |
68 | | - |
69 | | -print(f"\n{'='*50}") |
70 | | -print(f"🏁 GAME OVER!") |
71 | | -print(f"{'='*50}") |
72 | | -print(f"🎯 Final Round: {round_number}") |
73 | | -print(f"📊 Sequence Length Reached: {len(sequence)}") |
74 | | - |
75 | | -if round_number == 1: |
76 | | - print(f"💡 Try again to beat the first round!\n") |
77 | | -else: |
78 | | - print(f"🏆 Great job! You made it to round {round_number}!\n") |
| 88 | + print(f"🏆 Great job! You made it to round {round_number - 1}!\n") |
| 89 | + |
| 90 | + replay_choice = input("🔁 Do you want to play again? (Y/N): ").strip().upper() |
| 91 | + |
| 92 | + if replay_choice != 'Y': |
| 93 | + play_again = False |
79 | 94 |
|
80 | 95 | print("👋 Thanks for playing Simon Says! Goodbye!\n") |
0 commit comments