Rewrote the scoreboard class. Added ability to enter name for scoreboard.

This commit is contained in:
Storm Dragon 2025-02-14 16:50:04 -05:00
parent 5a791510ea
commit 4a15f951f0

View File

@ -109,12 +109,9 @@ class Scoreboard:
return i + 1 return i + 1
return None return None
def add_high_score(self, name="Player"): def add_high_score(self):
"""Add current score to high scores if it qualifies. """Add current score to high scores if it qualifies.
Args:
name (str): Player name for high score entry
Returns: Returns:
bool: True if score was added, False if not bool: True if score was added, False if not
""" """
@ -122,6 +119,11 @@ class Scoreboard:
if position is None: if position is None:
return False 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 # Insert new score at correct position
self.highScores.insert(position - 1, { self.highScores.insert(position - 1, {
'name': name, 'name': name,
@ -137,6 +139,7 @@ class Scoreboard:
localConfig.set("scoreboard", f"name_{i+1}", entry['name']) localConfig.set("scoreboard", f"name_{i+1}", entry['name'])
write_config() write_config()
speak(f"Congratulations {name}! You got position {position} on the high score table!")
return True return True