-
Notifications
You must be signed in to change notification settings - Fork 0
/
2048.js
96 lines (74 loc) · 1.91 KB
/
2048.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import grid from './modules/grid.js';
grid.init();
document.addEventListener("keyup", function (e) {
let direction = null;
if (e.keyCode === 38) {
direction = "UP";
} else if (e.keyCode === 39) {
direction = "RIGHT";
} else if (e.keyCode === 40) {
direction = "DOWN";
} else if (e.keyCode === 37) {
direction = "LEFT";
}
if (direction !== null) {
grid.slide(direction);
}
return false;
});
// touch mobile with hammer
// var myElement = document.getElementById('wrapper');
var myElement = document.querySelector('.wrapper');
var mc = new Hammer(myElement);
//enable all directions
mc.get('swipe').set({
direction: Hammer.DIRECTION_ALL,
threshold: 1,
velocity:0.1
});
// listen to events...
mc.on("swipeup swipedown swipeleft swiperight tap press", function(ev) {
let direction = null;
if (ev.type === 'swiperight') {
direction = "RIGHT";
} else if (ev.type === 'swipeleft') {
direction = "LEFT";
} else if (ev.type === 'swipeup') {
direction = "UP";
} else if (ev.type === 'swipedown') {
direction = "DOWN";
}
if (direction !== null) {
grid.slide(direction);
}
return false;
});
// listen voice AI move game
var alanBtnInstance = alanBtn({
key: "90307e8608d5558e8868eff283c9f0fb2e956eca572e1d8b807a3e2338fdd0dc/stage",
// onCommand: function (commandData) {
// if (commandData.command === "go:back") {
// //call client code that will react on the received command
// }
// },
onCommand: function(commondData) {
let directionVoice = null;
if (commondData.command === 'go-left') {
directionVoice = "LEFT";
}
if (commondData.command === 'go-right') {
directionVoice = "RIGHT";
}
if (commondData.command === 'go-up') {
directionVoice = "UP";
}
if (commondData.command === 'go-down') {
directionVoice = "DOWN";
}
if (directionVoice !== null) {
grid.slide(directionVoice);
}
return false;
},
rootEl: document.getElementById("alan-btn"),
});