|
@@ -4,6 +4,32 @@ import Tetromino from "./Tetromino";
|
4
|
4
|
|
5
|
5
|
export default class GameLogic {
|
6
|
6
|
|
|
7
|
+ static levelTicks = {
|
|
8
|
+ '1': 1000,
|
|
9
|
+ '2': 900,
|
|
10
|
+ '3': 800,
|
|
11
|
+ '4': 700,
|
|
12
|
+ '5': 600,
|
|
13
|
+ '6': 500,
|
|
14
|
+ '7': 400,
|
|
15
|
+ '8': 300,
|
|
16
|
+ '9': 200,
|
|
17
|
+ '10': 150,
|
|
18
|
+ };
|
|
19
|
+
|
|
20
|
+ static levelThresholds = {
|
|
21
|
+ '1': 100,
|
|
22
|
+ '2': 300,
|
|
23
|
+ '3': 500,
|
|
24
|
+ '4': 700,
|
|
25
|
+ '5': 1000,
|
|
26
|
+ '7': 1500,
|
|
27
|
+ '8': 2000,
|
|
28
|
+ '9': 3000,
|
|
29
|
+ '10': 4000,
|
|
30
|
+ '11': 5000,
|
|
31
|
+ };
|
|
32
|
+
|
7
|
33
|
currentGrid: Array<Array<Object>>;
|
8
|
34
|
|
9
|
35
|
height: number;
|
|
@@ -13,6 +39,7 @@ export default class GameLogic {
|
13
|
39
|
gamePaused: boolean;
|
14
|
40
|
gameTime: number;
|
15
|
41
|
score: number;
|
|
42
|
+ level: number;
|
16
|
43
|
|
17
|
44
|
currentObject: Tetromino;
|
18
|
45
|
|
|
@@ -31,7 +58,6 @@ export default class GameLogic {
|
31
|
58
|
this.width = width;
|
32
|
59
|
this.gameRunning = false;
|
33
|
60
|
this.gamePaused = false;
|
34
|
|
- this.gameTick = 250;
|
35
|
61
|
this.colors = colors;
|
36
|
62
|
}
|
37
|
63
|
|
|
@@ -165,9 +191,21 @@ export default class GameLogic {
|
165
|
191
|
this.currentObject.rotate(false);
|
166
|
192
|
}
|
167
|
193
|
|
|
194
|
+ setNewGameTick(level: number) {
|
|
195
|
+ if (level > 10)
|
|
196
|
+ return;
|
|
197
|
+ this.gameTick = GameLogic.levelTicks[level];
|
|
198
|
+ clearInterval(this.gameTickInterval);
|
|
199
|
+ this.gameTickInterval = setInterval(this.onTick, this.gameTick);
|
|
200
|
+ }
|
|
201
|
+
|
168
|
202
|
onTick(callback: Function) {
|
169
|
203
|
this.tryMoveTetromino(0, 1);
|
170
|
|
- callback(this.score, this.getFinalGrid());
|
|
204
|
+ callback(this.score, this.level, this.getFinalGrid());
|
|
205
|
+ if (this.level <= 10 && this.score > GameLogic.levelThresholds[this.level]) {
|
|
206
|
+ this.level++;
|
|
207
|
+ this.setNewGameTick(this.level);
|
|
208
|
+ }
|
171
|
209
|
}
|
172
|
210
|
|
173
|
211
|
onClock(callback: Function) {
|
|
@@ -248,9 +286,11 @@ export default class GameLogic {
|
248
|
286
|
this.gamePaused = false;
|
249
|
287
|
this.gameTime = 0;
|
250
|
288
|
this.score = 0;
|
|
289
|
+ this.level = 1;
|
|
290
|
+ this.gameTick = GameLogic.levelTicks[this.level];
|
251
|
291
|
this.currentGrid = this.getEmptyGrid();
|
252
|
292
|
this.createTetromino();
|
253
|
|
- tickCallback(this.score, this.getFinalGrid());
|
|
293
|
+ tickCallback(this.score, this.level, this.getFinalGrid());
|
254
|
294
|
clockCallback(this.gameTime);
|
255
|
295
|
this.onTick = this.onTick.bind(this, tickCallback);
|
256
|
296
|
this.onClock = this.onClock.bind(this, clockCallback);
|