Browse Source

Changed game project organization and added basic start screen

Arnaud Vergnet 3 years ago
parent
commit
3989652c29

+ 1
- 1
src/components/Tabbar/CustomTabBar.js View File

@@ -78,7 +78,7 @@ class CustomTabBar extends React.Component<Props, State> {
78 78
             canPreventDefault: true,
79 79
         });
80 80
         if (route.name === "home" && !event.defaultPrevented)
81
-            this.props.navigation.navigate('tetris');
81
+            this.props.navigation.navigate('game-start');
82 82
     }
83 83
 
84 84
     /**

+ 19
- 3
src/navigation/MainNavigator.js View File

@@ -8,7 +8,7 @@ import DebugScreen from '../screens/About/DebugScreen';
8 8
 import {createStackNavigator, TransitionPresets} from "@react-navigation/stack";
9 9
 import i18n from "i18n-js";
10 10
 import TabNavigator from "./TabNavigator";
11
-import GameScreen from "../screens/Game/GameScreen";
11
+import GameMainScreen from "../screens/Game/screens/GameMainScreen";
12 12
 import VoteScreen from "../screens/Amicale/VoteScreen";
13 13
 import LoginScreen from "../screens/Amicale/LoginScreen";
14 14
 import {Platform} from "react-native";
@@ -27,6 +27,8 @@ import EquipmentScreen from "../screens/Amicale/Equipment/EquipmentListScreen";
27 27
 import EquipmentLendScreen from "../screens/Amicale/Equipment/EquipmentRentScreen";
28 28
 import EquipmentConfirmScreen from "../screens/Amicale/Equipment/EquipmentConfirmScreen";
29 29
 import DashboardEditScreen from "../screens/Other/Settings/DashboardEditScreen";
30
+import GameStartScreen from "../screens/Game/screens/GameStartScreen";
31
+import GameEndScreen from "../screens/Game/screens/GameEndScreen";
30 32
 
31 33
 const modalTransition = Platform.OS === 'ios' ? TransitionPresets.ModalPresentationIOS : TransitionPresets.ModalSlideFromBottomIOS;
32 34
 
@@ -92,8 +94,22 @@ function MainStackComponent(props: { createTabNavigator: () => React.Node }) {
92 94
                 }}
93 95
             />
94 96
             <MainStack.Screen
95
-                name="tetris"
96
-                component={GameScreen}
97
+                name="game-start"
98
+                component={GameStartScreen}
99
+                options={{
100
+                    title: i18n.t("screens.game.title"),
101
+                }}
102
+            />
103
+            <MainStack.Screen
104
+                name="game-main"
105
+                component={GameMainScreen}
106
+                options={{
107
+                    title: i18n.t("screens.game.title"),
108
+                }}
109
+            />
110
+            <MainStack.Screen
111
+                name="game-end"
112
+                component={GameEndScreen}
97 113
                 options={{
98 114
                     title: i18n.t("screens.game.title"),
99 115
                 }}

+ 3
- 3
src/screens/Game/__tests__/GridManager.test.js View File

@@ -1,7 +1,7 @@
1 1
 import React from 'react';
2
-import GridManager from "../GridManager";
3
-import ScoreManager from "../ScoreManager";
4
-import Piece from "../Piece";
2
+import GridManager from "../logic/GridManager";
3
+import ScoreManager from "../logic/ScoreManager";
4
+import Piece from "../logic/Piece";
5 5
 
6 6
 let colors = {
7 7
     tetrisBackground: "#000002"

+ 1
- 1
src/screens/Game/__tests__/Piece.test.js View File

@@ -1,5 +1,5 @@
1 1
 import React from 'react';
2
-import Piece from "../Piece";
2
+import Piece from "../logic/Piece";
3 3
 import ShapeI from "../Shapes/ShapeI";
4 4
 
5 5
 let colors = {

+ 1
- 1
src/screens/Game/__tests__/ScoreManager.test.js View File

@@ -1,5 +1,5 @@
1 1
 import React from 'react';
2
-import ScoreManager from "../ScoreManager";
2
+import ScoreManager from "../logic/ScoreManager";
3 3
 
4 4
 
5 5
 test('incrementScore', () => {

src/screens/Game/GameLogic.js → src/screens/Game/logic/GameLogic.js View File

@@ -3,6 +3,7 @@
3 3
 import Piece from "./Piece";
4 4
 import ScoreManager from "./ScoreManager";
5 5
 import GridManager from "./GridManager";
6
+import type {CustomTheme} from "../../../managers/ThemeManager";
6 7
 
7 8
 export default class GameLogic {
8 9
 
@@ -45,20 +46,20 @@ export default class GameLogic {
45 46
     #onClock: Function;
46 47
     endCallback: Function;
47 48
 
48
-    #colors: Object;
49
+    #theme: CustomTheme;
49 50
 
50
-    constructor(height: number, width: number, colors: Object) {
51
+    constructor(height: number, width: number, theme: CustomTheme) {
51 52
         this.#height = height;
52 53
         this.#width = width;
53 54
         this.#gameRunning = false;
54 55
         this.#gamePaused = false;
55
-        this.#colors = colors;
56
+        this.#theme = theme;
56 57
         this.#autoRepeatActivationDelay = 300;
57 58
         this.#autoRepeatDelay = 50;
58 59
         this.#nextPieces = [];
59 60
         this.#nextPiecesCount = 3;
60 61
         this.#scoreManager = new ScoreManager();
61
-        this.#gridManager = new GridManager(this.getWidth(), this.getHeight(), this.#colors);
62
+        this.#gridManager = new GridManager(this.getWidth(), this.getHeight(), this.#theme);
62 63
     }
63 64
 
64 65
     getHeight(): number {
@@ -179,7 +180,7 @@ export default class GameLogic {
179 180
 
180 181
     generateNextPieces() {
181 182
         while (this.#nextPieces.length < this.#nextPiecesCount) {
182
-            this.#nextPieces.push(new Piece(this.#colors));
183
+            this.#nextPieces.push(new Piece(this.#theme));
183 184
         }
184 185
     }
185 186
 
@@ -219,7 +220,7 @@ export default class GameLogic {
219 220
         this.#gameTime = 0;
220 221
         this.#scoreManager = new ScoreManager();
221 222
         this.#gameTick = GameLogic.levelTicks[this.#scoreManager.getLevel()];
222
-        this.#gridManager = new GridManager(this.getWidth(), this.getHeight(), this.#colors);
223
+        this.#gridManager = new GridManager(this.getWidth(), this.getHeight(), this.#theme);
223 224
         this.#nextPieces = [];
224 225
         this.generateNextPieces();
225 226
         this.createTetromino();

src/screens/Game/GridManager.js → src/screens/Game/logic/GridManager.js View File

@@ -2,10 +2,10 @@
2 2
 
3 3
 import Piece from "./Piece";
4 4
 import ScoreManager from "./ScoreManager";
5
-import type {Coordinates} from './Shapes/BaseShape';
6
-import type {Grid} from "./components/GridComponent";
7
-import type {Cell} from "./components/CellComponent";
8
-import type {CustomTheme} from "../../managers/ThemeManager";
5
+import type {Coordinates} from '../Shapes/BaseShape';
6
+import type {Grid} from "../components/GridComponent";
7
+import type {Cell} from "../components/CellComponent";
8
+import type {CustomTheme} from "../../../managers/ThemeManager";
9 9
 
10 10
 /**
11 11
  * Class used to manage the game grid

src/screens/Game/Piece.js → src/screens/Game/logic/Piece.js View File

@@ -1,14 +1,14 @@
1
-import ShapeL from "./Shapes/ShapeL";
2
-import ShapeI from "./Shapes/ShapeI";
3
-import ShapeJ from "./Shapes/ShapeJ";
4
-import ShapeO from "./Shapes/ShapeO";
5
-import ShapeS from "./Shapes/ShapeS";
6
-import ShapeT from "./Shapes/ShapeT";
7
-import ShapeZ from "./Shapes/ShapeZ";
8
-import type {Coordinates} from './Shapes/BaseShape';
9
-import BaseShape from "./Shapes/BaseShape";
10
-import type {Grid} from "./components/GridComponent";
11
-import type {CustomTheme} from "../../managers/ThemeManager";
1
+import ShapeL from "../Shapes/ShapeL";
2
+import ShapeI from "../Shapes/ShapeI";
3
+import ShapeJ from "../Shapes/ShapeJ";
4
+import ShapeO from "../Shapes/ShapeO";
5
+import ShapeS from "../Shapes/ShapeS";
6
+import ShapeT from "../Shapes/ShapeT";
7
+import ShapeZ from "../Shapes/ShapeZ";
8
+import type {Coordinates} from '../Shapes/BaseShape';
9
+import BaseShape from "../Shapes/BaseShape";
10
+import type {Grid} from "../components/GridComponent";
11
+import type {CustomTheme} from "../../../managers/ThemeManager";
12 12
 
13 13
 /**
14 14
  * Class used as an abstraction layer for shapes.

src/screens/Game/ScoreManager.js → src/screens/Game/logic/ScoreManager.js View File


+ 26
- 0
src/screens/Game/screens/GameEndScreen.js View File

@@ -0,0 +1,26 @@
1
+// @flow
2
+
3
+import * as React from "react";
4
+import {StackNavigationProp} from "@react-navigation/stack";
5
+import type {CustomTheme} from "../../../managers/ThemeManager";
6
+import {withTheme} from "react-native-paper";
7
+
8
+type Props = {
9
+    navigation: StackNavigationProp,
10
+    theme: CustomTheme,
11
+}
12
+
13
+type State = {
14
+
15
+}
16
+
17
+class GameEndScreen extends React.Component<Props, State> {
18
+
19
+    render() {
20
+        return (
21
+            null
22
+        );
23
+    }
24
+}
25
+
26
+export default withTheme(GameEndScreen);

src/screens/Game/GameScreen.js → src/screens/Game/screens/GameMainScreen.js View File

@@ -4,14 +4,14 @@ import * as React from 'react';
4 4
 import {Alert, View} from 'react-native';
5 5
 import {IconButton, Text, withTheme} from 'react-native-paper';
6 6
 import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
7
-import GameLogic from "./GameLogic";
8
-import type {Grid} from "./components/GridComponent";
9
-import GridComponent from "./components/GridComponent";
10
-import Preview from "./components/Preview";
7
+import GameLogic from "../logic/GameLogic";
8
+import type {Grid} from "../components/GridComponent";
9
+import GridComponent from "../components/GridComponent";
10
+import Preview from "../components/Preview";
11 11
 import i18n from "i18n-js";
12
-import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton";
12
+import MaterialHeaderButtons, {Item} from "../../../components/Overrides/CustomHeaderButton";
13 13
 import {StackNavigationProp} from "@react-navigation/stack";
14
-import type {CustomTheme} from "../../managers/ThemeManager";
14
+import type {CustomTheme} from "../../../managers/ThemeManager";
15 15
 
16 16
 type Props = {
17 17
     navigation: StackNavigationProp,
@@ -26,13 +26,13 @@ type State = {
26 26
     gameLevel: number,
27 27
 }
28 28
 
29
-class GameScreen extends React.Component<Props, State> {
29
+class GameMainScreen extends React.Component<Props, State> {
30 30
 
31 31
     logic: GameLogic;
32 32
 
33 33
     constructor(props) {
34 34
         super(props);
35
-        this.logic = new GameLogic(20, 10, this.props.theme.colors);
35
+        this.logic = new GameLogic(20, 10, this.props.theme);
36 36
         this.state = {
37 37
             grid: this.logic.getCurrentGrid(),
38 38
             gameRunning: false,
@@ -287,4 +287,4 @@ class GameScreen extends React.Component<Props, State> {
287 287
 
288 288
 }
289 289
 
290
-export default withTheme(GameScreen);
290
+export default withTheme(GameMainScreen);

+ 36
- 0
src/screens/Game/screens/GameStartScreen.js View File

@@ -0,0 +1,36 @@
1
+// @flow
2
+
3
+import * as React from "react";
4
+import {StackNavigationProp} from "@react-navigation/stack";
5
+import type {CustomTheme} from "../../../managers/ThemeManager";
6
+import {Button, Headline, withTheme} from "react-native-paper";
7
+import {View} from "react-native";
8
+
9
+type Props = {
10
+    navigation: StackNavigationProp,
11
+    theme: CustomTheme,
12
+}
13
+
14
+type State = {
15
+
16
+}
17
+
18
+class GameStartScreen extends React.Component<Props, State> {
19
+
20
+    render() {
21
+        return (
22
+            <View style={{flex: 1}}>
23
+                <Headline style={{textAlign: "center"}}>Coucou</Headline>
24
+                <Button
25
+                    mode={"contained"}
26
+                    onPress={() => this.props.navigation.navigate("game-main")}
27
+                >
28
+                    PLAY
29
+                </Button>
30
+            </View>
31
+        );
32
+    }
33
+}
34
+
35
+export default withTheme(GameStartScreen);
36
+

Loading…
Cancel
Save