import { useEffect, useRef } from "react"; import { useGame } from "@vimazing/typing-chud"; import "@vimazing/typing-chud/game.css"; import type { GameManager } from "@vimazing/typing-chud"; import { useKeyBindings } from "./useKeyBindings"; import { useMounted } from "./useMounted"; function App() { const gameManager = useGame({}, useKeyBindings); const { containerRef, gameStatus, scoreManager, renderBoard, cursor } = gameManager; const gameManagerRef = useRef(gameManager); const [mounted] = useMounted(); useEffect(() => { gameManagerRef.current = gameManager; }, [gameManager]); // Re-render board when cursor position changes useEffect(() => { if (mounted) { renderBoard(); } }, [cursor.position(), renderBoard, mounted]); const formatTime = (ms: number) => { const seconds = Math.floor(ms / 1000); const minutes = Math.floor(seconds / 60); const remainingSeconds = seconds % 60; return `${minutes}:${remainingSeconds.toString().padStart(2, "0")}`; }; return (

Typing Chud

Time: {formatTime(scoreManager.timeValue)}
Keystrokes: {scoreManager.totalKeystrokes}
{gameStatus === "waiting" &&

Press space to start

} {gameStatus === "started" &&

Game running...

} {gameStatus === "game-over" &&

Game Over! Press space to restart

} {gameStatus === "game-won" &&

You Won! Press space to restart

}
); } export default App;