This repository has been archived by the owner on May 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaderboard.html
123 lines (112 loc) · 3.14 KB
/
leaderboard.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
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Top 10 Scores</title>
<style>
body {
font-family: Arial, sans-serif;
background: center/cover repeat;
color: #333;
text-align: center;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
}
.container {
width: 80%;
max-width: 800px;
background-color: rgba(255, 255, 255, 0.8);
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 10px;
margin-top: 32px;
margin-bottom: 32px;
}
h1 {
font-size: 2.5rem;
margin-bottom: 1rem;
}
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
padding: 10px;
border-bottom: 1px solid #ccc;
text-align: left;
}
th {
font-size: 1.25rem;
font-weight: bold;
background-color: #f9f9f9;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
tr:hover {
background-color: #ddd;
}
.score {
font-size: 32px;
font-weight: bold;
color: #2ecc71;
}
.ranking-img {
width: 48px;
height: 48px;
margin-right: 5px;
display: inline-block;
font-size: 32px;
text-align: center;
line-height: 48px;
}
</style>
</head>
<body>
<div class="container">
<a href="/">Back to game</a>
<h1>Top 10 Scores</h1>
<table>
<thead>
<tr>
<th>Rank</th>
<th>Score</th>
</tr>
</thead>
<tbody id="table-body"></tbody>
</table>
</div>
<script type="module">
import LeaderboardManager from "./src/LeaderboardManager";
import firstPlacePNG from "./Textures/FirstPlacePNG.png";
import secondPlacePNG from "./Textures/SecondPlacePNG.png";
import thirdPlacePNG from "./Textures/ThirdPlacePNG.png";
import background from "./Textures/GameBackgroundDarkPNG.png";
document.body.style.backgroundImage = `url(${background})`;
const leaderboard = new LeaderboardManager();
const scores = leaderboard.viewTopScores().map(({ value }) => value);
const element = document.getElementById("table-body");
const rankingImages = [firstPlacePNG, secondPlacePNG, thirdPlacePNG];
if (scores.length === 0) {
element.innerHTML = `<tr><td colspan="2">You haven't played this game yet!</td></tr>`;
} else {
element.innerHTML = scores
.map((score, i) =>
i < 3
? `<tr><td><img class="ranking-img" src="${
rankingImages[i] || "default-ranking.png"
}"></td><td class="score">${score}</td></tr>`
: `<tr><td><span class="ranking-img">${
i + 1
}</span></td><td class="score">${score}</td></tr>`
)
.join("");
}
</script>
</body>
</html>