-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
112 lines (98 loc) · 3.16 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
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { StatusBar } from 'expo-status-bar';
import {ImageBackground, SafeAreaView, StyleSheet, Text, View} from 'react-native';
import StartGameScreen from "./screens/StartGameScreen";
import {LinearGradient} from "expo-linear-gradient";
import {useEffect, useState} from "react";
import GameScreen from "./screens/GameScreen";
import Colors from "./util/colors";
import GameOverScreen from "./screens/GameOverScreen";
import {useFonts} from 'expo-font';
import AppLoading from "expo-app-loading";
// import * as SplashScreen from "expo-splash-screen";
// SplashScreen.preventAutoHideAsync()
export default function App() {
const [userNumber, setUserNumber] = useState(null);
const [gameOver, setGameOver] = useState(false);
const [rounds, setRounds] = useState(0);
const [fontsLoaded] = useFonts({
'open-sans': require('./assets/fonts/OpenSans-Regular.ttf'),
'open-sans-bold': require('./assets/fonts/OpenSans-Bold.ttf'),
});
// useEffect(() => {
//
// }, [userNumber, gameOver, rounds]);
if (!fontsLoaded) {
return <AppLoading />
}
function startGameHandler(enteredNumber) {
setUserNumber(enteredNumber);
setGameOver(false);
setRounds(0);
}
function handleRestart() {
console.log('restart')
setRounds(0);
setUserNumber(null);
// setGameOver(false);
console.log('(RESTART) Rounds: ', rounds);
console.log('(RESTART) User number: ', userNumber)
console.log('(RESTART) Game over bool: ', gameOver)
}
function incrementRounds() {
setRounds((prevState) => {
return prevState + 1
})
}
let screen = <StartGameScreen onPickedNumber={startGameHandler}/>
if (userNumber) {
screen = <GameScreen pickedNumber={userNumber} onGameOver={gameOverHandler} />
}
if (gameOver && userNumber) {
console.log('Game over: ', gameOver);
console.log('user number: ', userNumber)
screen = <GameOverScreen rounds={rounds} pickedNumber={userNumber} onRestart={handleRestart} />
}
function gameOverHandler(rounds) {
setGameOver(true);
setRounds(rounds);
}
return (
<>
<StatusBar style={'light'}/>
<LinearGradient
style={styles.rootScreen}
colors={[
Colors.primary700,
Colors.accent500,
]}
>
<ImageBackground
source={require('./assets/images/background.png')}
resizeMode='cover'
style={styles.rootScreen}
imageStyle={styles.backgroundImage}
>
{/*<StartGameScreen />*/}
<SafeAreaView style={styles.rootScreen}>
{screen}
</SafeAreaView>
</ImageBackground>
</LinearGradient>
</>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
rootScreen: {
flex: 1,
// backgroundColor: '#ddb52f'
},
backgroundImage: {
opacity: 0.15
}
});