feat(phase2.2): implement finalScore calculation

- finalScore equals current game score when gameStatus is 'game-over' or 'game-won'
- finalScore is null during active gameplay ('waiting' and 'started')
- Passed currentScore from gameManager to useScore hook
This commit is contained in:
2025-10-30 23:57:23 +00:00
parent 2a7162abf3
commit 52cdbd81d5
2 changed files with 6 additions and 3 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ export function useGame(optionsOrCols: GameOptions | number, rows?: number, plat
},
});
const scoreManager = useScore({ gameStatus, keyLog: keyBindings.keyLog });
const scoreManager = useScore({ gameStatus, keyLog: keyBindings.keyLog, currentScore: score });
// Wrap renderBoard to match Unified API signature
const renderBoardWrapped = () => {
+5 -2
View File
@@ -5,18 +5,21 @@ import type { GameStatus, KeyLogEntry } from "../types";
export type UseScoreParams = {
gameStatus: GameStatus;
keyLog: KeyLogEntry[];
currentScore: number;
};
export function useScore({ gameStatus, keyLog }: UseScoreParams) {
export function useScore({ gameStatus, keyLog, currentScore }: UseScoreParams) {
const timer = useTimer();
const { timeValue, startTimer, stopTimer, resetTimer } = timer;
useScoreTime({ gameStatus, timer });
const finalScore = gameStatus === 'game-over' || gameStatus === 'game-won' ? currentScore : null;
return {
timeValue,
totalKeystrokes: keyLog.length,
finalScore: null, // TODO: Calculate on game-won
finalScore,
startTimer,
stopTimer,
resetTimer,