-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleaderboard.html
More file actions
138 lines (123 loc) · 5.19 KB
/
leaderboard.html
File metadata and controls
138 lines (123 loc) · 5.19 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description" content="Number Guessing Game">
<meta name="author" content="Group K8">
<meta name="keywords" content="Number Guessing Game, Guessing Game, Number Game, Game">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<title>Leaderboard</title>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='styles.css') }}">
<style>
.leaderboard li {
font-size: 16px;
padding: 8px;
background: white;
margin: 5px 0;
border-radius: 6px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
transition: transform 0.3s ease-in-out;
animation: fadeInUp 0.5s ease-in-out;
}
.leaderboard li:hover {
transform: scale(1.05);
background-color: #d4edda;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
</style>
</head>
<body>
<a href="{{ url_for('logout') }}">Logout</a>
<h1>Welcome, {{ username }}!</h1>
<p>Leaderboard:</p>
{% if leaderboard %}
<ul class="leaderboard">
{% for user in leaderboard %}
<li>
{% if loop.index == 1 %}
🥇 <strong>{{ user.username }}</strong> - {{ user.score }}
{% elif loop.index == 2 %}
🥈 <strong>{{ user.username }}</strong> - {{ user.score }}
{% elif loop.index == 3 %}
🥉 <strong>{{ user.username }}</strong> - {{ user.score }}
{% else %}
{{ user.username }} - {{ user.score }}
{% endif %}
</li>
{% endfor %}
</ul>
{% else %}
<p>No players yet. Be the first to play!</p>
{% endif %}
</ul>
<audio id="celebrationSound">
<source src="{{ url_for('static', filename='success.mp3') }}" type="audio/mpeg">
</audio>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#leaderboardModal" onclick="fetchLeaderboard()">
View Leaderboard
</button>
<div class="modal fade" id="leaderboardModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Leaderboard</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<ul id="leaderboardList" class="list-group">
<!-- Dynamic leaderboard will be inserted here -->
</ul>
</div>
</div>
</div>
</div>
<script>
// Function to play sound when user is in top 3
function playCelebrationSound() {
let sound = document.getElementById("celebrationSound");
sound.play();
}
// Play sound if the user is in the top 3 on page load
window.onload = function () {
let leaderboardItems = document.querySelectorAll('.leaderboard li');
leaderboardItems.forEach(item => {
if (item.textContent.includes('🥇') || item.textContent.includes('🥈') || item.textContent.includes('🥉')) {
playCelebrationSound(); // Play sound for top 3 players
}
});
};
// Fetch and update leaderboard
function fetchLeaderboard() {
fetch('/leaderboard-data')
.then(response => response.json())
.then(data => {
let leaderboardList = document.getElementById("leaderboardList");
leaderboardList.innerHTML = ""; // Clear existing list
data.forEach((user, index) => {
let listItem = document.createElement("li");
listItem.classList.add("list-group-item");
listItem.innerHTML =
(index == 0 ? "🥇 " : index == 1 ? "🥈 " : index == 2 ? "🥉 " : "") +
`<strong>${user.username}</strong> - ${user.score}`;
leaderboardList.appendChild(listItem);
});
});
}
// Refresh leaderboard every 10 seconds
setInterval(fetchLeaderboard, 10000);
</script>
<script src="{{ url_for('static', filename='script.js') }}"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>