-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
88 lines (77 loc) · 2.05 KB
/
App.js
File metadata and controls
88 lines (77 loc) · 2.05 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import {
ImageBackground,
SafeAreaView,
StyleSheet,
StatusBar,
} from "react-native";
import StartMenu from "./screens/StartMenu";
import Game from "./screens/Game";
import GameOver from "./screens/GameOver";
import { LinearGradient } from "expo-linear-gradient";
import { useState } from "react";
import colors from "./constants/colors";
import {useFonts} from "expo-font";
import AppLoading from "expo-app-loading";
export default function App() {
const [textInput, setInputInput] = useState("");
const [gameOver, setGameOver] = useState(false);
const [totalGuess, setTotalGuess] = useState(0);
const [guess, setGuess] = useState("");
const [isLoading] = useFonts({
"open-sans-bold": require("./assets/fonts/OpenSans-Bold.ttf"),}
);
if(!isLoading){
<AppLoading/>
};
let screen = <StartMenu textValue={changeText} />;
function changeText(text) {
setInputInput(text);
setGameOver(false);
}
function restart(){
setGameOver(false);
setInputInput(null);
setTotalGuess(0);
setGuess(null);
screen =<StartMenu textValue={changeText} />
}
function onGameOver(paraTotalGuess, paraGuess) {
setTotalGuess(paraTotalGuess);
setGuess(paraGuess);
setGameOver(true);
}
if (textInput) {
screen = <Game textValue={textInput} onGameOver={onGameOver} />;
}
if (gameOver && textInput) {
console.log(totalGuess);
screen = <GameOver total={totalGuess} guess={guess} restart={restart}/>;
}
return (
<LinearGradient
colors={[colors.primary1, colors.primary2]}
style={styles.screen}
>
<ImageBackground
source={require("./assets/images/background.png")}
resizeMode="cover"
style={styles.screen}
imageStyle={styles.backgroundImage}
>
<SafeAreaView style={styles.safearea}>{screen}</SafeAreaView>
</ImageBackground>
</LinearGradient>
);
}
const styles = StyleSheet.create({
screen: {
flex: 1,
},
safearea: {
flex: 1,
marginTop: StatusBar.currentHeight,
},
backgroundImage: {
opacity: 0.25,
},
});