Allow range selection on new game

Allow the user to choose the range again when starting a new game.
This commit is contained in:
gpt-engineer-app[bot] 2025-07-21 07:41:09 +00:00
parent c3e18446b6
commit b725498696
2 changed files with 28 additions and 8 deletions

View file

@ -51,9 +51,19 @@ const BalancedTernaryGame: React.FC<BalancedTernaryGameProps> = ({ showSocialSha
setHasGameStarted(true); setHasGameStarted(true);
}, [targetRange]); }, [targetRange]);
// Start game for the first time // Start game for the first time or reset game
const startGame = () => { const startGame = () => {
startNewGame(); if (hasGameStarted) {
// Reset to allow range selection
setIsGameActive(false);
setHasGameStarted(false);
setIsGameWon(false);
setTimer(0);
setCurrentSum(0);
setCardValues(new Array(8).fill(0));
} else {
startNewGame();
}
}; };
// Timer effect // Timer effect
@ -169,7 +179,7 @@ const BalancedTernaryGame: React.FC<BalancedTernaryGameProps> = ({ showSocialSha
</div> </div>
{/* Range Selection */} {/* Range Selection */}
{!hasGameStarted && ( {!isGameActive && (
<Card className="p-6"> <Card className="p-6">
<div className="space-y-4"> <div className="space-y-4">
<Label className="text-lg font-semibold">Target Number Range</Label> <Label className="text-lg font-semibold">Target Number Range</Label>
@ -283,7 +293,7 @@ const BalancedTernaryGame: React.FC<BalancedTernaryGameProps> = ({ showSocialSha
</div> </div>
)} )}
<Button onClick={hasGameStarted ? startNewGame : startGame} size="lg" className="px-8"> <Button onClick={!isGameActive ? startNewGame : startGame} size="lg" className="px-8">
{!hasGameStarted ? 'Start Game' : isGameWon ? 'Play Again' : 'New Game'} {!hasGameStarted ? 'Start Game' : isGameWon ? 'Play Again' : 'New Game'}
</Button> </Button>
</div> </div>

View file

@ -46,9 +46,19 @@ const TernaryNumberGame: React.FC<TernaryNumberGameProps> = ({ showSocialShare =
setHasGameStarted(true); setHasGameStarted(true);
}, [targetRange]); }, [targetRange]);
// Start game for the first time // Start game for the first time or reset game
const startGame = () => { const startGame = () => {
startNewGame(); if (hasGameStarted) {
// Reset to allow range selection
setIsGameActive(false);
setHasGameStarted(false);
setIsGameWon(false);
setTimer(0);
setCurrentSum(0);
setCardValues(new Array(8).fill(0));
} else {
startNewGame();
}
}; };
// Timer effect // Timer effect
@ -120,7 +130,7 @@ const TernaryNumberGame: React.FC<TernaryNumberGameProps> = ({ showSocialShare =
</div> </div>
{/* Range Selection */} {/* Range Selection */}
{!hasGameStarted && ( {!isGameActive && (
<Card className="p-6"> <Card className="p-6">
<div className="space-y-4"> <div className="space-y-4">
<Label className="text-lg font-semibold">Target Number Range</Label> <Label className="text-lg font-semibold">Target Number Range</Label>
@ -217,7 +227,7 @@ const TernaryNumberGame: React.FC<TernaryNumberGameProps> = ({ showSocialShare =
</div> </div>
)} )}
<Button onClick={hasGameStarted ? startNewGame : startGame} size="lg" className="px-8"> <Button onClick={!isGameActive ? startNewGame : startGame} size="lg" className="px-8">
{!hasGameStarted ? 'Start Game' : isGameWon ? 'Play Again' : 'New Game'} {!hasGameStarted ? 'Start Game' : isGameWon ? 'Play Again' : 'New Game'}
</Button> </Button>
</div> </div>