forked from livnoni/snakeGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (48 loc) · 1.95 KB
/
index.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
//create Tabulator on DOM element with id "score-table"
$("#score-table").tabulator({
// height:100, // set height of table (in CSS or here), this enables the Virtual DOM and improves render speed dramatically (can be any valid css height value)
layout:"fitColumns", //fit columns to width of table (optional)
rowFormatter:function(row){
if(row.getData().id == 1){
row.getElement().css({"background-color":"#75df12"});
}
else if(row.getData().id <= 10){
row.getElement().css({"background-color":"#dfd465"});
}
else {
row.getElement().css({"background-color":"#df767a"});
}
},
columns:[ //Define Table Columns
{title:"Rate", field:"id", width:30, align:"center"},
{title:"Name", field:"name"},
{title:"Score", field:"score"},
{title:"mark", field:"mark", align:"left", formatter:"progress"},
]
});
function onGameOver(data) {
var username = prompt("Please enter your name:", "your name");
if (username == null || username == "") {
console.log("User cancelled the prompt.")
} else {
if(username == "your name") username = "Unknown Player";
console.log("username=",username);
console.log("data=",Object.assign(data,{name:username}));
var xhr = new XMLHttpRequest();
xhr.open("POST", `${config.nodeServerAddress}/sendScore`, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(data));
}
if (confirm("Do you want to play again ?")) {
var game = new Game();
console.log("game=\n"+JSON.stringify(game));
game.startGame();
} else {
}
}
////////////////////////////////////////////////////////////
///////////////////////RUN-GAME/////////////////////////////
////////////////////////////////////////////////////////////
var game = new Game();
console.log("game=\n"+JSON.stringify(game));
game.startGame();