-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
74 lines (63 loc) · 2.2 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
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, ImageBackground, SafeAreaView} from 'react-native';
import StartGameScreen from "./screens/StartGameScreen";
import {LinearGradient} from "expo-linear-gradient";
import {useState} from "react";
import GameScreen from "./screens/GameScreen";
import Colors from "./constants/colors";
import GameOverScreen from "./screens/GameOverScreen";
import { useFonts } from 'expo-font';
import AppLoading from 'expo-app-loading'
export default function App() {
const [pickedNumber, setPickedNumber] = useState();
const [isGameOver, setIsGameOver] = useState(false);
const [guessRounds, setGuessRounds] = useState(0);
const [fontsLoaded, fontError] = useFonts({
'OpenSans-Bold': require('./assets/fonts/OpenSans-Bold.ttf'),
'OpenSans-Regular': require('./assets/fonts/OpenSans-Regular.ttf'),
});
if (!fontsLoaded && !fontError) {
return <AppLoading />;
}
function onPickedNumberHandler(pickedNumber){
setPickedNumber(pickedNumber)
}
function onGameOverHandler(guessRound){
setIsGameOver(true)
setGuessRounds(guessRound)
}
function startNewGameHandler(){
setPickedNumber(null)
setGuessRounds(0)
}
let screen = <StartGameScreen onPickedNumber={onPickedNumberHandler} />
if(pickedNumber){
screen = <GameScreen pickedNumber={pickedNumber} onGameOver={onGameOverHandler} />
}
if(isGameOver){
screen = <GameOverScreen pickedNumber={pickedNumber} roundsNumber={guessRounds} onStartNewGame={startNewGameHandler} />
}
return (
<>
<StatusBar style={'light'} />
<LinearGradient colors={[Colors.primary700, Colors.ascent500]} style={styles.appScreen}>
<ImageBackground
source={require('./assets/images/background.png')}
resizeMode={'cover'}
style={styles.appScreen}
imageStyle={styles.backgroundImage}
>
<SafeAreaView style={styles.appScreen}>{screen}</SafeAreaView>
</ImageBackground>
</LinearGradient>
</>
);
}
const styles = StyleSheet.create({
appScreen: {
flex: 1,
},
backgroundImage: {
opacity: 0.15,
}
});