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:
@@ -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
|
// Wrap renderBoard to match Unified API signature
|
||||||
const renderBoardWrapped = () => {
|
const renderBoardWrapped = () => {
|
||||||
|
|||||||
@@ -5,18 +5,21 @@ import type { GameStatus, KeyLogEntry } from "../types";
|
|||||||
export type UseScoreParams = {
|
export type UseScoreParams = {
|
||||||
gameStatus: GameStatus;
|
gameStatus: GameStatus;
|
||||||
keyLog: KeyLogEntry[];
|
keyLog: KeyLogEntry[];
|
||||||
|
currentScore: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useScore({ gameStatus, keyLog }: UseScoreParams) {
|
export function useScore({ gameStatus, keyLog, currentScore }: UseScoreParams) {
|
||||||
const timer = useTimer();
|
const timer = useTimer();
|
||||||
const { timeValue, startTimer, stopTimer, resetTimer } = timer;
|
const { timeValue, startTimer, stopTimer, resetTimer } = timer;
|
||||||
|
|
||||||
useScoreTime({ gameStatus, timer });
|
useScoreTime({ gameStatus, timer });
|
||||||
|
|
||||||
|
const finalScore = gameStatus === 'game-over' || gameStatus === 'game-won' ? currentScore : null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
timeValue,
|
timeValue,
|
||||||
totalKeystrokes: keyLog.length,
|
totalKeystrokes: keyLog.length,
|
||||||
finalScore: null, // TODO: Calculate on game-won
|
finalScore,
|
||||||
startTimer,
|
startTimer,
|
||||||
stopTimer,
|
stopTimer,
|
||||||
resetTimer,
|
resetTimer,
|
||||||
|
|||||||
Reference in New Issue
Block a user