From efec9f91c7ae35f9a13931137a4e77117b4c6b04 Mon Sep 17 00:00:00 2001 From: Tim Glasgow Date: Tue, 9 Aug 2022 18:49:39 -0500 Subject: [PATCH] Addition game navigation and redux action --- .../src/components/ScrollingPicker.js | 8 ++++---- squarenotsquare/src/libs/Random.js | 17 +++++++++++++++++ squarenotsquare/src/navigation/SquareStack.js | 6 ++++++ .../src/redux/actions/UserActions.js | 19 +++++++++++++------ squarenotsquare/src/redux/types/UserTypes.js | 4 +++- squarenotsquare/src/screens/Game.js | 4 ++-- squarenotsquare/src/screens/Home.js | 12 ++++++++---- 7 files changed, 53 insertions(+), 17 deletions(-) diff --git a/squarenotsquare/src/components/ScrollingPicker.js b/squarenotsquare/src/components/ScrollingPicker.js index 95e20eb..8122f33 100644 --- a/squarenotsquare/src/components/ScrollingPicker.js +++ b/squarenotsquare/src/components/ScrollingPicker.js @@ -15,9 +15,9 @@ function ScrollingPicker(props) { function onScroll(event){ if (event.nativeEvent.contentOffset.x === 0) { - props.modeSetter(0); + props.modeSetter('square'); } else if (event.nativeEvent.contentOffset.x === (Metrics.icons.buttonIcon * 2)) { - props.modeSetter(1); + props.modeSetter('addition'); } Animated.event([ { @@ -39,7 +39,7 @@ function ScrollingPicker(props) { onScroll={onScroll} scrollEventThrottle={0} > - + - + = 10); + + result.push({left: left, right: right}); + } + return result; } \ No newline at end of file diff --git a/squarenotsquare/src/navigation/SquareStack.js b/squarenotsquare/src/navigation/SquareStack.js index 5eee0cb..379fa99 100644 --- a/squarenotsquare/src/navigation/SquareStack.js +++ b/squarenotsquare/src/navigation/SquareStack.js @@ -9,6 +9,7 @@ import HighScore from '../screens/HighScore'; import Settings from '../screens/Settings'; import Splash from '../screens/Splash'; import Score from '../screens/Score'; +import AdditionGame from '../screens/AdditionGame'; const SquareNav = createStackNavigator(); @@ -43,6 +44,11 @@ function SquareStack() { component={Game} options={noHeader} /> + { - squareNav('Game'); - dispatch({ - type: SQUARE_START - }); + if (mode === 'square') { + squareNav('Game'); + dispatch({ + type: SQUARE_START + }); + } else if (mode === 'addition') { + squareNav('AdditionGame'); + dispatch({ + type: ADDITION_START + }) + } } } diff --git a/squarenotsquare/src/redux/types/UserTypes.js b/squarenotsquare/src/redux/types/UserTypes.js index 1f20595..bba52a3 100644 --- a/squarenotsquare/src/redux/types/UserTypes.js +++ b/squarenotsquare/src/redux/types/UserTypes.js @@ -1,2 +1,4 @@ export const SQUARE_START = 'square-start'; -export const SQUARE_FINISHED = 'square-finished'; \ No newline at end of file +export const SQUARE_FINISHED = 'square-finished'; +export const ADDITION_START = 'addition-start'; +export const ADDITION_FINISHED = 'addition-finished'; \ No newline at end of file diff --git a/squarenotsquare/src/screens/Game.js b/squarenotsquare/src/screens/Game.js index a310918..468766c 100644 --- a/squarenotsquare/src/screens/Game.js +++ b/squarenotsquare/src/screens/Game.js @@ -139,7 +139,7 @@ function Game(props){ function generatePair(answer, shapeIndex, pairIndex) { if (answer === 0) { return ( - + {generateSquare(pairIndex)} {generateShape(shapeIndex, pairIndex)} @@ -148,7 +148,7 @@ function Game(props){ ); } else { return ( - + {generateShape(shapeIndex, pairIndex)} {generateSquare(pairIndex)} diff --git a/squarenotsquare/src/screens/Home.js b/squarenotsquare/src/screens/Home.js index d9835e0..37c4a98 100644 --- a/squarenotsquare/src/screens/Home.js +++ b/squarenotsquare/src/screens/Home.js @@ -13,20 +13,24 @@ import ModePicker from '../components/ScrollingPicker'; function Home(){ const dispatch = useDispatch(); - const [mode, setMode] = useState(0); + const [mode, setMode] = useState('square'); useEffect(() => { BackHandler.addEventListener('hardwareBackPress', () => {return true}); }, []) function onPressStart(){ - dispatch(squareStartPressed()); + dispatch(squareStartPressed(mode)); } function onPressHighScores(){ dispatch(goToScores()); } + function setGameMode(newMode) { + setMode(newMode); + } + const now = new Date(Date.now()); return ( @@ -51,9 +55,9 @@ function Home(){ - + - {mode === 0 ? 'Squares' : 'Addition'} + {mode === 'square' ? 'Squares' : 'Addition'}