chore: initialize typing-chud project with Unified API structure

- Copy vim-snake structure stripped of game-specific logic
- Remove finalScore calculation (raw data only)
- Setup example app with keybinding state management
- Empty board renders and waits for game logic
This commit is contained in:
2025-11-03 21:36:09 +00:00
commit 80f7aa3f8a
40 changed files with 3987 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
import { useEffect } from "react";
import type { GameManager } from "../../src";
export const useKeyBindings = (gameManager: GameManager) => {
const { gameStatus, renderBoard, startGame, quitGame, clearKeyLog } = gameManager;
useEffect(() => {
const handler = (ev: KeyboardEvent) => {
// start game
if (ev.code === "Space") {
if (["waiting", "game-over", "game-won"].includes(gameStatus)) {
clearKeyLog();
renderBoard();
if (gameStatus === "game-over" || gameStatus === "game-won") {
quitGame();
setTimeout(() => startGame(), 0);
} else {
startGame();
}
return;
}
}
// ignore other keys while waiting
if (gameStatus === "waiting") return;
// quit
if (ev.key === "q" || ev.key === "Q") {
quitGame();
return;
}
};
window.addEventListener("keydown", handler);
return () => window.removeEventListener("keydown", handler);
}, [gameStatus]);
};