-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBase2048.js
71 lines (61 loc) · 1.32 KB
/
Base2048.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
window.onload = function() {
generateMap(4);
generateScore(0);
displayBestScore();
generateCell();
var score = 0;
$('body').on('keydown', function(e) {
if (e.which === 37) {
// si fleche de gauche
let grid1 = copyGridState();
left();
testVictory();
let grid2 = copyGridState();
if (grid1 != grid2) {
displayBestScore();
generateCell();
} else {
testDefeat();
}
}
if (e.which === 38) {
// si fleche du haut
let grid1 = copyGridState();
up();
testVictory();
let grid2 = copyGridState();
if (grid1 != grid2) {
displayBestScore();
generateCell();
}
}
if (e.which === 39) {
// si fleche de droite
let grid1 = copyGridState();
right();
testVictory();
let grid2 = copyGridState();
if (grid1 != grid2) {
displayBestScore();
generateCell();
} else {
testDefeat();
}
}
if (e.which === 40) {
// si fleche du bas
let grid1 = copyGridState();
down();
testVictory();
let grid2 = copyGridState();
if (grid1 != grid2) {
displayBestScore();
generateCell();
} else {
testDefeat();
}
} //end if touche du bas
});
//
//
}; // end game