From 4a15f951f0ac31a2020217f764ec66076b9fd77a Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Fri, 14 Feb 2025 16:50:04 -0500 Subject: [PATCH] Rewrote the scoreboard class. Added ability to enter name for scoreboard. --- __init__.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/__init__.py b/__init__.py index 307e8b2..988d3ab 100755 --- a/__init__.py +++ b/__init__.py @@ -109,34 +109,37 @@ class Scoreboard: return i + 1 return None - def add_high_score(self, name="Player"): + def add_high_score(self): """Add current score to high scores if it qualifies. - - Args: - name (str): Player name for high score entry - + Returns: bool: True if score was added, False if not """ position = self.check_high_score() if position is None: return False - + + # Prompt for name using get_input + name = get_input("New high score! Enter your name:", "Player") + if name is None: # User cancelled + name = "Player" + # Insert new score at correct position self.highScores.insert(position - 1, { 'name': name, 'score': self.currentScore }) - + # Keep only top 10 self.highScores = self.highScores[:10] - + # Save to config for i, entry in enumerate(self.highScores): localConfig.set("scoreboard", f"score_{i+1}", str(entry['score'])) localConfig.set("scoreboard", f"name_{i+1}", entry['name']) - + write_config() + speak(f"Congratulations {name}! You got position {position} on the high score table!") return True