refactor: separate score calculation from score management
BREAKING CHANGES: - Remove timeLimit from GameOptions (use gameOver function instead) - Remove finalScore from ScoreManager (pure data collection only) - Remove rows/cols parameters from useScore - Remove finalScore calculation logic from useScore hook ADDITIONS: - Create calculateMazeScore() utility function - ScoreManager now only returns raw metrics: timeValue, keystrokes, optimalSteps, efficiency, distToKey, distToExit - Score calculation moved to consumer (calculateMazeScore takes scoreManager + mazeSize) - Example app now uses calculateMazeScore to compute final score on game-won BENEFITS: - ScoreManager is now a pure data collector with no side effects - Scoring algorithm is reusable and testable in isolation - Game-over conditions fully controlled via gameOver option - Clear separation of concerns: collection vs calculation
This commit is contained in:
+2
-2
@@ -6,7 +6,7 @@ import { useHeroRender } from './useCursor';
|
||||
import { useScore } from './useScore';
|
||||
|
||||
export function useGame(options: GameOptions, platformHook?: unknown): GameManager {
|
||||
const { cols, rows, timeLimit = 600, gameOver } = options;
|
||||
const { cols, rows, gameOver } = options;
|
||||
const board = useBoard(cols, rows);
|
||||
const { containerRef, renderBoard } = board;
|
||||
const gameStatusManager = useGameStatus();
|
||||
@@ -14,7 +14,7 @@ export function useGame(options: GameOptions, platformHook?: unknown): GameManag
|
||||
|
||||
const hero = cursor.hero;
|
||||
const renderer = useHeroRender({ gameStatus: gameStatusManager.gameStatus, board, hero });
|
||||
const scoreManager = useScore({ board, hero, gameStatusManager, keyManager, rows, cols, timeLimit, gameOver });
|
||||
const scoreManager = useScore({ board, hero, gameStatusManager, keyManager, gameOver });
|
||||
|
||||
const gameManager: GameManager = {
|
||||
containerRef,
|
||||
|
||||
Reference in New Issue
Block a user