Rewrote the scoreboard class. Added ability to enter name for scoreboard.
This commit is contained in:
parent
5a791510ea
commit
4a15f951f0
21
__init__.py
21
__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
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user