From b725498696d9af55f39678f6fcbc7045943c9ce0 Mon Sep 17 00:00:00 2001 From: "gpt-engineer-app[bot]" <159125892+gpt-engineer-app[bot]@users.noreply.github.com> Date: Mon, 21 Jul 2025 07:41:09 +0000 Subject: [PATCH] Allow range selection on new game Allow the user to choose the range again when starting a new game. --- src/components/BalancedTernaryGame.tsx | 18 ++++++++++++++---- src/components/TernaryNumberGame.tsx | 18 ++++++++++++++---- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/components/BalancedTernaryGame.tsx b/src/components/BalancedTernaryGame.tsx index e105065..eb57c0b 100644 --- a/src/components/BalancedTernaryGame.tsx +++ b/src/components/BalancedTernaryGame.tsx @@ -51,9 +51,19 @@ const BalancedTernaryGame: React.FC = ({ showSocialSha setHasGameStarted(true); }, [targetRange]); - // Start game for the first time + // Start game for the first time or reset game 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 @@ -169,7 +179,7 @@ const BalancedTernaryGame: React.FC = ({ showSocialSha {/* Range Selection */} - {!hasGameStarted && ( + {!isGameActive && (
@@ -283,7 +293,7 @@ const BalancedTernaryGame: React.FC = ({ showSocialSha
)} - diff --git a/src/components/TernaryNumberGame.tsx b/src/components/TernaryNumberGame.tsx index cc339a4..e4c3f7d 100644 --- a/src/components/TernaryNumberGame.tsx +++ b/src/components/TernaryNumberGame.tsx @@ -46,9 +46,19 @@ const TernaryNumberGame: React.FC = ({ showSocialShare = setHasGameStarted(true); }, [targetRange]); - // Start game for the first time + // Start game for the first time or reset game 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 @@ -120,7 +130,7 @@ const TernaryNumberGame: React.FC = ({ showSocialShare = {/* Range Selection */} - {!hasGameStarted && ( + {!isGameActive && (
@@ -217,7 +227,7 @@ const TernaryNumberGame: React.FC = ({ showSocialShare =
)} -