-
Notifications
You must be signed in to change notification settings - Fork 0
/
highscores.html
111 lines (94 loc) · 3.2 KB
/
highscores.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<style>
body {
background-color: #f1f1f1;
}
.btn-xl {
padding: 1rem 2rem;
font-size: 1.5rem;
line-height: 2;
border-radius: .6rem;
}
.mt50 {
margin-top: 50px;
}
.mb50 {
margin-bottom: 50px;
}
</style>
<title>Highscores</title>
</head>
<body>
<div class="container">
<div class="row mt50 mb50">
<div class="col">
<h1 class="display-1">#BOEF</h1>
<h3 class="text-muted">Assist the police by playing this game!</h3>
</div>
</div>
<div class="row mt50">
<div class="col-md-12">
<a class="btn btn-success btn-primary btn-xl btn-block" href="index.html" role="button">Back to home</a>
</div>
</div>
<div class="row mt50">
<div class="col-md-6">
<h4>Most recent highscores</h4>
<ul id="lastScores">
<li>
Loading
</li>
</ul>
</div>
<div class="col-md-6">
<h4>All time highscores!</h4>
<ul id="highScores">
<li>
Loading
</li>
</ul>
</div>
</div>
</div>
<script>
function updateScores() {
let request = new XMLHttpRequest();
request.open('GET', 'http://dohdatasciencevm6.westeurope.cloudapp.azure.com/api/maps/Oceans11/scores', false);
request.send(null);
if (request.status === 200) {
let scores = JSON.parse(request.responseText);
console.log(scores);
var sortedHighScores = scores.scores.sort(function (a, b) {
return b.score - a.score
});
console.log(sortedHighScores);
let highScoresUL = document.getElementById('highScores');
highScoresUL.innerHTML = '';
for (var i = 0; i < Math.min(5, sortedHighScores.length); i++) {
let score = sortedHighScores[i];
highScoresUL.innerHTML += '<li><strong>' + score.username + '</strong>: ' + score.score + '</li>';
}
var sortedLastScores = scores.scores.sort(function (a, b) {
return Date.parse(b.datetime) - Date.parse(a.datetime)
});
let lastScoresUL = document.getElementById('lastScores');
lastScoresUL.innerHTML = '';
for (var i = 0; i < Math.min(5, sortedLastScores.length); i++) {
let score = sortedLastScores[i];
lastScoresUL.innerHTML += '<li><strong>' + score.username + '</strong>: ' + score.score + '</li>';
}
}
else
alert(request.responseText);
}
updateScores();
setInterval(updateScores, 1000);
</script>
</body>
</html>