Skip to content

Implement High Score System and Display#96

Draft
Copilot wants to merge 3 commits intodevelopfrom
copilot/implement-high-score-system
Draft

Implement High Score System and Display#96
Copilot wants to merge 3 commits intodevelopfrom
copilot/implement-high-score-system

Conversation

Copy link
Contributor

Copilot AI commented Oct 20, 2025

Overview

This PR implements a complete high score system for Ophidian with persistent storage, sorted display, and full keyboard/mouse navigation support.

Changes

New Components

HighScoreEntry (src/score/high_score_entry.py)

  • Data model representing individual high score entries
  • Stores score, maximum snake length, highest level reached, and timestamp
  • Implements equality comparison for proper identity checking
  • Provides JSON serialization/deserialization

HighScoreRepository (src/score/high_score_repository.py)

  • Repository pattern for high score persistence
  • JSON-based storage (automatically excluded by .gitignore)
  • Automatic sorting (highest score first)
  • Configurable top-N limiting (default: 10 scores)
  • Methods: add_score(), is_high_score(), load(), save(), clear()

Updated Components

HighScoresMenu (src/graphics/high_scores_menu.py)

  • Replaced placeholder with functional high score table display
  • Shows rank, score, length, and level in a formatted table
  • Color-coded top 3 scores (gold/green, silver/white, bronze)
  • Scroll support for lists with more than 8 entries
  • Visual scroll indicators ("▲ More above", "▼ More below")
  • Performance optimization via score caching
  • Keyboard navigation: Up/Down arrows to scroll, ESC/Enter to return

GameEngine (src/game_engine.py)

  • Tracks maximum snake length during gameplay
  • Automatically saves high scores when game ends or restarts
  • Only saves scores with cumulative_points > 0
  • Logs new high score achievements

Ophidian (src/ophidian.py)

  • Auto-refreshes scores when entering high scores menu
  • Resets scroll position on menu entry

Features

Persistent Storage - High scores saved to high_scores.json between sessions
Automatic Sorting - Scores always displayed highest-first
Smart Limiting - Only top 10 scores retained
Rich Display - Shows rank, score, length, and level for each entry
Full Navigation - Keyboard (arrows, ESC, Enter) and mouse (click) support
Performance - Caching prevents repeated disk reads
UX Polish - Color coding, scroll indicators, empty state messaging

Testing

  • 26 unit tests covering all new functionality
  • All existing tests continue to pass
  • Integration tests verify game-to-menu flow
  • Cross-platform compatibility verified
  • CodeQL security scan: 0 alerts

Example

After playing a game, the high score is automatically saved. Navigate to "High Scores" from the main menu to see:

HIGH SCORES

RANK     SCORE      LENGTH     LEVEL
#1       15000      150        10
#2       12500      125        8
#3       10000      100        7
...

Press ESC or ENTER to return to main menu
Use UP/DOWN arrows to scroll

Closes #[issue number]

Original prompt

This section details on the original issue you should resolve

<issue_title>Implement High Score System and Display</issue_title>
<issue_description>## Description
Create a high score system with display in the main menu.

Tasks

  • Create high score storage system
  • Design high score display screen
  • Add score sorting and limiting
  • Implement score entry system
  • Add score categories (length, time, etc.)
  • Create score table navigation

Acceptance Criteria

  • High scores are persisted between sessions
  • Scores are properly sorted and displayed
  • New high scores can be entered
  • Table shows relevant score information
  • Navigation works with keyboard and mouse</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #80


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 20, 2025 05:07
Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
…ss-platform compatibility

Co-authored-by: dmccoystephenson <21204351+dmccoystephenson@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement high score system and display Implement High Score System and Display Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants