-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.html
77 lines (61 loc) · 2.45 KB
/
score.html
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
<!DOCTYPE html>
<html>
<head>
<title>UFO BATTLE</title>
<link href="css/styles.css" rel="stylesheet" type="text/css">
<link href="http://fonts.cdnfonts.com/css/picksuhl" rel="stylesheet">
</head>
<body>
<div class="header">
<h1>TIME'S UP!</h1>
</div>
<ul>
<li><a href="home.html">Home</a></li>
<li><a href="preferences.html">Preferences</a></li>
<li><a href="records.html">Records</a></li>
</ul>
<div style="width: 1100px;">
<h2>FINAL SCORE:</h2>
<p id="penalty1">0</p>
<p id="penalty2">0</p>
<h1 id="total"></h1>
</div>
<script type="text/javascript">
window.onload = function () {
let aux = sessionStorage.getItem("number"),
penalty1, penalty2;
penalty1 = sessionStorage.getItem("time") / 60;
if (aux === "1")
penalty2 = 0;
else
penalty2 = (aux-1) * 50;
let calc = sessionStorage.getItem("score") / penalty1 - penalty2;
document.getElementById("penalty1").innerHTML = "Time penalty: 1/" + penalty1;
document.getElementById("penalty2").innerHTML = "# UFO penaly: - " + penalty2 + " points";
document.getElementById("total").innerHTML = "Total: " + calc + " points";
sessionStorage.setItem("score", calc);
loginRequest();
}
var http_request = new XMLHttpRequest(), url = "http://wd.etsisi.upm.es:10000/records?";
function loginRequest(){
if(sessionStorage.getItem("logged")) {
var punctuation = sessionStorage.getItem("score"), ufos = sessionStorage.getItem("number"), disposedTime = sessionStorage.getItem("time");
var params = "punctuation=" + punctuation + "&ufos=" + ufos + "&disposedTime=" + disposedTime;
http_request.open("POST", url, true);
http_request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http_request.setRequestHeader('Authorization', sessionStorage.getItem("token"));
http_request.responseType = 'json';
http_request.onload = responseProcess;
http_request.send(params);
}
}
function responseProcess() {
var aresponse;
if (http_request.status == 201){
alert("Score stored properly!");
}
else
alert("ATTENTION: Error storing score");
}
</script>
</html>