From a32294e394d58e9f4b6be6489b5d25273b9a0bb2 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Sun, 15 Mar 2020 20:34:20 +0100 Subject: [PATCH] Improved colors --- screens/Tetris/GameLogic.js | 9 ++++++--- screens/Tetris/TetrisScreen.js | 2 +- screens/Tetris/Tetromino.js | 24 +++++++++++++----------- screens/Tetris/components/Cell.js | 2 +- screens/Tetris/components/Grid.js | 2 +- utils/ThemeManager.js | 22 ++++++++++++++++++++++ 6 files changed, 44 insertions(+), 17 deletions(-) diff --git a/screens/Tetris/GameLogic.js b/screens/Tetris/GameLogic.js index c93c4d0..44e19a6 100644 --- a/screens/Tetris/GameLogic.js +++ b/screens/Tetris/GameLogic.js @@ -21,11 +21,14 @@ export default class GameLogic { onTick: Function; endCallback: Function; - constructor(height: number, width: number) { + colors: Object; + + constructor(height: number, width: number, colors: Object) { this.height = height; this.width = width; this.gameRunning = false; this.gameTick = 1000; + this.colors = colors; } getHeight(): number { @@ -46,7 +49,7 @@ export default class GameLogic { grid.push([]); for (let col = 0; col < this.getWidth(); col++) { grid[row].push({ - color: '#fff', + color: this.colors.tetrisBackground, isEmpty: true, }); } @@ -145,7 +148,7 @@ export default class GameLogic { createTetromino() { let shape = Math.floor(Math.random() * 7); - this.currentObject = new Tetromino(shape); + this.currentObject = new Tetromino(shape, this.colors); if (!this.isTetrominoPositionValid()) this.endGame(); } diff --git a/screens/Tetris/TetrisScreen.js b/screens/Tetris/TetrisScreen.js index a21c2a3..c0bb6dc 100644 --- a/screens/Tetris/TetrisScreen.js +++ b/screens/Tetris/TetrisScreen.js @@ -28,7 +28,7 @@ class TetrisScreen extends React.Component { constructor(props) { super(props); this.colors = props.theme.colors; - this.logic = new GameLogic(20, 10); + this.logic = new GameLogic(20, 10, this.colors); this.state = { grid: this.logic.getEmptyGrid(), gameTime: 0, diff --git a/screens/Tetris/Tetromino.js b/screens/Tetris/Tetromino.js index 5aa75fe..470b97a 100644 --- a/screens/Tetris/Tetromino.js +++ b/screens/Tetris/Tetromino.js @@ -45,27 +45,29 @@ export default class Tetromino { ], }; - static colors = { - 0: '#00f8ff', - 1: '#ffe200', - 2: '#b817ff', - 3: '#0cff34', - 4: '#ff000b', - 5: '#1000ff', - 6: '#ff9400', - }; - + static colors: Object; currentType: Object; currentShape: Object; currentRotation: number; position: Object; + colors: Object; - constructor(type: Tetromino.types) { + constructor(type: Tetromino.types, colors: Object) { this.currentType = type; this.currentShape = Tetromino.shapes[type]; this.currentRotation = 0; this.position = {x: 0, y: 0}; + this.colors = colors; + Tetromino.colors = { + 0: colors.tetrisI, + 1: colors.tetrisO, + 2: colors.tetrisT, + 3: colors.tetrisS, + 4: colors.tetrisZ, + 5: colors.tetrisJ, + 6: colors.tetrisL, + }; } getColor() { diff --git a/screens/Tetris/components/Cell.js b/screens/Tetris/components/Cell.js index a3fd525..f0e764c 100644 --- a/screens/Tetris/components/Cell.js +++ b/screens/Tetris/components/Cell.js @@ -25,7 +25,7 @@ class Cell extends React.PureComponent { style={{ flex: 1, backgroundColor: this.props.color, - borderColor: this.props.isEmpty ? this.props.color : "#393939", + borderColor: this.props.isEmpty ? this.props.color : this.colors.tetrisBorder, borderStyle: 'solid', borderWidth: 1, aspectRatio: 1, diff --git a/screens/Tetris/components/Grid.js b/screens/Tetris/components/Grid.js index 19be7f9..53e7904 100644 --- a/screens/Tetris/components/Grid.js +++ b/screens/Tetris/components/Grid.js @@ -31,7 +31,7 @@ class Grid extends React.Component{ return( {cells} diff --git a/utils/ThemeManager.js b/utils/ThemeManager.js index 86ae540..eb3f914 100644 --- a/utils/ThemeManager.js +++ b/utils/ThemeManager.js @@ -54,6 +54,17 @@ export default class ThemeManager { proxiwashColor: '#1fa5ee', menuColor: '#e91314', tutorinsaColor: '#f93943', + + // Tetris + tetrisBackground:'#d1d1d1', + tetrisBorder:'#afafaf', + tetrisI : '#42f1ff', + tetrisO : '#ffdd00', + tetrisT : '#ba19ff', + tetrisS : '#0bff34', + tetrisZ : '#ff0009', + tetrisJ : '#134cff', + tetrisL : '#ff8834', }, }; } @@ -94,6 +105,17 @@ export default class ThemeManager { proxiwashColor: '#1fa5ee', menuColor: '#b81213', tutorinsaColor: '#f93943', + + // Tetris + tetrisBackground:'#2c2c2c', + tetrisBorder:'#1b1b1b', + tetrisI : '#30b3be', + tetrisO : '#c1a700', + tetrisT : '#9114c7', + tetrisS : '#08a121', + tetrisZ : '#b50008', + tetrisJ : '#0f37b9', + tetrisL : '#b96226', }, }; }