-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
100 lines (63 loc) · 1.95 KB
/
script.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
96
97
98
99
name = document.cookie.split(';')[0].split('=')[1]
document.getElementById("name-input").value = name
windowChangeStyle()
refreshClassifica()
function addClassifica(){
clearInterval(gameInterval)
name = document.cookie.split(';')[0].split('=')[1]
let data = {'nome': name, 'score': parseInt(score)}
fetch('http://93.48.224.122:8081/add_score', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data)
})
.then((response) => response.json())
.finally(() => location.reload())
}
function refreshClassifica(){
fetch('http://93.48.224.122:8081/visualizza_classifica')
.then((response) => response.json())
.then((data) => {
data = data['data']
for(let i=1; i<11; i++){
let testoAdd = ''
if(i <= data.length){
testoAdd = data[i-1]['nome'] + ' - ' + data[i-1]['score']
}else{
testoAdd = '???'
}
document.getElementById('pos-'+i.toString()).innerHTML = testoAdd
}
})
}
function nameSave(name){
var now = new Date();
var time = now.getTime();
var expireTime = time + 1000*43200*500;
now.setTime(expireTime);
document.cookie = 'name='+name + ';expires='+now.toUTCString()+';path=/'
}
onresize = (event) => {
windowChangeStyle()
};
function windowChangeStyle(){
let width = window.innerWidth
}
function classificaClick(){
document.location = "classifica.html"
}
function gameClick(){
document.location = "index.html"
}
function setCanvasSize(){
side = 35
canvasHeight = side*20
canvasWidth = side*20
while(window.innerHeight < canvasHeight+canvasY || window.innerWidth < canvasWidth){
side -= 1
canvasHeight = side*20
canvasWidth = side*20
}
}