|
@@ -3,8 +3,8 @@
|
3
|
3
|
import * as React from "react";
|
4
|
4
|
import {StackNavigationProp} from "@react-navigation/stack";
|
5
|
5
|
import type {CustomTheme} from "../../../managers/ThemeManager";
|
6
|
|
-import {Button, Card, Divider, Headline, Paragraph, withTheme} from "react-native-paper";
|
7
|
|
-import {View} from "react-native";
|
|
6
|
+import {Button, Card, Divider, Headline, Paragraph, Text, withTheme} from "react-native-paper";
|
|
7
|
+import {ScrollView, View} from "react-native";
|
8
|
8
|
import i18n from "i18n-js";
|
9
|
9
|
import Mascot, {MASCOT_STYLE} from "../../../components/Mascot/Mascot";
|
10
|
10
|
import MascotPopup from "../../../components/Mascot/MascotPopup";
|
|
@@ -14,9 +14,21 @@ import GridComponent from "../components/GridComponent";
|
14
|
14
|
import GridManager from "../logic/GridManager";
|
15
|
15
|
import Piece from "../logic/Piece";
|
16
|
16
|
import * as Animatable from "react-native-animatable";
|
|
17
|
+import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
|
|
18
|
+import LinearGradient from "react-native-linear-gradient";
|
|
19
|
+import SpeechArrow from "../../../components/Mascot/SpeechArrow";
|
|
20
|
+
|
|
21
|
+type GameStats = {
|
|
22
|
+ score: number,
|
|
23
|
+ level: number,
|
|
24
|
+ time: number,
|
|
25
|
+}
|
17
|
26
|
|
18
|
27
|
type Props = {
|
19
|
28
|
navigation: StackNavigationProp,
|
|
29
|
+ route: {
|
|
30
|
+ params: GameStats
|
|
31
|
+ },
|
20
|
32
|
theme: CustomTheme,
|
21
|
33
|
}
|
22
|
34
|
|
|
@@ -27,6 +39,10 @@ type State = {
|
27
|
39
|
class GameStartScreen extends React.Component<Props, State> {
|
28
|
40
|
|
29
|
41
|
gridManager: GridManager;
|
|
42
|
+ scores: Array<number>;
|
|
43
|
+
|
|
44
|
+ gameStats: GameStats | null;
|
|
45
|
+ isHighScore: boolean;
|
30
|
46
|
|
31
|
47
|
state = {
|
32
|
48
|
mascotDialogVisible: AsyncStorageManager.getInstance().preferences.gameStartShowBanner.current === "1",
|
|
@@ -35,6 +51,30 @@ class GameStartScreen extends React.Component<Props, State> {
|
35
|
51
|
constructor(props: Props) {
|
36
|
52
|
super(props);
|
37
|
53
|
this.gridManager = new GridManager(4, 4, props.theme);
|
|
54
|
+ this.scores = JSON.parse(AsyncStorageManager.getInstance().preferences.gameScores.current);
|
|
55
|
+ this.scores.sort((a, b) => b - a);
|
|
56
|
+ if (this.props.route.params != null)
|
|
57
|
+ this.recoverGameScore();
|
|
58
|
+ }
|
|
59
|
+
|
|
60
|
+ recoverGameScore() {
|
|
61
|
+ this.gameStats = this.props.route.params;
|
|
62
|
+ this.isHighScore = this.scores.length === 0 || this.gameStats.score > this.scores[0];
|
|
63
|
+ for (let i = 0; i < 3; i++) {
|
|
64
|
+ if (this.scores.length > i && this.gameStats.score > this.scores[i]) {
|
|
65
|
+ this.scores.splice(i, 0, this.gameStats.score);
|
|
66
|
+ break;
|
|
67
|
+ } else if (this.scores.length <= i) {
|
|
68
|
+ this.scores.push(this.gameStats.score);
|
|
69
|
+ break;
|
|
70
|
+ }
|
|
71
|
+ }
|
|
72
|
+ if (this.scores.length > 3)
|
|
73
|
+ this.scores.splice(3, 1);
|
|
74
|
+ AsyncStorageManager.getInstance().savePref(
|
|
75
|
+ AsyncStorageManager.getInstance().preferences.gameScores.key,
|
|
76
|
+ JSON.stringify(this.scores)
|
|
77
|
+ );
|
38
|
78
|
}
|
39
|
79
|
|
40
|
80
|
hideMascotDialog = () => {
|
|
@@ -97,10 +137,110 @@ class GameStartScreen extends React.Component<Props, State> {
|
97
|
137
|
);
|
98
|
138
|
})}
|
99
|
139
|
</View>
|
100
|
|
-
|
101
|
140
|
);
|
102
|
141
|
}
|
103
|
142
|
|
|
143
|
+ getPostGameContent(stats: GameStats) {
|
|
144
|
+ return (
|
|
145
|
+ <View style={{
|
|
146
|
+ flex: 1
|
|
147
|
+ }}>
|
|
148
|
+ <Mascot
|
|
149
|
+ emotion={this.isHighScore ? MASCOT_STYLE.LOVE : MASCOT_STYLE.NORMAL}
|
|
150
|
+ animated={this.isHighScore}
|
|
151
|
+ style={{
|
|
152
|
+ width: this.isHighScore ? "50%" : "30%",
|
|
153
|
+ marginLeft: this.isHighScore ? "auto" : null,
|
|
154
|
+ marginRight: this.isHighScore ? "auto" : null,
|
|
155
|
+ }}/>
|
|
156
|
+ <SpeechArrow
|
|
157
|
+ style={{marginLeft: this.isHighScore ? "60%" : "20%"}}
|
|
158
|
+ size={20}
|
|
159
|
+ color={this.props.theme.colors.mascotMessageArrow}
|
|
160
|
+ />
|
|
161
|
+ <Card style={{
|
|
162
|
+ borderColor: this.props.theme.colors.mascotMessageArrow,
|
|
163
|
+ borderWidth: 2,
|
|
164
|
+ marginLeft: 20,
|
|
165
|
+ marginRight: 20,
|
|
166
|
+ }}>
|
|
167
|
+ <Card.Content>
|
|
168
|
+ <Headline
|
|
169
|
+ style={{
|
|
170
|
+ textAlign: "center",
|
|
171
|
+ color: this.isHighScore
|
|
172
|
+ ? this.props.theme.colors.gameGold
|
|
173
|
+ : this.props.theme.colors.primary
|
|
174
|
+ }}>
|
|
175
|
+ {this.isHighScore
|
|
176
|
+ ? i18n.t("screens.game.newHighScore")
|
|
177
|
+ : i18n.t("screens.game.gameOver.text")}
|
|
178
|
+ </Headline>
|
|
179
|
+ <Divider/>
|
|
180
|
+ <View style={{
|
|
181
|
+ flexDirection: "row",
|
|
182
|
+ marginLeft: "auto",
|
|
183
|
+ marginRight: "auto",
|
|
184
|
+ marginTop: 10,
|
|
185
|
+ marginBottom: 10,
|
|
186
|
+ }}>
|
|
187
|
+ <Text style={{
|
|
188
|
+ fontSize: 20,
|
|
189
|
+ }}>
|
|
190
|
+ {i18n.t("screens.game.score", {score: stats.score})}
|
|
191
|
+ </Text>
|
|
192
|
+ <MaterialCommunityIcons
|
|
193
|
+ name={'star'}
|
|
194
|
+ color={this.props.theme.colors.tetrisScore}
|
|
195
|
+ size={30}
|
|
196
|
+ style={{
|
|
197
|
+ marginLeft: 5
|
|
198
|
+ }}/>
|
|
199
|
+ </View>
|
|
200
|
+ <View style={{
|
|
201
|
+ flexDirection: "row",
|
|
202
|
+ marginLeft: "auto",
|
|
203
|
+ marginRight: "auto",
|
|
204
|
+ }}>
|
|
205
|
+ <Text>{i18n.t("screens.game.level")}</Text>
|
|
206
|
+ <MaterialCommunityIcons
|
|
207
|
+ style={{
|
|
208
|
+ marginRight: 5,
|
|
209
|
+ marginLeft: 5,
|
|
210
|
+ }}
|
|
211
|
+ name={"gamepad-square"}
|
|
212
|
+ size={20}
|
|
213
|
+ color={this.props.theme.colors.textDisabled}
|
|
214
|
+ />
|
|
215
|
+ <Text>
|
|
216
|
+ {stats.level}
|
|
217
|
+ </Text>
|
|
218
|
+ </View>
|
|
219
|
+ <View style={{
|
|
220
|
+ flexDirection: "row",
|
|
221
|
+ marginLeft: "auto",
|
|
222
|
+ marginRight: "auto",
|
|
223
|
+ }}>
|
|
224
|
+ <Text>{i18n.t("screens.game.time")}</Text>
|
|
225
|
+ <MaterialCommunityIcons
|
|
226
|
+ style={{
|
|
227
|
+ marginRight: 5,
|
|
228
|
+ marginLeft: 5,
|
|
229
|
+ }}
|
|
230
|
+ name={"timer"}
|
|
231
|
+ size={20}
|
|
232
|
+ color={this.props.theme.colors.textDisabled}
|
|
233
|
+ />
|
|
234
|
+ <Text>
|
|
235
|
+ {stats.time}
|
|
236
|
+ </Text>
|
|
237
|
+ </View>
|
|
238
|
+ </Card.Content>
|
|
239
|
+ </Card>
|
|
240
|
+ </View>
|
|
241
|
+ )
|
|
242
|
+ }
|
|
243
|
+
|
104
|
244
|
getWelcomeText() {
|
105
|
245
|
return (
|
106
|
246
|
<View>
|
|
@@ -109,7 +249,14 @@ class GameStartScreen extends React.Component<Props, State> {
|
109
|
249
|
marginLeft: "auto",
|
110
|
250
|
marginRight: "auto",
|
111
|
251
|
}}/>
|
|
252
|
+ <SpeechArrow
|
|
253
|
+ style={{marginLeft: "60%"}}
|
|
254
|
+ size={20}
|
|
255
|
+ color={this.props.theme.colors.mascotMessageArrow}
|
|
256
|
+ />
|
112
|
257
|
<Card style={{
|
|
258
|
+ borderColor: this.props.theme.colors.mascotMessageArrow,
|
|
259
|
+ borderWidth: 2,
|
113
|
260
|
marginLeft: 10,
|
114
|
261
|
marginRight: 10,
|
115
|
262
|
}}>
|
|
@@ -131,44 +278,173 @@ class GameStartScreen extends React.Component<Props, State> {
|
131
|
278
|
</Paragraph>
|
132
|
279
|
</Card.Content>
|
133
|
280
|
</Card>
|
|
281
|
+ </View>
|
|
282
|
+ );
|
|
283
|
+ }
|
|
284
|
+
|
|
285
|
+ getPodiumRender(place: 1 | 2 | 3, score: string) {
|
|
286
|
+ let icon = "podium-gold";
|
|
287
|
+ let color = this.props.theme.colors.gameGold;
|
|
288
|
+ let fontSize = 20;
|
|
289
|
+ let size = 70;
|
|
290
|
+ if (place === 2) {
|
|
291
|
+ icon = "podium-silver";
|
|
292
|
+ color = this.props.theme.colors.gameSilver;
|
|
293
|
+ fontSize = 18;
|
|
294
|
+ size = 60;
|
|
295
|
+ } else if (place === 3) {
|
|
296
|
+ icon = "podium-bronze";
|
|
297
|
+ color = this.props.theme.colors.gameBronze;
|
|
298
|
+ fontSize = 15;
|
|
299
|
+ size = 50;
|
|
300
|
+ }
|
|
301
|
+ return (
|
|
302
|
+ <View style={{
|
|
303
|
+ marginLeft: place === 2 ? 20 : "auto",
|
|
304
|
+ marginRight: place === 3 ? 20 : "auto",
|
|
305
|
+ flexDirection: "column",
|
|
306
|
+ alignItems: "center",
|
|
307
|
+ justifyContent: "flex-end",
|
|
308
|
+ }}>
|
|
309
|
+ {
|
|
310
|
+ this.isHighScore && place === 1
|
|
311
|
+ ?
|
|
312
|
+ <Animatable.View
|
|
313
|
+ animation={"swing"}
|
|
314
|
+ iterationCount={"infinite"}
|
|
315
|
+ duration={2000}
|
|
316
|
+ delay={1000}
|
|
317
|
+ useNativeDriver={true}
|
|
318
|
+ style={{
|
|
319
|
+ position: "absolute",
|
|
320
|
+ top: -20
|
|
321
|
+ }}
|
|
322
|
+ >
|
|
323
|
+ <Animatable.View
|
|
324
|
+ animation={"pulse"}
|
|
325
|
+ iterationCount={"infinite"}
|
|
326
|
+ useNativeDriver={true}
|
|
327
|
+ >
|
|
328
|
+ <MaterialCommunityIcons
|
|
329
|
+ name={"decagram"}
|
|
330
|
+ color={this.props.theme.colors.gameGold}
|
|
331
|
+ size={150}
|
|
332
|
+ />
|
|
333
|
+ </Animatable.View>
|
|
334
|
+ </Animatable.View>
|
134
|
335
|
|
|
336
|
+ : null
|
|
337
|
+ }
|
|
338
|
+ <MaterialCommunityIcons
|
|
339
|
+ name={icon}
|
|
340
|
+ color={this.isHighScore && place === 1 ? "#fff" : color}
|
|
341
|
+ size={size}
|
|
342
|
+ />
|
|
343
|
+ <Text style={{
|
|
344
|
+ textAlign: "center",
|
|
345
|
+ fontWeight: place === 1 ? "bold" : null,
|
|
346
|
+ fontSize: fontSize,
|
|
347
|
+ }}>{score}</Text>
|
135
|
348
|
</View>
|
136
|
349
|
);
|
137
|
350
|
}
|
138
|
351
|
|
|
352
|
+ getTopScoresRender() {
|
|
353
|
+ const gold = this.scores.length > 0
|
|
354
|
+ ? this.scores[0]
|
|
355
|
+ : "-";
|
|
356
|
+ const silver = this.scores.length > 1
|
|
357
|
+ ? this.scores[1]
|
|
358
|
+ : "-";
|
|
359
|
+ const bronze = this.scores.length > 2
|
|
360
|
+ ? this.scores[2]
|
|
361
|
+ : "-";
|
|
362
|
+ return (
|
|
363
|
+ <View style={{
|
|
364
|
+ marginBottom: 20,
|
|
365
|
+ marginTop: 20
|
|
366
|
+ }}>
|
|
367
|
+ {this.getPodiumRender(1, gold.toString())}
|
|
368
|
+ <View style={{
|
|
369
|
+ flexDirection: "row",
|
|
370
|
+ marginLeft: "auto",
|
|
371
|
+ marginRight: "auto",
|
|
372
|
+ }}>
|
|
373
|
+ {this.getPodiumRender(3, bronze.toString())}
|
|
374
|
+ {this.getPodiumRender(2, silver.toString())}
|
|
375
|
+ </View>
|
|
376
|
+ </View>
|
|
377
|
+ );
|
|
378
|
+ }
|
|
379
|
+
|
|
380
|
+ getMainContent() {
|
|
381
|
+ return (
|
|
382
|
+ <LinearGradient
|
|
383
|
+ style={{flex: 1}}
|
|
384
|
+ colors={[
|
|
385
|
+ this.props.theme.colors.background + "00",
|
|
386
|
+ this.props.theme.colors.background
|
|
387
|
+ ]}
|
|
388
|
+ start={{x: 0, y: 0.1}}
|
|
389
|
+ end={{x: 0.1, y: 1}}
|
|
390
|
+ >
|
|
391
|
+ <View style={{flex: 1}}>
|
|
392
|
+ {
|
|
393
|
+ this.gameStats != null
|
|
394
|
+ ? this.getPostGameContent(this.gameStats)
|
|
395
|
+ : this.getWelcomeText()
|
|
396
|
+ }
|
|
397
|
+ <Button
|
|
398
|
+ icon={"play"}
|
|
399
|
+ mode={"contained"}
|
|
400
|
+ onPress={() => this.props.navigation.replace(
|
|
401
|
+ "game-main",
|
|
402
|
+ {
|
|
403
|
+ highScore: this.scores.length > 0
|
|
404
|
+ ? this.scores[0]
|
|
405
|
+ : null
|
|
406
|
+ }
|
|
407
|
+ )}
|
|
408
|
+ style={{
|
|
409
|
+ marginLeft: "auto",
|
|
410
|
+ marginRight: "auto",
|
|
411
|
+ marginTop: 10,
|
|
412
|
+ }}
|
|
413
|
+ >
|
|
414
|
+ {i18n.t("screens.game.play")}
|
|
415
|
+ </Button>
|
|
416
|
+ {this.getTopScoresRender()}
|
|
417
|
+ </View>
|
|
418
|
+ </LinearGradient>
|
|
419
|
+ )
|
|
420
|
+ }
|
|
421
|
+
|
|
422
|
+ keyExtractor = (item: number) => item.toString();
|
|
423
|
+
|
139
|
424
|
render() {
|
140
|
425
|
return (
|
141
|
426
|
<View style={{flex: 1}}>
|
142
|
427
|
{this.getPiecesBackground()}
|
143
|
|
- {this.getWelcomeText()}
|
144
|
|
- <Button
|
145
|
|
- icon={"play"}
|
146
|
|
- mode={"contained"}
|
147
|
|
- onPress={() => this.props.navigation.navigate("game-main")}
|
148
|
|
- style={{
|
149
|
|
- marginLeft: "auto",
|
150
|
|
- marginRight: "auto",
|
151
|
|
- marginTop: 10,
|
152
|
|
- }}
|
153
|
|
- >
|
154
|
|
- {i18n.t("screens.game.play")}
|
155
|
|
- </Button>
|
156
|
|
- <MascotPopup
|
157
|
|
- visible={this.state.mascotDialogVisible}
|
158
|
|
- title={i18n.t("screens.game.mascotDialog.title")}
|
159
|
|
- message={i18n.t("screens.game.mascotDialog.message")}
|
160
|
|
- icon={"gamepad-variant"}
|
161
|
|
- buttons={{
|
162
|
|
- action: null,
|
163
|
|
- cancel: {
|
164
|
|
- message: i18n.t("screens.game.mascotDialog.button"),
|
165
|
|
- icon: "check",
|
166
|
|
- onPress: this.hideMascotDialog,
|
167
|
|
- }
|
168
|
|
- }}
|
169
|
|
- emotion={MASCOT_STYLE.COOL}
|
170
|
|
- />
|
|
428
|
+ <ScrollView>
|
|
429
|
+ {this.getMainContent()}
|
|
430
|
+ <MascotPopup
|
|
431
|
+ visible={this.state.mascotDialogVisible}
|
|
432
|
+ title={i18n.t("screens.game.mascotDialog.title")}
|
|
433
|
+ message={i18n.t("screens.game.mascotDialog.message")}
|
|
434
|
+ icon={"gamepad-variant"}
|
|
435
|
+ buttons={{
|
|
436
|
+ action: null,
|
|
437
|
+ cancel: {
|
|
438
|
+ message: i18n.t("screens.game.mascotDialog.button"),
|
|
439
|
+ icon: "check",
|
|
440
|
+ onPress: this.hideMascotDialog,
|
|
441
|
+ }
|
|
442
|
+ }}
|
|
443
|
+ emotion={MASCOT_STYLE.COOL}
|
|
444
|
+ />
|
|
445
|
+ </ScrollView>
|
171
|
446
|
</View>
|
|
447
|
+
|
172
|
448
|
);
|
173
|
449
|
}
|
174
|
450
|
}
|