-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresults.php
More file actions
92 lines (82 loc) · 2.47 KB
/
Copy pathresults.php
File metadata and controls
92 lines (82 loc) · 2.47 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
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$room = $_GET['room'] ?? '';
$name = $_GET['name'] ?? '';
$path = "rooms/$room.json";
if (!file_exists($path)) {
die("Room not found.");
}
$data = json_decode(file_get_contents($path), true);
if (!($data['results_ready'] ?? false)) {
die("Results not ready yet.");
}
$questions = $data['questions'] ?? [];
$current_index = $data['question_index'] ?? 0;
$is_host = ($data['host'] === $name);
?>
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Round Results</title>
<link rel="stylesheet" href="style.css">
</head>
<canvas id="confetti-canvas" class="confetti"></canvas>
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.6.0/dist/confetti.browser.min.js"></script>
<script>
setTimeout(() => {
confetti({
particleCount: 150,
spread: 80,
origin: { y: 0.6 }
});
}, 500);
</script>
<body>
<h2>🎉 Results for This Round</h2>
<?php if (!empty($data['votes'])): ?>
<ul>
<?php
arsort($data['votes']);
foreach ($data['votes'] as $player => $count): ?>
<li><strong><?= htmlspecialchars($player) ?></strong>: <?= $count ?> vote(s)</li>
<?php endforeach; ?>
</ul>
<?php else: ?>
<p><em>No votes recorded.</em></p>
<?php endif; ?>
<?php if ($current_index + 1 < count($questions)): ?>
<?php if ($is_host): ?>
<form action="next_round.php" method="POST">
<input type="hidden" name="room" value="<?= htmlspecialchars($room) ?>">
<input type="hidden" name="name" value="<?= htmlspecialchars($name) ?>">
<button type="submit">➡️ Next Question</button>
</form>
<?php else: ?>
<p><em>Waiting for the host to start the next round...</em></p>
<script>
function checkRoundStart() {
fetch('get_status.php?room=<?= $room ?>')
.then(res => res.json())
.then(data => {
if (data.round_started) {
window.location.href = "game.php?room=<?= $room ?>&name=<?= urlencode($name) ?>";
}
});
}
setInterval(checkRoundStart, 1000);
</script>
<?php endif; ?>
<?php else: ?>
<h3>🏁 Game Over! Thanks for playing 🎉</h3>
<form action="index.php" method="GET">
<button type="submit">🔁 Back to Start</button>
</form>
<?php
// Optional: delete room file
// unlink($path);
?>
<?php endif; ?>
</body>
</html>