-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
81 lines (72 loc) · 2.22 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
/* eslint-disable react-native/no-inline-styles */
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow strict-local
*/
import React, {useState} from 'react';
import {ImageBackground} from 'react-native';
import {Box, NativeBaseProvider, StatusBar} from 'native-base';
import {Colors} from './resources/constants/Colors';
import {Spacing} from './resources/constants/Spacing';
import LinearGradient from 'react-native-linear-gradient';
import StartGameScreen from './resources/screens/StartGameScreen';
import GameScreen from './resources/screens/GameScreen';
import GameOverScreen from './resources/screens/GameOverScreen';
export default function App() {
const [userNumber, setUserNumber] = useState('');
const [gameIsOver, setGameIsOver] = useState(false);
const [guessesNumber, setGuessesNumber] = useState(0);
const handlePickedNumber = number => setUserNumber(number);
let renderedScreen = <StartGameScreen onPicked={handlePickedNumber} />;
if (userNumber) {
// setGameIsOver(false);
renderedScreen = (
<GameScreen
chosenNumber={userNumber}
onGameOver={onGameOverHandler}
onNewGuess={updateGuessesNumber}
/>
);
}
if (gameIsOver && userNumber) {
renderedScreen = (
<GameOverScreen
userNumber={userNumber}
roundsNumber={guessesNumber}
onStartNewGame={startNewGame}
/>
);
}
function onGameOverHandler() {
setGameIsOver(true);
}
function startNewGame() {
setUserNumber('');
setGuessesNumber(0);
setGameIsOver(false);
}
function updateGuessesNumber(num) {
setGuessesNumber(num);
}
return (
<NativeBaseProvider>
<StatusBar backgroundColor={Colors.primary600 + 'd7'} />
<LinearGradient
colors={[Colors.primary600, Colors.secondary500]}
style={{flex: 1}}>
<ImageBackground
style={{flex: 1}}
source={require('./resources/assets/images/background.png')}
resizeMode="cover"
imageStyle={{opacity: 0.25}}>
<Box safeArea px={Spacing.screenPadding} flex="1">
{renderedScreen}
</Box>
</ImageBackground>
</LinearGradient>
</NativeBaseProvider>
);
}