Skip to content

[Feature]: Add a High Score Tracker for the Snake Game #763

@leonagoel

Description

@leonagoel

Description

The current Snake game does not save or display a high score between
sessions. Once the game is closed, the player's best score is lost.
Adding a persistent high score tracker would improve the gameplay
experience significantly.

Current Behavior

  • Score resets to 0 every time the game is launched
  • No record of previous best scores is maintained

Proposed Feature

  • Save the highest score to a local file (e.g., highscore.txt)
  • Display the high score on the game screen alongside the current score
  • Update the file whenever a new high score is achieved
  • Show a "New High Score!" message when the record is broken

Example Implementation

def load_high_score():
    try:
        with open("highscore.txt", "r") as f:
            return int(f.read())
    except FileNotFoundError:
        return 0

def save_high_score(score):
    with open("highscore.txt", "w") as f:
        f.write(str(score))

Benefits

  • Encourages replayability
  • Minimal code change with high impact
  • Follows standard game design practices

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions