-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodele.js
36 lines (27 loc) · 880 Bytes
/
modele.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
import Piece from "./piece.js";
import TetrisView from './view.js';
class TetrisModel {
constructor(view) {
this.grid = view.getEmptyGrid();
this.score = 0;
this.level = 1;
this.lines = 0;
this.gameOver = false;
}
// Binding.
bindDisplayGrid (callback) {
// Définition d'une nouvelle propriété pouvant être utilisée à partir d'une instance de Model.
this.DisplayGrid = callback; // On veut pouvoir actualiser la View (depuis le Controller) quand nous récupérons les données.
}
start() {
this.view = new TetrisView(this.game);
this.view.getEmptyGrid();
}
getRandomPiece(grid){
const pieces = ['I', 'J', 'L', 'O', 'S', 'T', 'Z'];
const new_piece = new Piece(pieces[Math.floor(Math.random() * pieces.length)], grid);
new_piece.insertPiece();
refreshGrid();
}
}
export default TetrisModel