-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.js
56 lines (53 loc) · 1.07 KB
/
level.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function Level() {
this.level = 1;
this.rand = 0;
this.tetrominoInQueue = 0;
this.nextTetromino = 0;
this.lockDelay = 1000;
}
Level.prototype.getLevel = function() {
return this.level;
};
Level.prototype.getNextTetromino = function() {
var new_rand = Math.floor(Math.random() * 7) + 1;
while(new_rand === this.rand) {
new_rand = Math.floor(Math.random() * 7) + 1;
}
this.rand = new_rand;
console.log("Random Nunber: " + this.rand);
switch(this.rand) {
case 1:
this.nextTetromino = new IBlock();
break;
case 2:
this.nextTetromino = new JBlock();
break;
case 3:
this.nextTetromino = new SBlock();
break;
case 4:
this.nextTetromino = new ZBlock();
break;
case 5:
this.nextTetromino = new OBlock();
break;
case 6:
this.nextTetromino = new TBlock();
break;
case 7:
this.nextTetromino = new LBlock();
break;
}
return this.nextTetromino;
};
Level.prototype.levelUp = function() {
if(this.lockDelay >= 500) {
this.lockDelay -= 100;
} else {
this.lockDelay -= 50;
}
if(this.level < 15) {
this.level++;
}
return this.level;
};