Skip to content

Commit 43a9d2e

Browse files
committed
Finished working game v1.00
1 parent 4142d60 commit 43a9d2e

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

GameScreen.js

+47
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { Text, View, StyleSheet, TouchableHighlight} from 'react-native';
55

66
export default class GameScreen extends React.Component {
77
constructor(props) {
8+
89
super(props);
910

1011
this.state = {
@@ -14,6 +15,8 @@ export default class GameScreen extends React.Component {
1415
this.props.navigation.getParam('data').map(player =>
1516
this.state.scoreboard[player.name] = {20: 0, 19: 0, 18: 0, 17: 0, 16: 0, 15: 0, B: 0, score: 0}
1617
)
18+
19+
this.history = [JSON.parse(JSON.stringify( this.state.scoreboard ))]
1720
}
1821

1922
textColor = (clicks) => {
@@ -47,10 +50,21 @@ export default class GameScreen extends React.Component {
4750
}
4851
}
4952

53+
undoFunction = () => {
54+
console.log(this.history);
55+
if (this.history.length > 1){
56+
this.setState(prevState => {
57+
this.history.pop()
58+
return {scoreboard: JSON.parse(JSON.stringify(this.history[this.history.length-1]))}
59+
})
60+
}
61+
}
62+
5063
scoreboardButton = (name, num) => {
5164
if (this.state.scoreboard[name][num] < 3) {
5265
this.setState(prevState => {
5366
prevState.scoreboard[name][num]++;
67+
this.history.push(JSON.parse(JSON.stringify(prevState.scoreboard)));
5468
return {scoreboard: prevState.scoreboard}
5569
})
5670
}
@@ -65,6 +79,7 @@ export default class GameScreen extends React.Component {
6579
else {
6680
prevState.scoreboard[key]["score"] += num;
6781
}
82+
this.history.push(JSON.parse(JSON.stringify(prevState.scoreboard)));
6883
return {scoreboard: prevState.scoreboard}
6984
})
7085
}
@@ -140,12 +155,44 @@ export default class GameScreen extends React.Component {
140155
<View style={{ flexDirection: 'row', flex: 1}}>
141156
{buttonsListArr}
142157
</View>
158+
<View style={{flexDirection: 'row'}}>
159+
<TouchableHighlight style={{flex:1}} underLayColor='green' onPress={() => {this.undoFunction()}}>
160+
<View style={styles.undoButton}>
161+
<Text style={styles.undoText}> Undo </Text>
162+
</View>
163+
</TouchableHighlight>
164+
<TouchableHighlight style={{flex:1}} underLayColor='green' onPress={() => {this.props.navigation.navigate('Home')}}>
165+
<View style={styles.newGameButton}>
166+
<Text style={styles.newGameText}> New Game </Text>
167+
</View>
168+
</TouchableHighlight>
169+
</View>
143170
</View>
144171
);
145172
}
146173
}
147174

148175
const styles = StyleSheet.create({
176+
undoButton: {
177+
alignItems: 'center',
178+
backgroundColor: 'indianred'
179+
},
180+
undoText: {
181+
padding: 15,
182+
fontSize: 25,
183+
fontWeight: 'bold',
184+
color: 'white'
185+
},
186+
newGameButton: {
187+
alignItems: 'center',
188+
backgroundColor: '#2196F3'
189+
},
190+
newGameText: {
191+
padding: 15,
192+
fontSize: 25,
193+
fontWeight: 'bold',
194+
color: 'white'
195+
},
149196
playerContainer: {
150197
height: 70,
151198
alignItems: 'center',

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@
2222
},
2323
"dependencies": {
2424
"expo": "^27.0.1",
25+
"lodash": "^4.17.10",
2526
"react": "16.3.1",
2627
"react-native": "~0.55.2",
2728
"react-native-elements": "^0.19.1",
2829
"react-native-material-design": "^0.3.7",
2930
"react-native-swipeout": "^2.3.3",
3031
"react-native-vector-icons": "^4.6.0",
31-
"react-navigation": "^2.6.2"
32+
"react-navigation": "^2.6.2",
33+
"underscore": "^1.9.1"
3234
}
3335
}

0 commit comments

Comments
 (0)