Improved colors

This commit is contained in:
Arnaud Vergnet 2020-03-15 20:34:20 +01:00
parent 7b45841c30
commit a32294e394
6 changed files with 44 additions and 17 deletions

View file

@ -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();
}

View file

@ -28,7 +28,7 @@ class TetrisScreen extends React.Component<Props, State> {
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,

View file

@ -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() {

View file

@ -25,7 +25,7 @@ class Cell extends React.PureComponent<Props> {
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,

View file

@ -31,7 +31,7 @@ class Grid extends React.Component<Props>{
return(
<View style={{
flexDirection: 'row',
backgroundColor: '#fff'
backgroundColor: this.colors.tetrisBackground
}}>
{cells}
</View>

View file

@ -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',
},
};
}