-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
75 lines (64 loc) · 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
75
/* eslint-disable global-require */
/* eslint-disable max-len */
/* eslint-disable no-console */
import * as Font from 'expo-font';
import { AppLoading } from 'expo';
import React, { useState } from 'react';
import { StyleSheet, View } from 'react-native';
import Header from './Components/header';
import StartGameScreen from './Screens/StartGameScreen';
import GameScreen from './Screens/GameScreen';
import GameOver from './Screens/GameOver';
const loadFont = () => Font.loadAsync({
'OpenSans-Bold': require('./assets/fonts/OpenSans-Bold.ttf'),
'OpenSans': require('./assets/fonts/OpenSans-Regular.ttf')
});
export default function App() {
const [userNumber, setUserNumber] = useState();
const [numRounds, setNumRounds] = useState(0);
const [fontLoaded, setFontLoaded] = useState(false);
if (!fontLoaded) {
return <AppLoading startAsync={loadFont} onFinish={() => setFontLoaded(true)} onError={(err) => console.log(err)} />;
}
const startGameHandler = (selectedNumber) => {
console.log(selectedNumber);
setUserNumber(selectedNumber);
};
const gameOverHandler = (rounds) => {
setNumRounds(rounds);
};
const resetGame = () => {
setUserNumber(null);
setNumRounds(0);
};
let content = <StartGameScreen onStartGame={startGameHandler} />;
if (userNumber && numRounds <= 0) {
content = <GameScreen userInput={userNumber} onGameOver={gameOverHandler} />;
} else if (numRounds > 0) {
content = <GameOver rounds={numRounds} userNumber={userNumber} reset={resetGame} />;
}
return (
<View style={styles.screen}>
<Header title="Guess The Number" />
<View style={styles.inputScreen}>{content}</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
screen: {
flex: 1,
},
inputScreen: {
flex: 1,
// backgroundColor: 'black',
// justifyContent: 'center',
// alignItems: 'center',
// flexDirection: 'row'
},
});