feat: implement game-over logic with time and hint limits

- Add configurable timeLimit to GameOptions (default 600 seconds / 10 minutes)
- Time limit applies to all difficulty levels (harder puzzles = more time pressure)
- Implement game-over triggers:
  1. Time limit exceeded: timeValue >= timeLimit → 'Time's up!'
  2. Hint penalty limit: hintsUsed * penalty >= 500 → 'Too many hints!'
- Hint limits by difficulty:
  - Easy: 20 hints max (20 × 25 = 500 points)
  - Medium: 10 hints max (10 × 50 = 500 points)
  - Hard: 5 hints max (5 × 100 = 500 points)
- Add gameOverReason to ScoreManager to display specific failure reason
- Timer stops on game-over
- Update example app to show game-over reason
- Both conditions checked during gameplay before win condition
This commit is contained in:
2025-10-22 21:48:33 +01:00
parent 97c31ab6cc
commit f68098657b
6 changed files with 194 additions and 6 deletions
+2 -2
View File
@@ -7,7 +7,7 @@ import { useCursorRender } from './useCursor/useCursorRender';
import { useScore } from './useScore';
export function useGame(options: GameOptions = {}, platformHook?: unknown): GameManager {
const { difficulty = 'easy' } = options;
const { difficulty = 'easy', timeLimit = 600 } = options;
const board = useBoard();
const { containerRef, renderBoard, generateBoard, boardRendered } = board;
@@ -24,7 +24,7 @@ export function useGame(options: GameOptions = {}, platformHook?: unknown): Game
const cursorPosition = cursor.position();
const cursorMode = cursor.mode();
const scoreManager = useScore({ board, gameStatusManager, keyLog, cursorMode, difficulty, hintsUsed: hintsUsedRef.current });
const scoreManager = useScore({ board, gameStatusManager, keyLog, cursorMode, difficulty, hintsUsed: hintsUsedRef.current, timeLimit });
useCursorRender(containerRef, cursorPosition, cursorMode, gameStatus, boardRendered);