|
94 | 94 | "general": WORD_LIST, |
95 | 95 | "programming": [w for w in WORD_LIST if w in PROGRAMMING_SET], |
96 | 96 | "networking": [ |
97 | | - w |
98 | | - for w in WORD_LIST |
99 | | - if w in ("network", "protocol", "bandwidth", "packet") |
| 97 | + w for w in WORD_LIST if w in ("network", "protocol", "bandwidth", "packet") |
100 | 98 | ], |
101 | 99 | } |
102 | 100 |
|
@@ -266,8 +264,7 @@ def play_round(word: str, difficulty: str) -> Union[int, tuple]: |
266 | 264 |
|
267 | 265 | print("\nScrambled:", " ".join(scrambled)) |
268 | 266 | print( |
269 | | - "(Type your guess, or 'hint', 'skip', 'quit'." |
270 | | - f" Time suggested: {max_time}s)\n" |
| 267 | + f"(Type your guess, or 'hint', 'skip', 'quit'. Time suggested: {max_time}s)\n" |
271 | 268 | ) |
272 | 269 |
|
273 | 270 | start = time.perf_counter() |
@@ -295,12 +292,19 @@ def play_round(word: str, difficulty: str) -> Union[int, tuple]: |
295 | 292 | # check answer |
296 | 293 | if guess == word: |
297 | 294 | points = compute_score(word, elapsed, difficulty) |
298 | | - print(color(f"Correct! +{points} pts (time: {int(elapsed)}s, attempts: {attempts})", '32')) |
| 295 | + print( |
| 296 | + color( |
| 297 | + f"Correct! +{points} pts (time: {int(elapsed)}s, attempts: {attempts})", |
| 298 | + "32", |
| 299 | + ) |
| 300 | + ) |
299 | 301 | return points |
300 | 302 | else: |
301 | 303 | # small helpful feedback |
302 | 304 | same_positions = sum(1 for a, b in zip(guess, word) if a == b) |
303 | | - print(f"Not quite. {same_positions} letter(s) in the correct position. Try again.") |
| 305 | + print( |
| 306 | + f"Not quite. {same_positions} letter(s) in the correct position. Try again." |
| 307 | + ) |
304 | 308 |
|
305 | 309 |
|
306 | 310 | def pick_word_by_difficulty_and_category( |
@@ -331,16 +335,19 @@ def celebratory_art() -> None: |
331 | 335 |
|
332 | 336 |
|
333 | 337 | def play_game() -> None: |
334 | | - print(color("WELCOME TO WORD SCRAMBLE", '36')) |
335 | | - print(color("------------------------", '36')) |
| 338 | + print(color("WELCOME TO WORD SCRAMBLE", "36")) |
| 339 | + print(color("------------------------", "36")) |
336 | 340 | # choose difficulty |
337 | 341 | while True: |
338 | | - diff = input("Choose difficulty (easy / medium / hard) [medium]: ").strip().lower() or "medium" |
| 342 | + diff = ( |
| 343 | + input("Choose difficulty (easy / medium / hard) [medium]: ").strip().lower() |
| 344 | + or "medium" |
| 345 | + ) |
339 | 346 | if diff in DIFFICULTIES: |
340 | 347 | break |
341 | 348 | print("Invalid choice.") |
342 | 349 | # choose optional category |
343 | | - print("Available categories:", ', '.join(CATEGORIES.keys())) |
| 350 | + print("Available categories:", ", ".join(CATEGORIES.keys())) |
344 | 351 | cat = input("Pick category (or press Enter for mixed): ").strip().lower() or None |
345 | 352 | if cat and cat not in CATEGORIES: |
346 | 353 | print("Unknown category, using mixed words.") |
@@ -368,7 +375,12 @@ def play_game() -> None: |
368 | 375 | # combo bonus for streaks: +5% per consecutive correct (rounded) |
369 | 376 | combo_bonus = int(points * (0.05 * (streak - 1))) if streak > 1 else 0 |
370 | 377 | if combo_bonus: |
371 | | - print(color(f"Combo! +{combo_bonus} bonus points for a streak of {streak}", '33')) |
| 378 | + print( |
| 379 | + color( |
| 380 | + f"Combo! +{combo_bonus} bonus points for a streak of {streak}", |
| 381 | + "33", |
| 382 | + ) |
| 383 | + ) |
372 | 384 | points += combo_bonus |
373 | 385 | total_score += points |
374 | 386 | celebratory_art() |
@@ -397,7 +409,9 @@ def main_menu() -> None: |
397 | 409 | elif choice == "3": |
398 | 410 | print("\nInstructions:") |
399 | 411 | print("- Guess the original word from the scrambled letters.") |
400 | | - print("- Commands during a round: 'hint' (reveals one letter), 'skip', 'quit'.") |
| 412 | + print( |
| 413 | + "- Commands during a round: 'hint' (reveals one letter), 'skip', 'quit'." |
| 414 | + ) |
401 | 415 | print("- Faster correct answers score more points.") |
402 | 416 | print("- High scores are saved locally in high_scores.json.\n") |
403 | 417 | elif choice == "4": |
|
0 commit comments