Browse Source

Addition screen implementation

pull/8/head
Tim Glasgow 2 years ago
parent
commit
86b5233c8f
  1. 19
      squarenotsquare/src/redux/actions/UserActions.js
  2. 4
      squarenotsquare/src/redux/reducers/UserReducer.js
  3. 39
      squarenotsquare/src/screens/AdditionGame.js
  4. 4
      squarenotsquare/src/screens/styles/AppStyles.js
  5. 17
      squarenotsquare/src/themes/Metrics.js

19
squarenotsquare/src/redux/actions/UserActions.js

@ -1,5 +1,5 @@
import { squareNav } from "../../navigation/SquareNav"; import { squareNav } from "../../navigation/SquareNav";
import { ADDITION_START, SQUARE_FINISHED, SQUARE_START } from "../types/UserTypes"; import { ADDITION_FINISHED, ADDITION_START, SQUARE_FINISHED, SQUARE_START } from "../types/UserTypes";
import { calculateSquareScore } from "../../libs/CalculateScore"; import { calculateSquareScore } from "../../libs/CalculateScore";
import DbAPI from "../../realm/DbAPI"; import DbAPI from "../../realm/DbAPI";
@ -34,4 +34,21 @@ export function squareFinished(answers, finalTime) {
user: newUser user: newUser
}); });
} }
}
export function addFinished(answers, finalTime) {
return (dispatch, getState) => {
setTimeout(() => squareNav('Score'), 3000);
const userState = getState().user;
let newUser = {...userState};
newUser.lastGameTime = finalTime;
newUser.lastGameAnswers = answers;
let finalScore = calculateSquareScore(answers, finalTime);
DbAPI.createScore(userState.username, finalScore);
dispatch({
type: ADDITION_FINISHED,
user: newUser
});
}
} }

4
squarenotsquare/src/redux/reducers/UserReducer.js

@ -1,7 +1,8 @@
import { APP_INIT } from "../types/SystemTypes"; import { APP_INIT } from "../types/SystemTypes";
import { import {
SQUARE_START, SQUARE_START,
SQUARE_FINISHED SQUARE_FINISHED,
ADDITION_FINISHED
} from '../types/UserTypes'; } from '../types/UserTypes';
const initialUserState = { const initialUserState = {
@ -15,6 +16,7 @@ function usr(state = initialUserState, action) {
switch (action.type) { switch (action.type) {
case SQUARE_START: case SQUARE_START:
case SQUARE_FINISHED: case SQUARE_FINISHED:
case ADDITION_FINISHED:
return {...state, ...action.user}; return {...state, ...action.user};
default: default:
return state; return state;

39
squarenotsquare/src/screens/AdditionGame.js

@ -11,6 +11,7 @@ import MaterialIcon from 'react-native-vector-icons/MaterialCommunityIcons';
import Icons from '../themes/Icons'; import Icons from '../themes/Icons';
import Colors from "../themes/Colors"; import Colors from "../themes/Colors";
import Metrics from "../themes/Metrics"; import Metrics from "../themes/Metrics";
import { addFinished } from "../redux/actions/UserActions";
function AdditionGame(props){ function AdditionGame(props){
@ -77,8 +78,14 @@ function AdditionGame(props){
function selectAnswer(answer){ function selectAnswer(answer){
//fix let currentChallenge = addChallenge[challengeState.current];
if (true) { let outcome = (
answer === (
currentChallenge.left + currentChallenge.right
)
);
if (outcome) {
answers.current = answers.current + 1; answers.current = answers.current + 1;
} }
@ -101,13 +108,13 @@ function AdditionGame(props){
setHeaderColor(styles.darkGreen); setHeaderColor(styles.darkGreen);
setHeaderText(finalTime + ' s'); setHeaderText(finalTime + ' s');
setTimerState(4); setTimerState(4);
// dispatch(squareFinished(answers.current, finalTime)); dispatch(addFinished(answers.current, finalTime));
} }
function generateLine(left, right, pairIndex) { function generateLine(left, right, pairIndex) {
return ( return (
<Fade key={pairIndex} faded={challengeState.current !== pairIndex} duration={250}> <Fade key={pairIndex} faded={challengeState.current !== pairIndex} duration={250}>
<View style={[styles.buttonMargin]}> <View style={[styles.buttonMargin, styles.addQuestionHeight]}>
<Text style={[styles.headerTitleFont, styles.darkText, styles.centeredText]}> <Text style={[styles.headerTitleFont, styles.darkText, styles.centeredText]}>
{left + ' + ' + right + ' = '} {left + ' + ' + right + ' = '}
</Text> </Text>
@ -134,19 +141,21 @@ function AdditionGame(props){
origin={scrollOrigin} origin={scrollOrigin}
destination={scrollDestination.current} destination={scrollDestination.current}
duration={250} duration={250}
style={{overflow: 'hidden'}}
> >
<View style={[styles.gameView]} />
{squareMemo} {squareMemo}
<View style={[styles.gameView, styles.flexRow, styles.spaceEvenly, styles.centeredItems]}> <Fade faded={challengeState.current < 20} duration={250}>
<MaterialIcon <View style={[styles.gameView, styles.flexRow, styles.spaceEvenly, styles.centeredItems]}>
name={Icons.squareIcons.check} <MaterialIcon
color={Colors.material.green800} name={Icons.squareIcons.check}
size={Metrics.icons.buttonIcon} color={Colors.material.green800}
/> size={Metrics.icons.buttonIcon}
<Text style={[styles.headerTitleFont, styles.greyText]}> />
Finish <Text style={[styles.headerTitleFont, styles.greyText]}>
</Text> Finish
</View> </Text>
</View>
</Fade>
</Autoscroll> </Autoscroll>
</View> </View>
<View style={[styles.timerView, styles.dark, styles.centeredJustify]}> <View style={[styles.timerView, styles.dark, styles.centeredJustify]}>

4
squarenotsquare/src/screens/styles/AppStyles.js

@ -109,6 +109,10 @@ export const styles = StyleSheet.create({
height: Metrics.buttons.answerButton.height height: Metrics.buttons.answerButton.height
}, },
addQuestionHeight: {
height: Metrics.screenSections.addQuestionHeight
},
nineKeyButton: { nineKeyButton: {
borderRadius: Metrics.buttons.borderRadius, borderRadius: Metrics.buttons.borderRadius,
width: Metrics.buttons.nineKeyButton.width, width: Metrics.buttons.nineKeyButton.width,

17
squarenotsquare/src/themes/Metrics.js

@ -22,13 +22,6 @@ class AppMetrics {
opacity: 0.5, opacity: 0.5,
radius: 5 radius: 5
} }
this.screenSections = {
headerHeight: this.normalize(20),
sectionWidth: this.screenWidth,
footerHeight: this.normalize(10),
timerHeight: this.normalize(20)
}
this.icons = { this.icons = {
splashIcon: this.normalize(100), splashIcon: this.normalize(100),
@ -66,12 +59,20 @@ class AppMetrics {
} }
this.animated = { this.animated = {
squareInterval: ( gameScrollInterval: (
this.buttons.answerButton.height + this.buttons.answerButton.height +
(this.margins.buttonMargin * 2) (this.margins.buttonMargin * 2)
) )
} }
this.screenSections = {
headerHeight: this.normalize(20),
sectionWidth: this.screenWidth,
footerHeight: this.normalize(10),
timerHeight: this.normalize(20),
addQuestionHeight: this.buttons.answerButton.height
}
this.borders = { this.borders = {
width: 1 width: 1
} }

Loading…
Cancel
Save