-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
128 lines (107 loc) · 3.66 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
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
import React, { useState, useEffect } from 'react';
import { StyleSheet, View, ScrollView, LogBox } from 'react-native';
import { NativeRouter, Route } from 'react-router-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { ThemeProvider } from 'react-native-elements';
import * as Speech from 'expo-speech';
// Sockety Sockets
import io from 'socket.io-client';
// Reduxy Redux
import { startNewGame, } from './src/components/actions/actions.js';
import store from './src/store-vanilla/index.js';
import { Provider } from 'react-redux';
// Componenty Components
import HeaderComponent from './src/components/header/Header.js';
import Start from './src/components/start/Start.js';
import ShipPlacement from './src/components/ship-placement/Ship-placement.js';
import GameParley from './src/components/gameplay/Gameplay.js';
// import GameOver from './src/components/gameover/Gameover.js';
// import If from './src/components/if/If.js';
const serverUrl = 'https://sinky-ship-v3.herokuapp.com/';
// const serverUrl = 'http://localhost:3000';
LogBox.ignoreLogs(['Warning: ...']); // Ignore log notification by message
LogBox.ignoreAllLogs(); // Ignore all log notifications
// Component
const App = (props) => {
const displayGridGenerator = () => {
const displayArray = [];
for (let i = 0; i < 100; i++) {
displayArray[i] = { name: i, value: 'blue' };
}
return displayArray;
};
let initialDisplay = displayGridGenerator();
let [vocal, setVocal] = useState('');
let [gameComplete, setGameComplete] = useState('no');
let [gamePayload, setGamePayload] = useState({ displayBoard: initialDisplay, missileStatus: false, computerGuess: false });
let [socket, setSocket] = useState(io.connect(serverUrl, {
transports: ['websocket'],
jsonp: false
}));
const speak = (result) => {
const thingToSay = result;
Speech.speak(thingToSay);
};
const theme = {
colors: {
primary: '#143B4C'
}
};
useEffect(() => {
socket.on('guess', (payload) => {
setGamePayload({ ...payload });
setVocal(payload.missileStatus);
speak(payload.missileStatus);
});
socket.on('game-over', (payload) => {
// console.log('Winner: ', payload.winner);
setGameComplete(payload.winner);
speak(`Game Over. Winner, ${payload.winner}`);
});
socket.on('disconnect', () => {
console.log('connection to server lost');
});
}, []);
const newGame = () => {
startNewGame();
socket.emit('new-game');
};
return (
<Provider store={store}>
<NativeRouter>
<SafeAreaView style={styles.safeArea}>
<ThemeProvider theme={theme}>
<View style={styles.container}>
<ScrollView scrollEnabled={false}>
<HeaderComponent newGame={newGame} />
<Route exact path="/" render={(props) => (
<Start newGame3={newGame} />
)} />
<Route path="/ship-placement" render={(props) => (
<ShipPlacement {...props} socket={socket} gamePayload={gamePayload} />
)} />
<Route path="/game-parley" component={GameParley} />
{/* <If condition={!gameComplete === 'no'}>
<GameOver newGame={newGame} />
</If> */}
</ScrollView>
</View>
</ThemeProvider>
</SafeAreaView>
</NativeRouter >
</Provider>
);
}
const styles = StyleSheet.create({
safeArea: {
flex: 1,
backgroundColor: '#b9ced5',
},
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
export default App;