-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
51 lines (46 loc) · 1.3 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { StyleSheet, View, Button, Text } from "react-native";
import { useRef, useState } from "react";
import Grid from "./components/Grid";
import ModalPopup from "./components/ModalPopup";
export default function App() {
const [gameStatus, setGameStatus] = useState("playing");
const [gameId, setGameId] = useState(0);
const modalMessage = useRef(null);
if (gameStatus !== "playing") {
modalMessage.current = gameStatus;
}
const resetGame = () => {
setGameId(gameId + 1);
setGameStatus("playing");
};
return (
<View style={styles.container}>
<Text style={styles.title}>Minesweeper</Text>
<Grid key={gameId} setGameStatus={setGameStatus} />
<Button title="New Game" onPress={resetGame} />
<ModalPopup visible={gameStatus !== "playing"}>
<Text style={styles.modalTitle}>{`You ${modalMessage.current}!`}</Text>
<Button title="Retry" onPress={resetGame} />
</ModalPopup>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "space-evenly",
alignItems: "center",
backgroundColor: "#c6c6c6",
},
title: {
fontSize: 50,
fontWeight: "bold",
textAlign: "center",
},
modalTitle: {
fontSize: 30,
fontWeight: "bold",
textAlign: "center",
marginBottom: 30,
},
});