- Add GameMode type: 'letters' | 'words' | 'sentences' | 'paragraphs' - Add gameMode option to GameOptions (defaults to 'letters') - Create wordLists.ts with curated word lists for each mode - Update FallingLetter type to track: - fullText: complete word/sentence/paragraph - charIndex: current character progress in word - Modify word spawning to pick from mode-specific word list - Update handleTypedLetter to support multi-character typed sequences: - Track progress through word (charIndex) - Advance to next character when correct - Show complete word only when fully typed - Enhanced canvas rendering with color-coded progress: - Green: completed characters - Yellow: current character being typed - White: remaining characters - Add mode selector buttons to example app - Default to 'words' mode in example for testing - Full TypeScript support for all modes
163 lines
5.2 KiB
TypeScript
Executable File
163 lines
5.2 KiB
TypeScript
Executable File
import type { RefObject } from 'react';
|
|
|
|
// ============================================================================
|
|
// Core Game Types
|
|
// ============================================================================
|
|
|
|
export type GameStatus = 'waiting' | 'started' | 'game-won' | 'game-over';
|
|
export type GamePhase = 'idle' | 'playing';
|
|
export type PlayStatus = 'started' | 'game-over' | 'game-won';
|
|
export type GameMode = 'letters' | 'words' | 'sentences' | 'paragraphs';
|
|
|
|
export const isPlaying = (status: GameStatus): status is PlayStatus =>
|
|
status === 'started' || status === 'game-over' || status === 'game-won';
|
|
|
|
export const getGamePhase = (status: GameStatus): GamePhase =>
|
|
status === 'waiting' ? 'idle' : 'playing';
|
|
|
|
// ============================================================================
|
|
// Game-Specific Types
|
|
// ============================================================================
|
|
|
|
export type PlayerPosition = { x: number }; // pixel position 0-800
|
|
|
|
export type LetterState = 'normal' | 'wrong' | 'exploding';
|
|
export type ShipState = 'normal' | 'exploding';
|
|
|
|
export type FallingLetter = {
|
|
id: string;
|
|
letter: string;
|
|
x: number; // 0-800 pixel position
|
|
y: number; // 0-600 pixel position
|
|
state: LetterState;
|
|
stateStartTime?: number; // For animation timing
|
|
// For word/sentence/paragraph modes
|
|
fullText?: string; // The complete word/sentence/paragraph
|
|
charIndex?: number; // Current character index being typed (0-based)
|
|
};
|
|
|
|
// ============================================================================
|
|
// Input & Key Tracking
|
|
// ============================================================================
|
|
|
|
export type KeyLogEntry = { key: string; timestamp: number };
|
|
|
|
export type GameOptions = {
|
|
gameMode?: GameMode;
|
|
};
|
|
|
|
// ============================================================================
|
|
// Manager Interfaces - Board
|
|
// ============================================================================
|
|
|
|
export type BoardManager = {
|
|
containerRef: RefObject<HTMLDivElement | null>;
|
|
renderBoard: (cols: number, rows: number) => void;
|
|
};
|
|
|
|
// ============================================================================
|
|
// Manager Interfaces - Cursor/Snake
|
|
// ============================================================================
|
|
|
|
export type CursorMode = 'normal';
|
|
|
|
export type CursorManager = {
|
|
position: () => PlayerPosition;
|
|
mode: () => CursorMode;
|
|
|
|
// VIM-style motions (required by Unified API)
|
|
moveLeft: (count?: number) => void;
|
|
moveRight: (count?: number) => void;
|
|
moveUp: (count?: number) => void;
|
|
moveDown: (count?: number) => void;
|
|
moveToStart: () => void;
|
|
moveToEnd: () => void;
|
|
moveToTop: () => void;
|
|
moveToBottom: () => void;
|
|
repeatLastMotion: () => void;
|
|
};
|
|
|
|
// TODO: Define game-specific CursorManager extension if needed
|
|
|
|
// ============================================================================
|
|
// Manager Interfaces - Score
|
|
// ============================================================================
|
|
|
|
export type ScoreManager = {
|
|
timeValue: number;
|
|
totalKeystrokes: number;
|
|
score: number;
|
|
correct: number;
|
|
missed: number;
|
|
deaths: number;
|
|
};
|
|
|
|
// ============================================================================
|
|
// Manager Interfaces - Game Status
|
|
// ============================================================================
|
|
|
|
export type GameStatusManager = {
|
|
gameStatus: GameStatus;
|
|
setGameStatus: (status: GameStatus) => void;
|
|
startGame: () => void;
|
|
quitGame: () => void;
|
|
level: number;
|
|
shipState: ShipState;
|
|
shipExplosionTime: number;
|
|
updatePlayerX: (x: number) => void;
|
|
handleTypedLetter: (letter: string) => void;
|
|
setGameLoopCallback: (callback: (deltaTime: number, letters: FallingLetter[]) => void) => void;
|
|
addCorrect: () => void;
|
|
addMissed: () => void;
|
|
addDeath: () => void;
|
|
score: number;
|
|
correct: number;
|
|
missed: number;
|
|
deaths: number;
|
|
};
|
|
|
|
// ============================================================================
|
|
// Manager Interfaces - Key Tracking
|
|
// ============================================================================
|
|
|
|
export type GameKeyManager = {
|
|
keyLog: KeyLogEntry[];
|
|
clearKeyLog: () => void;
|
|
getKeyLog: () => KeyLogEntry[];
|
|
};
|
|
|
|
// ============================================================================
|
|
// Unified Game Manager - Main Interface
|
|
// ============================================================================
|
|
|
|
export type GameManager = {
|
|
// Required rendering
|
|
containerRef: RefObject<HTMLDivElement | null>;
|
|
renderBoard: () => void;
|
|
|
|
// Required managers
|
|
cursor: CursorManager;
|
|
scoreManager: ScoreManager;
|
|
|
|
// Required lifecycle
|
|
gameStatus: GameStatus;
|
|
setGameStatus: (status: GameStatus) => void;
|
|
startGame: () => void;
|
|
quitGame: () => void;
|
|
|
|
// Required key tracking
|
|
keyLog: KeyLogEntry[];
|
|
clearKeyLog: () => void;
|
|
getKeyLog: () => KeyLogEntry[];
|
|
|
|
// Game-specific
|
|
handleTypedLetter: (letter: string) => void;
|
|
};
|
|
|
|
// ============================================================================
|
|
// Hook Return Types
|
|
// ============================================================================
|
|
|
|
// Forward declarations for hook return types
|
|
// These will be imported from their respective modules
|