Browse Source

Improved colors

Arnaud Vergnet 4 years ago
parent
commit
a32294e394

+ 6
- 3
screens/Tetris/GameLogic.js View File

@@ -21,11 +21,14 @@ export default class GameLogic {
21 21
     onTick: Function;
22 22
     endCallback: Function;
23 23
 
24
-    constructor(height: number, width: number) {
24
+    colors: Object;
25
+
26
+    constructor(height: number, width: number, colors: Object) {
25 27
         this.height = height;
26 28
         this.width = width;
27 29
         this.gameRunning = false;
28 30
         this.gameTick = 1000;
31
+        this.colors = colors;
29 32
     }
30 33
 
31 34
     getHeight(): number {
@@ -46,7 +49,7 @@ export default class GameLogic {
46 49
             grid.push([]);
47 50
             for (let col = 0; col < this.getWidth(); col++) {
48 51
                 grid[row].push({
49
-                    color: '#fff',
52
+                    color: this.colors.tetrisBackground,
50 53
                     isEmpty: true,
51 54
                 });
52 55
             }
@@ -145,7 +148,7 @@ export default class GameLogic {
145 148
 
146 149
     createTetromino() {
147 150
         let shape = Math.floor(Math.random() * 7);
148
-        this.currentObject = new Tetromino(shape);
151
+        this.currentObject = new Tetromino(shape, this.colors);
149 152
         if (!this.isTetrominoPositionValid())
150 153
             this.endGame();
151 154
     }

+ 1
- 1
screens/Tetris/TetrisScreen.js View File

@@ -28,7 +28,7 @@ class TetrisScreen extends React.Component<Props, State> {
28 28
     constructor(props) {
29 29
         super(props);
30 30
         this.colors = props.theme.colors;
31
-        this.logic = new GameLogic(20, 10);
31
+        this.logic = new GameLogic(20, 10, this.colors);
32 32
         this.state = {
33 33
             grid: this.logic.getEmptyGrid(),
34 34
             gameTime: 0,

+ 13
- 11
screens/Tetris/Tetromino.js View File

@@ -45,27 +45,29 @@ export default class Tetromino {
45 45
         ],
46 46
     };
47 47
 
48
-    static colors = {
49
-        0: '#00f8ff',
50
-        1: '#ffe200',
51
-        2: '#b817ff',
52
-        3: '#0cff34',
53
-        4: '#ff000b',
54
-        5: '#1000ff',
55
-        6: '#ff9400',
56
-    };
57
-
48
+    static colors: Object;
58 49
 
59 50
     currentType: Object;
60 51
     currentShape: Object;
61 52
     currentRotation: number;
62 53
     position: Object;
54
+    colors: Object;
63 55
 
64
-    constructor(type: Tetromino.types) {
56
+    constructor(type: Tetromino.types, colors: Object) {
65 57
         this.currentType = type;
66 58
         this.currentShape = Tetromino.shapes[type];
67 59
         this.currentRotation = 0;
68 60
         this.position = {x: 0, y: 0};
61
+        this.colors = colors;
62
+        Tetromino.colors = {
63
+            0: colors.tetrisI,
64
+            1: colors.tetrisO,
65
+            2: colors.tetrisT,
66
+            3: colors.tetrisS,
67
+            4: colors.tetrisZ,
68
+            5: colors.tetrisJ,
69
+            6: colors.tetrisL,
70
+        };
69 71
     }
70 72
 
71 73
     getColor() {

+ 1
- 1
screens/Tetris/components/Cell.js View File

@@ -25,7 +25,7 @@ class Cell extends React.PureComponent<Props> {
25 25
                 style={{
26 26
                     flex: 1,
27 27
                     backgroundColor: this.props.color,
28
-                    borderColor: this.props.isEmpty ? this.props.color : "#393939",
28
+                    borderColor: this.props.isEmpty ? this.props.color : this.colors.tetrisBorder,
29 29
                     borderStyle: 'solid',
30 30
                     borderWidth: 1,
31 31
                     aspectRatio: 1,

+ 1
- 1
screens/Tetris/components/Grid.js View File

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

+ 22
- 0
utils/ThemeManager.js View File

@@ -54,6 +54,17 @@ export default class ThemeManager {
54 54
                 proxiwashColor: '#1fa5ee',
55 55
                 menuColor: '#e91314',
56 56
                 tutorinsaColor: '#f93943',
57
+
58
+                // Tetris
59
+                tetrisBackground:'#d1d1d1',
60
+                tetrisBorder:'#afafaf',
61
+                tetrisI : '#42f1ff',
62
+                tetrisO : '#ffdd00',
63
+                tetrisT : '#ba19ff',
64
+                tetrisS : '#0bff34',
65
+                tetrisZ : '#ff0009',
66
+                tetrisJ : '#134cff',
67
+                tetrisL : '#ff8834',
57 68
             },
58 69
         };
59 70
     }
@@ -94,6 +105,17 @@ export default class ThemeManager {
94 105
                 proxiwashColor: '#1fa5ee',
95 106
                 menuColor: '#b81213',
96 107
                 tutorinsaColor: '#f93943',
108
+
109
+                // Tetris
110
+                tetrisBackground:'#2c2c2c',
111
+                tetrisBorder:'#1b1b1b',
112
+                tetrisI : '#30b3be',
113
+                tetrisO : '#c1a700',
114
+                tetrisT : '#9114c7',
115
+                tetrisS : '#08a121',
116
+                tetrisZ : '#b50008',
117
+                tetrisJ : '#0f37b9',
118
+                tetrisL : '#b96226',
97 119
             },
98 120
         };
99 121
     }

Loading…
Cancel
Save