feat: implement scoring system and win condition (Phase 50)

- Add useTimer hook for elapsed time tracking
- Add useScore hook with comprehensive metrics:
  - Total keystrokes (all keys)
  - Edit keystrokes (only editing keys)
  - Optimal keystrokes (empty cells × 3)
  - Efficiency percentage (optimal/edit × 100)
  - Final score (70% efficiency + 30% time-based)
- Win condition detects board completion only in normal mode
- Track all keystrokes with timestamps in useGame
- Update example app with full scoreboard display
- Expose boardRef in BoardManager for state checking
- Adjust easy mode to 5 removed cells for testing
This commit is contained in:
2025-10-22 20:42:50 +01:00
parent 710ec4b83b
commit 8db4455dc5
11 changed files with 339 additions and 25 deletions
+3 -5
View File
@@ -1,11 +1,13 @@
import type { RefObject } from 'react';
import type { GameStatus, GameStatusManager } from './useGameStatus/types';
import type { CursorManager } from './useCursor/types';
import type { ScoreManager } from './useScore/types';
export type Difficulty = 'easy' | 'medium' | 'hard';
export type { GameStatus, GameStatusManager };
export type { CursorManager, Coord } from './useCursor/types';
export type { ScoreManager } from './useScore/types';
export type GameOptions = {
difficulty?: Difficulty;
@@ -17,11 +19,7 @@ export type GameManager = {
containerRef: RefObject<HTMLDivElement | null>;
renderBoard: () => void;
cursor: CursorManager;
scoreManager: {
timeValue: number;
keystrokes: number;
finalScore: number | null;
};
scoreManager: ScoreManager;
keyLog: KeyLogEntry[];
clearKeyLog: () => void;
getKeyLog: () => KeyLogEntry[];