From f48f7863cc311dae2cf0a04cf2602e83e7c63083 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Fri, 22 Aug 2025 11:08:33 +0000 Subject: [PATCH] Add hollow circles for empty state Replace pebbles with hollow circles with a thin grey border when they are all gone. -edited `src/components/SubtractionGame.tsx --- src/components/SubtractionGame.tsx | 44 ++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/src/components/SubtractionGame.tsx b/src/components/SubtractionGame.tsx index e9574f0..4391679 100644 --- a/src/components/SubtractionGame.tsx +++ b/src/components/SubtractionGame.tsx @@ -8,6 +8,7 @@ const SubtractionGame = () => { const [k, setK] = useState([3]); const [gameStarted, setGameStarted] = useState(false); const [circles, setCircles] = useState([]); + const [removedCircles, setRemovedCircles] = useState>(new Set()); const [currentPlayer, setCurrentPlayer] = useState<'Lata' | 'Raj'>('Lata'); const [winner, setWinner] = useState(null); const [highlightedIndices, setHighlightedIndices] = useState([]); @@ -23,18 +24,21 @@ const SubtractionGame = () => { // Calculate highlighted indices useEffect(() => { if (circles.length > 0) { + const activeCircles = circles.filter(i => !removedCircles.has(i)); const lastKIndices = []; - const start = Math.max(0, circles.length - k[0]); - for (let i = start; i < circles.length; i++) { - lastKIndices.push(i); + const activeCount = activeCircles.length; + const start = Math.max(0, activeCount - k[0]); + for (let i = start; i < activeCount; i++) { + lastKIndices.push(activeCircles[i]); } setHighlightedIndices(lastKIndices); } - }, [circles, k]); + }, [circles, k, removedCircles]); const startGame = () => { const initialCircles = Array.from({ length: n[0] }, (_, i) => i); setCircles(initialCircles); + setRemovedCircles(new Set()); setGameStarted(true); setCurrentPlayer('Lata'); setWinner(null); @@ -43,6 +47,7 @@ const SubtractionGame = () => { const resetGame = () => { setGameStarted(false); setCircles([]); + setRemovedCircles(new Set()); setWinner(null); setCurrentPlayer('Lata'); setHighlightedIndices([]); @@ -50,16 +55,25 @@ const SubtractionGame = () => { }; const handleCircleClick = (index: number) => { - if (!gameStarted || winner || !highlightedIndices.includes(index)) { + if (!gameStarted || winner || !highlightedIndices.includes(index) || removedCircles.has(index)) { return; } - // Remove all circles to the right of clicked circle - const newCircles = circles.slice(0, index); - setCircles(newCircles); + // Mark all circles from clicked index onwards as removed + const newRemovedCircles = new Set(removedCircles); + const activeCircles = circles.filter(i => !removedCircles.has(i)); + const clickedPosition = activeCircles.indexOf(index); + + // Remove all circles from clicked position onwards + for (let i = clickedPosition; i < activeCircles.length; i++) { + newRemovedCircles.add(activeCircles[i]); + } + + setRemovedCircles(newRemovedCircles); - // Check if game is over - if (newCircles.length === 0) { + // Check if game is over (no active circles left) + const remainingActive = circles.filter(i => !newRemovedCircles.has(i)); + if (remainingActive.length === 0) { setWinner(currentPlayer); setGameStarted(false); // Trigger confetti @@ -81,8 +95,14 @@ const SubtractionGame = () => { }; const getCircleClass = (index: number) => { + const isRemoved = removedCircles.has(index); const isHighlighted = highlightedIndices.includes(index); const isHovered = hoveredIndex !== null && index >= hoveredIndex; + + if (isRemoved) { + return 'w-8 h-8 rounded-full border border-gray-300 bg-transparent'; + } + const baseClass = `w-8 h-8 rounded-full border-2 border-black transition-colors ${isHighlighted ? 'cursor-pointer' : ''}`; let fillClass; @@ -183,7 +203,7 @@ const SubtractionGame = () => { key={index} className={getCircleClass(index)} onClick={() => handleCircleClick(index)} - onMouseEnter={() => highlightedIndices.includes(index) ? setHoveredIndex(index) : null} + onMouseEnter={() => (highlightedIndices.includes(index) && !removedCircles.has(index)) ? setHoveredIndex(index) : null} onMouseLeave={() => setHoveredIndex(null)} title={highlightedIndices.includes(index) ? 'Click to select' : 'Not selectable'} /> @@ -193,7 +213,7 @@ const SubtractionGame = () => { {circles.length > 0 && (

- {highlightedIndices.length} circle(s) highlighted • Last {Math.min(k[0], circles.length)} positions + {highlightedIndices.length} circle(s) highlighted • Last {Math.min(k[0], circles.filter(i => !removedCircles.has(i)).length)} positions

)}