Skip to content

refactor: simplify game code#1

Merged
milesapnash merged 21 commits into
mainfrom
refactor/simply-snake
May 23, 2026
Merged

refactor: simplify game code#1
milesapnash merged 21 commits into
mainfrom
refactor/simply-snake

Conversation

@milesapnash
Copy link
Copy Markdown
Owner

@milesapnash milesapnash commented May 23, 2026

  • Moved all classes into com.mapna.snake package
  • Encapsulated Snake state: owns its own movement, protects body list with unmodifiable view, uses HashSet for O(1) collision checks
  • Extracted game logic into testable GameEngine with injectable Random
  • Added WON game state when snake fills the board
  • Optimised food placement to enumerate free cells instead of retry loop
  • Eliminated magic floats and duplicated direction/paint logic in BoardRenderer
  • Extracted constants (HIGHSCORE_FILE, INITIAL_LENGTH, fonts) and removed excess final keywords
  • Fixed rendering fragility: score overlay now sets its own font/color explicitly instead of relying on side-effects from paintTitles
  • Removed unnecessary defensive copies on GameState.food
  • Added SnakeTest (12 tests) and FileHighScoreStoreTest (9 tests)
  • Added GitHub Actions CI pipeline (compile + test on push/PR)
  • Added maven-shade-plugin for runnable JAR packaging

@milesapnash milesapnash merged commit cb232e0 into main May 23, 2026
2 checks passed
@milesapnash milesapnash deleted the refactor/simply-snake branch May 23, 2026 18:45
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.

1 participant