forked from vikingeducation/project_tetris_js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
56 lines (46 loc) · 1.03 KB
/
Copy pathcontroller.js
File metadata and controls
56 lines (46 loc) · 1.03 KB
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
var controller = {
init: function() {
model.init();
view.init();
this.getBoard();
this.gameLoop();
},
getBoard: function() {
var tiles = model.totalTiles;
view.placeBoard(tiles);
},
getScore: function() {
var score = model.score;
view.renderScore(score);
},
reRender: function () {
view.clear();
view.render(model.currentPiece, model.grid);
},
//Take the following method out; put into model
playerInput: function(){
var button = model.keyPress;
model.movePiece(button);
},
gameLoop: function() {
model.generatePiece();
var counter = 0;
thatController = this;
setInterval(function() {
model.grid.sort();
if(counter % 1 === 0) {
thatController.playerInput();
}
if(counter % 10 === 0) {
model.fallPiece();
}
//logic, validations
model.checkForBoundary();
model.clearLines();
//rerender
thatController.reRender();
thatController.getScore();
counter ++;
}, 20)
}
}