Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GameStartScreen.js 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // @flow
  2. import * as React from "react";
  3. import {StackNavigationProp} from "@react-navigation/stack";
  4. import type {CustomTheme} from "../../../managers/ThemeManager";
  5. import {Button, Card, Divider, Headline, Paragraph, withTheme} from "react-native-paper";
  6. import {View} from "react-native";
  7. import i18n from "i18n-js";
  8. import Mascot, {MASCOT_STYLE} from "../../../components/Mascot/Mascot";
  9. import MascotPopup from "../../../components/Mascot/MascotPopup";
  10. import AsyncStorageManager from "../../../managers/AsyncStorageManager";
  11. import type {Grid} from "../components/GridComponent";
  12. import GridComponent from "../components/GridComponent";
  13. import GridManager from "../logic/GridManager";
  14. import Piece from "../logic/Piece";
  15. import * as Animatable from "react-native-animatable";
  16. type Props = {
  17. navigation: StackNavigationProp,
  18. theme: CustomTheme,
  19. }
  20. type State = {
  21. mascotDialogVisible: boolean,
  22. }
  23. class GameStartScreen extends React.Component<Props, State> {
  24. gridManager: GridManager;
  25. state = {
  26. mascotDialogVisible: AsyncStorageManager.getInstance().preferences.gameStartShowBanner.current === "1",
  27. }
  28. constructor(props: Props) {
  29. super(props);
  30. this.gridManager = new GridManager(4, 4, props.theme);
  31. }
  32. hideMascotDialog = () => {
  33. AsyncStorageManager.getInstance().savePref(
  34. AsyncStorageManager.getInstance().preferences.gameStartShowBanner.key,
  35. '0'
  36. );
  37. this.setState({mascotDialogVisible: false})
  38. };
  39. getPiecesBackground() {
  40. let gridList = [];
  41. for (let i = 0; i < 18; i++) {
  42. gridList.push(this.gridManager.getEmptyGrid(4, 4));
  43. const piece = new Piece(this.props.theme);
  44. piece.toGrid(gridList[i], true);
  45. }
  46. return (
  47. <View style={{
  48. position: "absolute",
  49. width: "100%",
  50. height: "100%",
  51. }}>
  52. {gridList.map((item: Grid, index: number) => {
  53. const size = 10 + Math.floor(Math.random() * 30);
  54. const top = Math.floor(Math.random() * 100);
  55. const rot = Math.floor(Math.random() * 360);
  56. const left = (index % 6) * 20;
  57. const animDelay = size * 20;
  58. const animDuration = 2 * (2000 - (size * 30));
  59. return (
  60. <Animatable.View
  61. animation={"fadeInDownBig"}
  62. delay={animDelay}
  63. duration={animDuration}
  64. key={index.toString()}
  65. style={{
  66. width: size + "%",
  67. position: "absolute",
  68. top: top + "%",
  69. left: left + "%",
  70. }}
  71. >
  72. <View style={{
  73. transform: [{rotateZ: rot + "deg"}],
  74. }}>
  75. <GridComponent
  76. width={4}
  77. height={4}
  78. grid={item}
  79. style={{
  80. marginRight: 5,
  81. marginLeft: 5,
  82. marginBottom: 5,
  83. }}
  84. />
  85. </View>
  86. </Animatable.View>
  87. );
  88. })}
  89. </View>
  90. );
  91. }
  92. getWelcomeText() {
  93. return (
  94. <View>
  95. <Mascot emotion={MASCOT_STYLE.COOL} style={{
  96. width: "40%",
  97. marginLeft: "auto",
  98. marginRight: "auto",
  99. }}/>
  100. <Card style={{
  101. marginLeft: 10,
  102. marginRight: 10,
  103. }}>
  104. <Card.Content>
  105. <Headline
  106. style={{
  107. textAlign: "center",
  108. color: this.props.theme.colors.primary
  109. }}>
  110. {i18n.t("screens.game.welcomeTitle")}
  111. </Headline>
  112. <Divider/>
  113. <Paragraph
  114. style={{
  115. textAlign: "center",
  116. marginTop: 10,
  117. }}>
  118. {i18n.t("screens.game.welcomeMessage")}
  119. </Paragraph>
  120. </Card.Content>
  121. </Card>
  122. </View>
  123. );
  124. }
  125. render() {
  126. return (
  127. <View style={{flex: 1}}>
  128. {this.getPiecesBackground()}
  129. {this.getWelcomeText()}
  130. <Button
  131. icon={"play"}
  132. mode={"contained"}
  133. onPress={() => this.props.navigation.navigate("game-main")}
  134. style={{
  135. marginLeft: "auto",
  136. marginRight: "auto",
  137. marginTop: 10,
  138. }}
  139. >
  140. {i18n.t("screens.game.play")}
  141. </Button>
  142. <MascotPopup
  143. visible={this.state.mascotDialogVisible}
  144. title={i18n.t("screens.game.mascotDialog.title")}
  145. message={i18n.t("screens.game.mascotDialog.message")}
  146. icon={"gamepad-variant"}
  147. buttons={{
  148. action: null,
  149. cancel: {
  150. message: i18n.t("screens.game.mascotDialog.button"),
  151. icon: "check",
  152. onPress: this.hideMascotDialog,
  153. }
  154. }}
  155. emotion={MASCOT_STYLE.COOL}
  156. />
  157. </View>
  158. );
  159. }
  160. }
  161. export default withTheme(GameStartScreen);