Allow range selection on new game
Allow the user to choose the range again when starting a new game.
This commit is contained in:
parent
c3e18446b6
commit
b725498696
2 changed files with 28 additions and 8 deletions
|
|
@ -51,9 +51,19 @@ const BalancedTernaryGame: React.FC<BalancedTernaryGameProps> = ({ showSocialSha
|
|||
setHasGameStarted(true);
|
||||
}, [targetRange]);
|
||||
|
||||
// Start game for the first time
|
||||
// Start game for the first time or reset game
|
||||
const startGame = () => {
|
||||
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
|
||||
|
|
@ -169,7 +179,7 @@ const BalancedTernaryGame: React.FC<BalancedTernaryGameProps> = ({ showSocialSha
|
|||
</div>
|
||||
|
||||
{/* Range Selection */}
|
||||
{!hasGameStarted && (
|
||||
{!isGameActive && (
|
||||
<Card className="p-6">
|
||||
<div className="space-y-4">
|
||||
<Label className="text-lg font-semibold">Target Number Range</Label>
|
||||
|
|
@ -283,7 +293,7 @@ const BalancedTernaryGame: React.FC<BalancedTernaryGameProps> = ({ showSocialSha
|
|||
</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'}
|
||||
</Button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -46,9 +46,19 @@ const TernaryNumberGame: React.FC<TernaryNumberGameProps> = ({ showSocialShare =
|
|||
setHasGameStarted(true);
|
||||
}, [targetRange]);
|
||||
|
||||
// Start game for the first time
|
||||
// Start game for the first time or reset game
|
||||
const startGame = () => {
|
||||
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
|
||||
|
|
@ -120,7 +130,7 @@ const TernaryNumberGame: React.FC<TernaryNumberGameProps> = ({ showSocialShare =
|
|||
</div>
|
||||
|
||||
{/* Range Selection */}
|
||||
{!hasGameStarted && (
|
||||
{!isGameActive && (
|
||||
<Card className="p-6">
|
||||
<div className="space-y-4">
|
||||
<Label className="text-lg font-semibold">Target Number Range</Label>
|
||||
|
|
@ -217,7 +227,7 @@ const TernaryNumberGame: React.FC<TernaryNumberGameProps> = ({ showSocialShare =
|
|||
</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'}
|
||||
</Button>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue