feat: add timeLimit option and time-based game-over logic

- Add timeLimit to GameOptions (default 600 seconds)
- Game-over triggers when time limit exceeded
- Remove all efficiency-based game-over logic
- Pass timeLimit through to useScore
- Check time limit during started and has-key states
This commit is contained in:
2025-10-22 22:07:59 +01:00
parent 7ccf7cdd55
commit 7800acaf56
3 changed files with 16 additions and 4 deletions
+13 -2
View File
@@ -13,11 +13,12 @@ type UseScoreParams = {
keyManager?: { keyLog: any[] };
rows: number;
cols: number;
timeLimit: number;
};
export function useScore({ board, hero, gameStatusManager, keyManager, rows, cols }: UseScoreParams) {
export function useScore({ board, hero, gameStatusManager, keyManager, rows, cols, timeLimit }: UseScoreParams) {
const timer = useTimer();
const { gameStatus } = gameStatusManager;
const { gameStatus, setGameStatus } = gameStatusManager;
const { timeValue, startTimer, stopTimer, resetTimer } = timer;
const {
@@ -35,6 +36,16 @@ export function useScore({ board, hero, gameStatusManager, keyManager, rows, col
useScoreTime({ gameStatus, timer });
useEffect(() => {
if (gameStatus !== "started" && gameStatus !== "has-key") return;
const timeLimitMs = timeLimit * 1000;
if (timeValue >= timeLimitMs) {
setGameStatus("game-over");
return;
}
}, [gameStatus, timeValue, timeLimit, setGameStatus]);
useEffect(() => {
if (gameStatus !== "game-won") return;