Skip to content

Commit 8073757

Browse files
committed
test
1 parent 563cf52 commit 8073757

File tree

2 files changed

+129
-1
lines changed

2 files changed

+129
-1
lines changed

Diff for: index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ <h4>Play the game</h4>
1616
<div class="tetris">
1717
<div class="grid"></div>
1818
<div class="sidebar">
19-
<h3>Score:<span id="score">0</span></h3>
19+
<h3>Score:<span id="score" class="score">0</span></h3>
2020
<!-- BOUTON start et Pause -->
2121
<div class="controls">
2222
<button id ="start" class="start">Start</button>

Diff for: test.js

+128
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@ class Controller {
2222
this.bindupdateGrid = this.bindupdateGrid.bind(this);
2323
this.modele.bindupdateGrid(this.bindupdateGrid);
2424

25+
<<<<<<< Updated upstream
26+
=======
27+
this.bindmoveRight = this.bindmoveRight.bind(this);
28+
this.view.bindmoveRight(this.bindmoveRight);
29+
30+
this.bindmoveLeft = this.bindmoveLeft.bind(this);
31+
this.view.bindmoveLeft(this.bindmoveLeft);
32+
33+
this.bindrotate = this.bindrotate.bind(this);
34+
this.view.bindrotate(this.bindrotate);
35+
36+
this.bindmoveDown = this.bindmoveDown.bind(this);
37+
this.view.bindmoveDown(this.bindmoveDown);
38+
39+
this.bindremoveLine = this.bindremoveLine.bind(this);
40+
this.modele.bindremoveLine(this.bindremoveLine);
41+
42+
>>>>>>> Stashed changes
2543
}
2644

2745
bindgetEmptyGrid(grid) {
@@ -40,18 +58,43 @@ class Controller {
4058
this.view.updateGrid();
4159
}
4260

61+
<<<<<<< Updated upstream
4362

63+
=======
64+
bindmoveRight() {
65+
this.modele.moveRight();
66+
}
67+
68+
bindmoveLeft() {
69+
this.modele.moveLeft();
70+
}
71+
72+
bindrotate() {
73+
this.modele.rotate();
74+
}
75+
76+
bindmoveDown() {
77+
this.modele.moveDown();
78+
}
79+
80+
bindremoveLine() {
81+
this.view.removeLine();
82+
}
83+
84+
>>>>>>> Stashed changes
4485
}
4586

4687
export let ctx;
4788
export let grid = [];
89+
export let score = 0;
4890

4991
class TetrisView {
5092

5193
constructor() {
5294

5395
this.startButton = document.getElementById("start");
5496
this.pauseButton = document.getElementById("stop");
97+
this.score1 = document.getElementById("score");
5598

5699
this.canvas = document.getElementById('tetris-canvas');
57100
ctx = this.canvas.getContext('2d');
@@ -63,6 +106,21 @@ class TetrisView {
63106
this.pauseButton.addEventListener('click', () => {
64107
this.pause();
65108
});
109+
<<<<<<< Updated upstream
110+
=======
111+
//Detecte lorsque on appuit sur une touche du clavier
112+
document.addEventListener("keydown", function(event) {
113+
if (event.keyCode == 37) { //fleche gauche
114+
this.moveLeft();
115+
} else if (event.keyCode == 39) { //fleche de droite
116+
this.moveRight();
117+
} else if (event.keyCode == 38) { //fleche du haut pour rotate la piece
118+
this.rotate();
119+
} else if (event.keyCode == 40) { //fleche du bas pour faire acceler la piece
120+
this.moveDown();
121+
}
122+
}.bind(this));
123+
>>>>>>> Stashed changes
66124

67125
this.game = new TetrisModel(this);
68126
}
@@ -77,6 +135,41 @@ class TetrisView {
77135
this.drop = callback; // On veut pouvoir actualiser la View (depuis le Controller) quand nous récupérons les données.
78136
}
79137

138+
<<<<<<< Updated upstream
139+
=======
140+
bindmoveRight (callback) {
141+
this.moveRight = callback;
142+
}
143+
144+
bindmoveLeft (callback) {
145+
this.moveLeft = callback;
146+
}
147+
148+
bindrotate (callback) {
149+
this.rotate = callback;
150+
}
151+
152+
bindmoveDown (callback) {
153+
this.moveDown = callback;
154+
}
155+
156+
///////////////////// FIN BIND VIEW ////////////////////////////////
157+
158+
//Fonction qui permet de supprimer la ligne lorsque elle est pleine
159+
removeLine() {
160+
for (let row = 0; row < grid.length; row++) { //parcours chaque ligne du tableau
161+
let isRowFull = grid[row].every(function(cell) {//verifie si toutes les cellules de la ligne sont remplis
162+
return cell !== 0;
163+
});
164+
if (isRowFull) {
165+
grid.splice(row, 1); // splice : methode permettant de supprimer la ligne
166+
grid.unshift(Array(10).fill(0)); //et une nouvelle ligne remplis de 0 est ajoutee en haut (unshift) ce qui permet de faire tomber toute les lignes du dessus.
167+
}
168+
}
169+
}
170+
171+
//Permet de mettre a jour la grille
172+
>>>>>>> Stashed changes
80173
updateGrid() {
81174
// On efface la grille
82175
ctx.fillStyle = ctx.background;
@@ -199,6 +292,12 @@ class TetrisModel {
199292
this.level = 1;
200293
this.lines = 0;
201294
this.gameOver = false;
295+
<<<<<<< Updated upstream
296+
=======
297+
this.currentPiece;
298+
this.nextPiece;
299+
this.multiplier=1;
300+
>>>>>>> Stashed changes
202301
}
203302

204303
// Binding.
@@ -212,6 +311,16 @@ class TetrisModel {
212311
this.updateGrid = callback; // On veut pouvoir actualiser la View (depuis le Controller) quand nous récupérons les données.
213312
}
214313

314+
<<<<<<< Updated upstream
315+
=======
316+
bindremoveLine (callback) {
317+
// Définition d'une nouvelle propriété pouvant être utilisée à partir d'une instance de Model.
318+
this.removeLine = callback; // On veut pouvoir actualiser la View (depuis le Controller) quand nous récupérons les données.
319+
}
320+
321+
///////////////////// FIN BIND MODELE ////////////////////////////////
322+
323+
>>>>>>> Stashed changes
215324
//Focntion qui se lance au démarrage du jeu
216325
start() {
217326
this.getEmptyGrid();
@@ -225,6 +334,17 @@ class TetrisModel {
225334
this.updateGrid();
226335
}
227336

337+
gameOver(){
338+
alert("Game Over !");
339+
}
340+
341+
score(nb_ligne){
342+
for (i in nb_ligne){
343+
this.score += this.multiplier * 100;
344+
this.multiplier++;
345+
}
346+
}
347+
228348
moveDown() {
229349
for (let i = 19; i >= 0; i--) {
230350
for (let j = 0; j < 10; j++) {
@@ -245,7 +365,15 @@ class TetrisModel {
245365
const pieces = ['I', 'J', 'L', 'O', 'S', 'T', 'Z'];
246366
const new_piece = new Piece(pieces[Math.floor(Math.random() * pieces.length)], grid);
247367
this.intervalId = setInterval(() => {
368+
<<<<<<< Updated upstream
248369
this.moveDown();
370+
=======
371+
if(this.moveDown() === 0){
372+
this.getRandomPiece(grid);
373+
this.removeLine();
374+
this.updateGrid();
375+
}
376+
>>>>>>> Stashed changes
249377
}, 1000);
250378
}
251379

0 commit comments

Comments
 (0)