Changed game project organization and added basic start screen

This commit is contained in:
Arnaud Vergnet 2020-07-18 19:45:24 +02:00
parent fe26ec0cc4
commit 3989652c29
12 changed files with 118 additions and 39 deletions

View file

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

View file

@ -8,7 +8,7 @@ import DebugScreen from '../screens/About/DebugScreen';
import {createStackNavigator, TransitionPresets} from "@react-navigation/stack"; import {createStackNavigator, TransitionPresets} from "@react-navigation/stack";
import i18n from "i18n-js"; import i18n from "i18n-js";
import TabNavigator from "./TabNavigator"; import TabNavigator from "./TabNavigator";
import GameScreen from "../screens/Game/GameScreen"; import GameMainScreen from "../screens/Game/screens/GameMainScreen";
import VoteScreen from "../screens/Amicale/VoteScreen"; import VoteScreen from "../screens/Amicale/VoteScreen";
import LoginScreen from "../screens/Amicale/LoginScreen"; import LoginScreen from "../screens/Amicale/LoginScreen";
import {Platform} from "react-native"; import {Platform} from "react-native";
@ -27,6 +27,8 @@ import EquipmentScreen from "../screens/Amicale/Equipment/EquipmentListScreen";
import EquipmentLendScreen from "../screens/Amicale/Equipment/EquipmentRentScreen"; import EquipmentLendScreen from "../screens/Amicale/Equipment/EquipmentRentScreen";
import EquipmentConfirmScreen from "../screens/Amicale/Equipment/EquipmentConfirmScreen"; import EquipmentConfirmScreen from "../screens/Amicale/Equipment/EquipmentConfirmScreen";
import DashboardEditScreen from "../screens/Other/Settings/DashboardEditScreen"; import DashboardEditScreen from "../screens/Other/Settings/DashboardEditScreen";
import GameStartScreen from "../screens/Game/screens/GameStartScreen";
import GameEndScreen from "../screens/Game/screens/GameEndScreen";
const modalTransition = Platform.OS === 'ios' ? TransitionPresets.ModalPresentationIOS : TransitionPresets.ModalSlideFromBottomIOS; const modalTransition = Platform.OS === 'ios' ? TransitionPresets.ModalPresentationIOS : TransitionPresets.ModalSlideFromBottomIOS;
@ -92,8 +94,22 @@ function MainStackComponent(props: { createTabNavigator: () => React.Node }) {
}} }}
/> />
<MainStack.Screen <MainStack.Screen
name="tetris" name="game-start"
component={GameScreen} component={GameStartScreen}
options={{
title: i18n.t("screens.game.title"),
}}
/>
<MainStack.Screen
name="game-main"
component={GameMainScreen}
options={{
title: i18n.t("screens.game.title"),
}}
/>
<MainStack.Screen
name="game-end"
component={GameEndScreen}
options={{ options={{
title: i18n.t("screens.game.title"), title: i18n.t("screens.game.title"),
}} }}

View file

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

View file

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

View file

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

View file

@ -3,6 +3,7 @@
import Piece from "./Piece"; import Piece from "./Piece";
import ScoreManager from "./ScoreManager"; import ScoreManager from "./ScoreManager";
import GridManager from "./GridManager"; import GridManager from "./GridManager";
import type {CustomTheme} from "../../../managers/ThemeManager";
export default class GameLogic { export default class GameLogic {
@ -45,20 +46,20 @@ export default class GameLogic {
#onClock: Function; #onClock: Function;
endCallback: Function; endCallback: Function;
#colors: Object; #theme: CustomTheme;
constructor(height: number, width: number, colors: Object) { constructor(height: number, width: number, theme: CustomTheme) {
this.#height = height; this.#height = height;
this.#width = width; this.#width = width;
this.#gameRunning = false; this.#gameRunning = false;
this.#gamePaused = false; this.#gamePaused = false;
this.#colors = colors; this.#theme = theme;
this.#autoRepeatActivationDelay = 300; this.#autoRepeatActivationDelay = 300;
this.#autoRepeatDelay = 50; this.#autoRepeatDelay = 50;
this.#nextPieces = []; this.#nextPieces = [];
this.#nextPiecesCount = 3; this.#nextPiecesCount = 3;
this.#scoreManager = new ScoreManager(); this.#scoreManager = new ScoreManager();
this.#gridManager = new GridManager(this.getWidth(), this.getHeight(), this.#colors); this.#gridManager = new GridManager(this.getWidth(), this.getHeight(), this.#theme);
} }
getHeight(): number { getHeight(): number {
@ -179,7 +180,7 @@ export default class GameLogic {
generateNextPieces() { generateNextPieces() {
while (this.#nextPieces.length < this.#nextPiecesCount) { while (this.#nextPieces.length < this.#nextPiecesCount) {
this.#nextPieces.push(new Piece(this.#colors)); this.#nextPieces.push(new Piece(this.#theme));
} }
} }
@ -219,7 +220,7 @@ export default class GameLogic {
this.#gameTime = 0; this.#gameTime = 0;
this.#scoreManager = new ScoreManager(); this.#scoreManager = new ScoreManager();
this.#gameTick = GameLogic.levelTicks[this.#scoreManager.getLevel()]; this.#gameTick = GameLogic.levelTicks[this.#scoreManager.getLevel()];
this.#gridManager = new GridManager(this.getWidth(), this.getHeight(), this.#colors); this.#gridManager = new GridManager(this.getWidth(), this.getHeight(), this.#theme);
this.#nextPieces = []; this.#nextPieces = [];
this.generateNextPieces(); this.generateNextPieces();
this.createTetromino(); this.createTetromino();

View file

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

View file

@ -1,14 +1,14 @@
import ShapeL from "./Shapes/ShapeL"; import ShapeL from "../Shapes/ShapeL";
import ShapeI from "./Shapes/ShapeI"; import ShapeI from "../Shapes/ShapeI";
import ShapeJ from "./Shapes/ShapeJ"; import ShapeJ from "../Shapes/ShapeJ";
import ShapeO from "./Shapes/ShapeO"; import ShapeO from "../Shapes/ShapeO";
import ShapeS from "./Shapes/ShapeS"; import ShapeS from "../Shapes/ShapeS";
import ShapeT from "./Shapes/ShapeT"; import ShapeT from "../Shapes/ShapeT";
import ShapeZ from "./Shapes/ShapeZ"; import ShapeZ from "../Shapes/ShapeZ";
import type {Coordinates} from './Shapes/BaseShape'; import type {Coordinates} from '../Shapes/BaseShape';
import BaseShape from "./Shapes/BaseShape"; import BaseShape from "../Shapes/BaseShape";
import type {Grid} from "./components/GridComponent"; import type {Grid} from "../components/GridComponent";
import type {CustomTheme} from "../../managers/ThemeManager"; import type {CustomTheme} from "../../../managers/ThemeManager";
/** /**
* Class used as an abstraction layer for shapes. * Class used as an abstraction layer for shapes.

View file

@ -0,0 +1,26 @@
// @flow
import * as React from "react";
import {StackNavigationProp} from "@react-navigation/stack";
import type {CustomTheme} from "../../../managers/ThemeManager";
import {withTheme} from "react-native-paper";
type Props = {
navigation: StackNavigationProp,
theme: CustomTheme,
}
type State = {
}
class GameEndScreen extends React.Component<Props, State> {
render() {
return (
null
);
}
}
export default withTheme(GameEndScreen);

View file

@ -4,14 +4,14 @@ import * as React from 'react';
import {Alert, View} from 'react-native'; import {Alert, View} from 'react-native';
import {IconButton, Text, withTheme} from 'react-native-paper'; import {IconButton, Text, withTheme} from 'react-native-paper';
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons"; import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
import GameLogic from "./GameLogic"; import GameLogic from "../logic/GameLogic";
import type {Grid} from "./components/GridComponent"; import type {Grid} from "../components/GridComponent";
import GridComponent from "./components/GridComponent"; import GridComponent from "../components/GridComponent";
import Preview from "./components/Preview"; import Preview from "../components/Preview";
import i18n from "i18n-js"; import i18n from "i18n-js";
import MaterialHeaderButtons, {Item} from "../../components/Overrides/CustomHeaderButton"; import MaterialHeaderButtons, {Item} from "../../../components/Overrides/CustomHeaderButton";
import {StackNavigationProp} from "@react-navigation/stack"; import {StackNavigationProp} from "@react-navigation/stack";
import type {CustomTheme} from "../../managers/ThemeManager"; import type {CustomTheme} from "../../../managers/ThemeManager";
type Props = { type Props = {
navigation: StackNavigationProp, navigation: StackNavigationProp,
@ -26,13 +26,13 @@ type State = {
gameLevel: number, gameLevel: number,
} }
class GameScreen extends React.Component<Props, State> { class GameMainScreen extends React.Component<Props, State> {
logic: GameLogic; logic: GameLogic;
constructor(props) { constructor(props) {
super(props); super(props);
this.logic = new GameLogic(20, 10, this.props.theme.colors); this.logic = new GameLogic(20, 10, this.props.theme);
this.state = { this.state = {
grid: this.logic.getCurrentGrid(), grid: this.logic.getCurrentGrid(),
gameRunning: false, gameRunning: false,
@ -287,4 +287,4 @@ class GameScreen extends React.Component<Props, State> {
} }
export default withTheme(GameScreen); export default withTheme(GameMainScreen);

View file

@ -0,0 +1,36 @@
// @flow
import * as React from "react";
import {StackNavigationProp} from "@react-navigation/stack";
import type {CustomTheme} from "../../../managers/ThemeManager";
import {Button, Headline, withTheme} from "react-native-paper";
import {View} from "react-native";
type Props = {
navigation: StackNavigationProp,
theme: CustomTheme,
}
type State = {
}
class GameStartScreen extends React.Component<Props, State> {
render() {
return (
<View style={{flex: 1}}>
<Headline style={{textAlign: "center"}}>Coucou</Headline>
<Button
mode={"contained"}
onPress={() => this.props.navigation.navigate("game-main")}
>
PLAY
</Button>
</View>
);
}
}
export default withTheme(GameStartScreen);