From 6f4a1accc4180144a32ac18b6e02d3480f31b48d Mon Sep 17 00:00:00 2001 From: Andre Padez Date: Wed, 22 Oct 2025 18:42:35 +0100 Subject: [PATCH] feat: add difficulty selector to example app Add interactive difficulty selection when game is idle: Example App Changes: - example/src/App.tsx: Add difficulty state and radio group - Import useState and Difficulty type - Radio buttons for Easy/Medium/Hard - Only visible when gameStatus === 'waiting' - Updates difficulty state on selection - Passes selected difficulty to useGame Core Changes: - src/useGame.ts: Respect difficulty changes - Add difficulty to useEffect dependencies - Regenerates board when difficulty changes UX Flow: 1. User sees difficulty selector on idle screen 2. Selects difficulty (easy/medium/hard) 3. Presses Space to start 4. Puzzle generated with selected difficulty 5. On quit, returns to selector with last selection Cell Counts: - Easy: 40 empty cells (~41 givens) - Medium: 50 empty cells (~31 givens) - Hard: 60 empty cells (~21 givens) --- example/src/App.tsx | 49 ++++++++++++++++++++++++++++++++++++++++++++- src/useGame.ts | 2 +- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index fc6b80a..f787f3a 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -1,9 +1,12 @@ +import { useState } from "react"; import { useGame } from "../../src/useGame"; import { useKeyBindings } from "./useKeyBindings"; +import type { Difficulty } from "../../src/types"; import '../../src/game.css'; function App() { - const gameManager = useGame({ difficulty: 'medium' }, useKeyBindings); + const [difficulty, setDifficulty] = useState('medium'); + const gameManager = useGame({ difficulty }, useKeyBindings); const { containerRef, gameStatus, scoreManager } = gameManager; const { timeValue, keystrokes, finalScore } = scoreManager; @@ -17,6 +20,50 @@ function App() { return (

VIMazing vim-sudoku example

+ + {gameStatus === "waiting" && ( +
+
+
Select Difficulty
+
+ + + +
+
+
+ )} +
{(gameStatus === "started" || gameStatus === "game-won") && (
diff --git a/src/useGame.ts b/src/useGame.ts index 941533d..4fe9c94 100644 --- a/src/useGame.ts +++ b/src/useGame.ts @@ -21,7 +21,7 @@ export function useGame(options: GameOptions = {}, platformHook?: unknown): Game } else if (gameStatus === 'waiting') { renderBoard(); } - }, [gameStatus]); + }, [gameStatus, difficulty]); const gameManager: GameManager = { containerRef,