-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
235 lines (231 loc) · 6.05 KB
/
App.tsx
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
import { createDrawerNavigator } from '@react-navigation/drawer'
import {
DarkTheme,
DefaultTheme,
NavigationContainer,
} from '@react-navigation/native'
import React from 'react'
import { Button, StatusBar, View } from 'react-native'
import 'react-native-gesture-handler'
import { GestureHandlerRootView } from 'react-native-gesture-handler'
import {
MaterialCommunityIcons,
Switch,
Text,
Button as ThemedButton,
} from './src/components/themedComponents'
import { GameProvider, useGameContext } from './src/contexts/game'
import { ThemeProvider, useThemeContext } from './src/contexts/theme'
import Game from './src/screens/Game'
import { Colors } from './src/styles/colors'
export const Drawer = createDrawerNavigator()
export default function App() {
return (
<GestureHandlerRootView style={{ flex: 1 }}>
<ThemeProvider>
<GameProvider>
<AppDrawer />
</GameProvider>
</ThemeProvider>
</GestureHandlerRootView>
)
}
const AppDrawer = () => {
const {
score,
reloadGame,
pauseGame,
setMoveInterval,
moveInterval,
bigFoodRarity,
setBigFoodRarity,
} = useGameContext()
const { toggleTheme, theme } = useThemeContext()
const isDark = theme === 'dark'
return (
<>
<NavigationContainer theme={theme === 'dark' ? DarkTheme : DefaultTheme}>
<Drawer.Navigator
initialRouteName='Game'
drawerContent={({ navigation }) => (
<View
style={{
paddingVertical: 20,
paddingHorizontal: 10,
flex: 1,
gap: 10,
backgroundColor: Colors[theme].background,
}}
>
<Text style={{ fontWeight: 'bold', fontSize: 20 }}>Game Options</Text>
<Text style={{ fontWeight: 'bold', fontSize: 11 }}>Game</Text>
<ThemedButton
title='Resume'
onPress={() => {
navigation.closeDrawer()
pauseGame()
}}
/>
<ThemedButton
title='New Game'
onPress={() => {
reloadGame()
navigation.closeDrawer()
}}
/>
<Text style={{ fontWeight: 'bold', fontSize: 11 }}>Game Difficulty</Text>
<View
style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
gap: 10,
}}
>
<View style={{ flex: 1 }}>
<Button
title='Easy'
onPress={() => setMoveInterval(70)}
color={
moveInterval === 70 ? Colors[theme].secondary : Colors[theme].primary
}
/>
</View>
<View style={{ flex: 1 }}>
<Button
title='Normal'
onPress={() => setMoveInterval(50)}
color={
moveInterval === 50 ? Colors[theme].secondary : Colors[theme].primary
}
/>
</View>
<View style={{ flex: 1 }}>
<Button
title='Hard'
onPress={() => setMoveInterval(20)}
color={
moveInterval === 20 ? Colors[theme].secondary : Colors[theme].primary
}
/>
</View>
</View>
<Text style={{ fontWeight: 'bold', fontSize: 11 }}>Others</Text>
<View
style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text>Enable Big Food Spawn</Text>
<Switch
value={!!bigFoodRarity}
onValueChange={(v) => setBigFoodRarity(v ? 0.8 : null)}
/>
</View>
<View
style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text>Enable Dark Mode</Text>
<Switch value={isDark} onValueChange={toggleTheme} />
</View>
<PersonalRecordBoard />
</View>
)}
>
<Drawer.Screen
name='Game'
component={Game}
options={{
headerTitle: '',
header: ({ navigation }) => (
<View
style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
paddingHorizontal: 15,
borderBottomWidth: 1,
borderBottomColor: isDark ? '#1f2937' : '#e5e7eb',
backgroundColor: Colors[theme].background,
}}
>
<MaterialCommunityIcons
name='menu'
onPress={() => navigation.openDrawer()}
size={35}
/>
<Text
style={{
fontSize: 35,
fontWeight: 'bold',
}}
>
{score}
<MaterialCommunityIcons name='food-apple' size={16} color='primary' />
</Text>
</View>
),
}}
/>
</Drawer.Navigator>
</NavigationContainer>
<StatusBar
barStyle={isDark ? 'light-content' : 'dark-content'}
backgroundColor={Colors[theme].background}
/>
</>
)
}
const PersonalRecordBoard = () => {
const { personalRecord, wipePersonalRecord } = useGameContext()
return (
<>
<Text style={{ fontWeight: 'bold', fontSize: 11 }}>Personal Record</Text>
{personalRecord.length ? (
<>
<View
style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text style={{ fontWeight: 'bold' }}>Score</Text>
<Text style={{ fontWeight: 'bold' }}>Dificulty</Text>
<Text style={{ fontWeight: 'bold' }}>Date Played</Text>
</View>
{personalRecord.map((record, index) => {
return (
<View
key={index}
style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
alignItems: 'center',
}}
>
<Text>{record.score}</Text>
<Text style={{ textTransform: 'capitalize' }}>{record.dificulty}</Text>
<Text>{new Date(record.date).toLocaleDateString()}</Text>
</View>
)
})}
<ThemedButton title='Wipe Personal Record' onPress={wipePersonalRecord} />
</>
) : (
<Text style={{ textAlign: 'center' }}>No Records Yet</Text>
)}
</>
)
}