-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenu.js
350 lines (333 loc) · 13.7 KB
/
Menu.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
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
/**
* @file Menu.js
* @author Claire Fleckney
* @date March 27, 2023
* @brief This is the file for controlling the
* page flow of the menu screens
*/
import { StatusBar } from 'expo-status-bar';
import { Audio } from 'expo-av';
import React, { Component } from 'react';
import { Alert, Image, Keyboard, Pressable, Text, TextInput, View } from 'react-native';
import styles from './Style';
import Stat from './Stats';
export default class Menu extends Component {
constructor(props) {
super(props);
this.state = {
pageNum: 1,
firstInst: true,
idArray: [],
id: undefined,
name: '',
job: 'Warrior',
warBorder: 'green',
mageBorder: '#303030',
rangBorder: '#303030',
ninBorder: '#303030',
warrior: require('./assets/sprites/warrior/warrior-front.png'),
mage: require('./assets/sprites/mage/mage-front.png'),
ranger: require('./assets/sprites/ranger/ranger-front.png'),
ninja: require('./assets/sprites/ninja/ninja-front.png'),
}
};
async componentDidMount() {
this.playBgMusic();
};
async componentWillUnmount() {
const{ remoteSound } = this.state;
if (remoteSound) {
remoteSound.stopAsync();
remoteSound.unloadAsync();
}
}
/**
* Plays the Menu background music
* @function playBgMusic()
*/
playBgMusic = async () => {
const { sound } = await Audio.Sound.createAsync({
uri: 'https://opengameart.org/sites/default/files/Exploring%20the%20Dungeon%20II_0.mp3',
});
this.setRemoteSound(sound);
await sound.playAsync();
sound.setIsLoopingAsync(true);
}
/**
* Loads and sets the background music
* @function setRemoteSound()
* @param {Sound} newPbo Background music to play
*/
setRemoteSound = (newPbo) => {
this.setState({
remoteSound: newPbo,
});
}
/**
* Dismisses the keyboard on screen press
* @function dismissKeyboard()
*/
dismissKeyboard = () => {
Keyboard.dismiss();
}
/**
* Sets the page number
* @function setPage()
* @param {int} p Page Number
*/
setPage = (p) => {
this.setState({ pageNum: p });
}
/**
* Sets the players name
* @function setName()
* @param {string} userName User entered name
*/
setName = (userName) => {
let newName = userName;
this.setState({
name: newName,
})
}
/**
* Sets the players Job
* @function setJob()
* @param {string} j Player Job
*/
setJob = (j) => { this.setState({ job: j });}
/**
* Sets the border color for the warrior icon
* @function setWarBorder()
* @param {string} b Color
*/
setWarBorder = (b) => { this.setState({ warBorder: b });}
/**
* Sets the border color for the mage icon
* @function setMageBorder()
* @param {string} b Color
*/
setMageBorder = (b) => { this.setState({ mageBorder: b });}
/**
* Sets the border color for the ranger icon
* @function setRangBorder()
* @param {string} b Color
*/
setRangBorder = (b) => { this.setState({ rangBorder: b });}
/**
* Sets the border color for the ninja icon
* @function setNinBorder()
* @param {string} b Color
*/
setNinBorder = (b) => { this.setState({ ninBorder: b });}
/**
* Navigates to the dungeon screen after player creation
* @function startNav()
* @param {int} page Page Number
* @param {string} name Player Name
* @param {string} job Player Job
*/
startNav = (page, name, job, id) => {
const { navigation } = this.props;
page = page;
name = name;
job = job;
id = id;
// If the user hasn't set a name, send an alert
if (name == '') {
Alert.alert('Name Field Empty', 'Please choose a name for your character');
} else {
{navigation.navigate(page, {name: name, job: job, id: id});};
}
};
/**
* Changes which set of instructions is showing
* @function changeInst()
*/
changeInst = () => {
this.setState({ firstInst: !this.state.firstInst });
}
render() {
let inst1 = 'Give your character a name and choose from one of four starting Jobs\n\nMake your way through the maze using the directional buttons\n\nTry to make it to the prize at the end!';
let inst2 = 'When Kobolds appear, swipe right to attack, swipe left to defend, and shake your device to activate your special abilities!\n\nYou can view your past progress on the Stats Screen';
let titlelogo = require('./assets/titlelogo.png');
const { db } = this.props;
if (this.state.pageNum === 1) { // Main Landing Page
return (
<View style={styles.container}>
<View style={styles.topContainer}>
<StatusBar style='light' />
<Image source={titlelogo} style={styles.titleLogo} />
</View>
<View style={styles.bottomContainer}>
<Pressable style={({pressed}) =>
[{borderBottomWidth: pressed ? 0 : 5,
borderRightWidth: pressed ? 0 : 5,},
styles.landingBtn
]}
onPress={() => {this.setPage(3)}}
>
<Text style={styles.landingBtnTxt}>Start New Game</Text>
</Pressable>
</View>
<View style={styles.bottomContainer}>
<Pressable style={({pressed}) =>
[{borderBottomWidth: pressed ? 0 : 5,
borderRightWidth: pressed ? 0 : 5,},
styles.landingBtn
]}
onPress={() => {this.setPage(2)}}
>
<Text style={styles.landingBtnTxt}>View Instructions</Text>
</Pressable>
</View>
<View style={styles.bottomContainer}>
<Pressable style={({pressed}) =>
[{borderBottomWidth: pressed ? 0 : 5,
borderRightWidth: pressed ? 0 : 5,},
styles.landingBtn
]}
onPress={() => {this.setPage(4)}}
>
<Text style={styles.landingBtnTxt}>View Past Stats</Text>
</Pressable>
</View>
</View>
)
} else if (this.state.pageNum === 2) { // Instructions Page
return (
<>
<View style={styles.instPage}>
<Pressable
style={({pressed}) => [{opacity: pressed? .25 : 1}, {transform: [{ rotate: '-90deg'}]}, styles.instButton]}
onPress={() => {this.changeInst()}}
/>
<View style={styles.instructions}>
{this.state.firstInst ?
<Text style={styles.instText}>{inst1}</Text> :
<Text style={styles.instText}>{inst2}</Text>
}
</View>
<Pressable
style={({pressed}) => [{opacity: pressed? .25 : 1}, {transform: [{ rotate: '90deg'}]}, styles.instButton]}
onPress={() => {this.changeInst()}}
/>
</View>
<View style={styles.instReturn}>
<Pressable style={({pressed}) =>
[{borderBottomWidth: pressed ? 0 : 5,
borderRightWidth: pressed ? 0 : 5,},
styles.landingBtn
]}
onPress={() => {this.setPage(1)}}
>
<Text style={styles.landingBtnTxt}>Return to Main Screen</Text>
</Pressable>
</View>
</>
)
} else if (this.state.pageNum === 3) { // Character Creation Page
return (
<Pressable style={styles.container} onPress={() => {this.dismissKeyboard}}>
<View style={styles.header}>
<TextInput
style={styles.nameInput}
onChangeText={this.setName}
value={this.state.name}
placeholder='Character Name'
/>
</View>
<View style={styles.job}>
<Pressable style={[{borderColor: this.state.warBorder}, styles.jobSelect]}
onPress={() => {this.setJob('Warrior'),
this.setWarBorder('green'),
this.setMageBorder('#303030'),
this.setRangBorder('#303030'),
this.setNinBorder('#303030')}}
>
<Image source={this.state.warrior} style={styles.jobSprite} />
<Text style={styles.spriteLabel}>Warrior</Text>
</Pressable>
<Pressable style={[{borderColor: this.state.mageBorder}, styles.jobSelect]}
onPress={() => {this.setJob('Mage'),
this.setWarBorder('#303030'),
this.setMageBorder('green'),
this.setRangBorder('#303030'),
this.setNinBorder('#303030')}}
>
<Image source={this.state.mage} style={styles.jobSprite} />
<Text style={styles.spriteLabel}>Mage</Text>
</Pressable>
<Pressable style={[{borderColor: this.state.rangBorder}, styles.jobSelect]}
onPress={() => {this.setJob('Ranger'),
this.setWarBorder('#303030'),
this.setMageBorder('#303030'),
this.setRangBorder('green'),
this.setNinBorder('#303030')}}
>
<Image source={this.state.ranger} style={styles.jobSprite} />
<Text style={styles.spriteLabel}>Ranger</Text>
</Pressable>
<Pressable style={[{borderColor: this.state.ninBorder}, styles.jobSelect]}
onPress={() => {this.setJob('Ninja'),
this.setWarBorder('#303030'),
this.setMageBorder('#303030'),
this.setRangBorder('#303030'),
this.setNinBorder('green')}}
>
<Image source={this.state.ninja} style={styles.jobSprite} />
<Text style={styles.spriteLabel}>Ninja</Text>
</Pressable>
</View>
<View style={styles.startGame}>
<Pressable style={({pressed}) =>
[{borderBottomWidth: pressed ? 0 : 5,
borderRightWidth: pressed ? 0 : 5,},
styles.landingBtn
]}
onPress={() => {this.startNav('Dungeon', this.state.name, this.state.job, this.state.id)}}
>
<Text style={styles.landingBtnTxt}>Begin Game</Text>
</Pressable>
</View>
<View style={styles.startGame}>
<Pressable style={({pressed}) =>
[{borderBottomWidth: pressed ? 0 : 5,
borderRightWidth: pressed ? 0 : 5,},
styles.backBtn
]}
onPress={() => this.setPage(1)}
>
<Text style={styles.landingBtnTxt}>Back to Main Screen</Text>
</Pressable>
</View>
</Pressable>
)
} else if (this.state.pageNum === 4) { // Stats Page
return (
<>
<View style={styles.container}>
<View style={styles.stats}>
<Text style={styles.statHeader}>Name</Text>
<Text style={styles.statHeader}>Job</Text>
<Text style={styles.statHeader}>Victory?</Text>
</View>
<View style={styles.statContainer}>
<Stat db={db} />
</View>
</View>
<View style={styles.bottomContainer}>
<Pressable style={({pressed}) =>
[{borderBottomWidth: pressed ? 0 : 5,
borderRightWidth: pressed ? 0 : 5,},
styles.landingBtn
]}
onPress={() => this.setPage(1)}
>
<Text style={styles.landingBtnTxt}>Back to Main Screen</Text>
</Pressable>
</View>
</>
)
}
}
}