Browse Source

rename game ref

pull/8/head
Tim Glasgow 3 years ago
parent
commit
31234ed027
  1. 10
      squarenotsquare/src/screens/Game.js

10
squarenotsquare/src/screens/Game.js

@ -21,7 +21,7 @@ function Game(props){
const [timerState, setTimerState] = useState(0); const [timerState, setTimerState] = useState(0);
const localTimer = useRef(null); const localTimer = useRef(null);
const startTime = useRef(0); const startTime = useRef(0);
const score = useRef(0); const answers = useRef(0);
const [scrollOrigin, setScrollOrigin] = useState(0); const [scrollOrigin, setScrollOrigin] = useState(0);
const scrollDestination = useRef(Metrics.animated.gameScrollInterval); const scrollDestination = useRef(Metrics.animated.gameScrollInterval);
const [headerText, setHeaderText] = useState('Ready?'); const [headerText, setHeaderText] = useState('Ready?');
@ -80,7 +80,7 @@ function Game(props){
function selectAnswer(pairIndex, correct){ function selectAnswer(pairIndex, correct){
if (pairIndex === challengeState.current){ if (pairIndex === challengeState.current){
if (correct) { if (correct) {
score.current = score.current + 1; answers.current = answers.current + 1;
} }
let newOrigin = scrollDestination.current; let newOrigin = scrollDestination.current;
@ -102,9 +102,7 @@ function Game(props){
setHeaderColor(styles.darkGreen); setHeaderColor(styles.darkGreen);
setHeaderText(finalTime + ' s'); setHeaderText(finalTime + ' s');
setTimerState(4); setTimerState(4);
setTimeout(() => { dispatch(squareFinished(answers.current, finalTime));
dispatch(squareFinished(score.current, finalTime));
}, 3000);
} }
function generateSquare(pairIndex){ function generateSquare(pairIndex){
@ -194,7 +192,7 @@ function Game(props){
</View> </View>
<View style={[styles.timerView, styles.dark, styles.centeredJustify]}> <View style={[styles.timerView, styles.dark, styles.centeredJustify]}>
<Text style={[styles.lightText, styles.headerTitleFont, styles.centeredText]}> <Text style={[styles.lightText, styles.headerTitleFont, styles.centeredText]}>
{score.current + ' / ' + squareChallenge.current.length} {answers.current + ' / ' + squareChallenge.current.length}
</Text> </Text>
</View> </View>
</SafeAreaView> </SafeAreaView>

Loading…
Cancel
Save