-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaftergame.html
207 lines (176 loc) · 5.95 KB
/
aftergame.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Game Over</title>
<style>
/* Fullscreen Black & Red Theme */
body {
background: linear-gradient(135deg, #000000, #8B0000);
color: white;
font-family: Arial, sans-serif;
text-align: center;
margin: 0;
padding: 0;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
/* Modal Styling */
#gameOverModal {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: '95vw';
max-width: 400px;
background: black;
padding: 20px;
border-radius: 10px;
text-align: center;
box-shadow: 0 0 15px rgba(255, 0, 0, 0.8);
border: 3px solid red;
}
h2 {
color: #ff0000;
font-size: 24px;
}
#gameOverModal p {
font-size: 18px;
margin: 10px 0;
}
/* Button Container */
.button-container {
display: flex;
justify-content: space-between;
gap: 10px;
}
/* Button Styling */
.btn {
flex: 1;
padding: 12px;
border: none;
color: white;
cursor: pointer;
border-radius: 5px;
font-size: 16px;
font-weight: bold;
transition: 0.3s;
}
/* Individual Button Colors */
#playAgainBtn {
background: #28a745; /* Green */
}
#playAgainBtn:hover {
background: #218838;
}
#dashboardBtn {
background: #007BFF; /* Blue */
}
#dashboardBtn:hover {
background: #0056b3;
}
#speakerBtn {
background: #ff0000; /* Red */
width: 100%;
margin-top: 10px;
}
#speakerBtn:hover {
background: #cc0000;
}
/* Responsive Modal */
@media (max-width: 500px) {
#gameOverModal {
width: 85%;
padding: 15px;
border: 4px solid red;
box-shadow: 0 0 20px rgba(255, 0, 0, 1);
}
h2 {
font-size: 20px;
}
#gameOverModal p {
font-size: 16px;
}
.btn {
font-size: 14px;
padding: 10px;
}
}
</style>
</head>
<body>
<div id="gameOverModal">
<h2>Game Over!</h2>
<p><strong>Player Name:</strong> <span id="playerName"></span></p>
<p><strong>Highest Score:</strong> <span id="highestScore"></span></p>
<p class=""><strong>Score:</strong> <span id="lastScore"></span></p>
<div class="button-container">
<button id="playAgainBtn" class="btn">Play Again</button>
<button id="dashboardBtn" class="btn">Leaderbord</button>
</div>
<button id="speakerBtn" class="btn">Tap to reveal speakers</button>
</div>
<script>
let userName = "";
let highestScore = 0;
let lastScore = 0;
function getUserNameFromToken() {
const token = localStorage.getItem("token");
if (!token) return;
try {
const base64Url = token.split(".")[1];
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
const jsonPayload = decodeURIComponent(
atob(base64)
.split("")
.map((c) => "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2))
.join("")
);
const user = JSON.parse(jsonPayload);
userName = user.name;
// console.log("Player Name:", userName);
sendScore()
} catch (error) {
console.error("Error decoding token:", error);
window.location.href = "entry.html";
}
}
function sendScore() {
if (!userName) return;
const data = { name: userName };
// console.log("Sending score:", data);
fetch("https://tedx-al.vercel.app/api/user/get", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data)
})
.then(response => response.json())
.then(result => {
// console.log("Score submitted:", result);
highestScore = result.user.score;
lastScore = result.user.lastScore;
document.getElementById("playerName").textContent = userName;
document.getElementById("highestScore").textContent = highestScore;
document.getElementById("lastScore").textContent = lastScore;
document.getElementById("gameOverModal").style.display = "block";
})
.catch(error => console.error("Error submitting score:", error));
}
document.getElementById("dashboardBtn").addEventListener("click", function () {
window.location.href = "https://tedx-al.vercel.app/dashboard";
});
document.getElementById("speakerBtn").addEventListener("click", function () {
window.location.href = "https://tedx-al.vercel.app/speaker";
});
document.getElementById("playAgainBtn").addEventListener("click", function () {
document.getElementById("gameOverModal").style.display = "none";
window.location.href = 'index-age.html';
});
getUserNameFromToken();
</script>
</body>
</html>