-
Notifications
You must be signed in to change notification settings - Fork 0
/
operations.js
40 lines (34 loc) · 901 Bytes
/
operations.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
// Positions object
var positions = {};
// Operations
exports.update = function(link) {
var data = link.data;
var color = data.id.toString().substring(0, 1);
var idInArray = parseInt(data.id.toString().substring(1));
if(color === "W") {
positions.white[idInArray] = { "x" : data.x, "y" : data.y };
}
else {
positions.black[idInArray] = { "x" : data.x, "y" : data.y };
}
link.send(200, positions);
};
// Built positions object
exports.setPositions = function(link) {
positions = link.data;
link.send(200);
};
// Get positions operations
exports.getPositions = function(link) {
link.send(200, positions);
};
// Reset the game
exports.resetGame = function(linke) {
if(link.data === "IonicaBizauMill") {
positions = {};
link.send(200, "Refresh page");
}
else {
link.send(200, "Wrong password");
}
}