From cf130e6fbc40c541fe8bd32576038e313660ab40 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Sat, 6 Aug 2022 12:47:26 -0500 Subject: [PATCH] scoring --- squarenotsquare/src/screens/Game.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/squarenotsquare/src/screens/Game.js b/squarenotsquare/src/screens/Game.js index 8099f3f..f605b9e 100644 --- a/squarenotsquare/src/screens/Game.js +++ b/squarenotsquare/src/screens/Game.js @@ -19,6 +19,7 @@ function Game(props){ const [timerState, setTimerState] = useState(0); const localTimer = useRef(null); const startTime = useRef(0); + const score = useRef(0); const [scrollOrigin, setScrollOrigin] = useState(0); const scrollDestination = useRef(Metrics.animated.gameScrollInterval); const [headerText, setHeaderText] = useState('Ready?'); @@ -71,8 +72,14 @@ function Game(props){ } }, [timerState]); - function scroll(pairIndex){ + + + function selectAnswer(pairIndex, correct){ if (pairIndex === challengeState.current){ + if (correct) { + score.current = score.current + 1; + } + let newOrigin = scrollDestination.current; let newDestination = scrollDestination.current - Metrics.animated.gameScrollInterval; @@ -96,7 +103,7 @@ function Game(props){ function generateSquare(pairIndex){ return ( scroll(pairIndex)} + onPress={() => selectAnswer(pairIndex, true)} style={[styles.darkGreen, styles.answerButton, styles.dropShadow, styles.centeredItems, styles.centeredJustify]} > scroll(pairIndex)} + onPress={() => selectAnswer(pairIndex, false)} style={[styles.darkGreen, styles.answerButton, styles.dropShadow, styles.centeredItems, styles.centeredJustify]} > + + + {score.current + ' / ' + squareChallenge.current.length} + + ); }