leaderboard

This commit is contained in:
angelicatesvara07-crypto 2025-12-15 13:19:37 +07:00
parent 6fc5352be1
commit 25f5d864d3
5 changed files with 127 additions and 27 deletions

BIN
Background.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 737 B

View File

@ -5,15 +5,6 @@ if (!isset($_SESSION['username'])) {
exit; exit;
} }
?> ?>
<html>
<head>
<title>Sudoku</title>
<style>
/*CSS kamu tetap sama*/
</style>
</head>
<body>
<html> <html>
<head> <head>
<title>Sudoku</title> <title>Sudoku</title>
@ -33,17 +24,15 @@ if (!isset($_SESSION['username'])) {
body { body {
font-family: 'Roboto', 'Segoe UI', sans-serif; font-family: 'Roboto', 'Segoe UI', sans-serif;
background-color: var(--bg-color); background: url("Background.jpg") no-repeat center center fixed;
background-size: cover;
color: var(--text-color); color: var(--text-color);
margin: 0; margin: 0;
padding: 0;
height: 100vh; height: 100vh;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden; overflow: hidden;
} }
.screen { .screen {
display: none; display: none;
flex-direction: column; flex-direction: column;
@ -52,7 +41,7 @@ if (!isset($_SESSION['username'])) {
width: 100%; width: 100%;
height: 100%; height: 100%;
position: absolute; position: absolute;
background-color: var(--bg-color); background-color: transparent;
animation: fadeIn 0.3s ease-in-out; animation: fadeIn 0.3s ease-in-out;
} }
@ -385,13 +374,18 @@ if (!isset($_SESSION['username'])) {
</head> </head>
<body> <body>
<div id="screen-menu" class="screen active"> <div id="screen-menu" class="screen active">
<img src="Sudoku icon.jpg" alt="Logo" class="logo-img"> <img src="Sudoku icon.jpg" alt="Logo" class="logo-img">
<div class="app-title">Sudoku</div> <div class="app-title">Sudoku</div>
<button class="btn-main" onclick="showLevelScreen()">Permainan Baru</button> <button class="btn-main" onclick="showLevelScreen()">Permainan Baru</button>
<button class="btn-main" onclick="window.location.href='leaderboard.php'">
Leaderboard
</button>
</div> </div>
<div id="screen-level" class="screen"> <div id="screen-level" class="screen">
<div class="level-title">Pilih Tingkat Kesulitan</div> <div class="level-title">Pilih Tingkat Kesulitan</div>
<button class="btn-level lvl-easy" onclick="startLevel('easy')">MUDAH<div style="font-size: 12px; font-weight: normal; margin-top: 5px;">Santai & Cepat</div></button> <button class="btn-level lvl-easy" onclick="startLevel('easy')">MUDAH<div style="font-size: 12px; font-weight: normal; margin-top: 5px;">Santai & Cepat</div></button>
@ -730,6 +724,7 @@ if (!isset($_SESSION['username'])) {
} }
stopTimer(); stopTimer();
saveScore();
let diffText = document.getElementById('difficulty-label').innerText; let diffText = document.getElementById('difficulty-label').innerText;
let timeText = document.getElementById("timer-label").innerText; let timeText = document.getElementById("timer-label").innerText;
@ -797,6 +792,15 @@ if (!isset($_SESSION['username'])) {
if (b[i][j] != 0) { b[i][j] = 0; count--; } if (b[i][j] != 0) { b[i][j] = 0; count--; }
} }
} }
function saveScore() {
fetch("save_score.php", {
method: "POST",
headers: { "Content-Type": "application/x-www-form-urlencoded" },
body: `difficulty=${currentDifficulty}&time=${secondsElapsed}`
});
}
</script> </script>
</body> </body>
</html> </html>

74
leaderboard.php Normal file
View File

@ -0,0 +1,74 @@
<?php
require_once 'db.php';
// TES KONEKSI
if (!$conn) {
die("DB connection failed");
}
$sql = "
SELECT username, difficulty, time_seconds
FROM leaderboard_sudoku
ORDER BY difficulty, time_seconds ASC
LIMIT 10
";
$result = $conn->query($sql);
?>
<style>
.leaderboard {
background: #1e1e1e;
color: white;
padding: 20px;
border-radius: 10px;
width: 350px;
}
.leaderboard table {
width: 100%;
border-collapse: collapse;
}
.leaderboard th, .leaderboard td {
padding: 8px;
border-bottom: 1px solid #444;
text-align: center;
}
.leaderboard th {
background: #333;
}
</style>
<div class="leaderboard">
<h3>🏆 Leaderboard</h3>
<table>
<tr>
<th>User</th>
<th>Level</th>
<th>Time</th>
</tr>
<?php if ($result && $result->num_rows > 0): ?>
<?php while ($row = $result->fetch_assoc()): ?>
<tr>
<td><?= htmlspecialchars($row['username']) ?></td>
<td><?= strtoupper($row['difficulty']) ?></td>
<td>
<?= sprintf(
"%02d:%02d",
floor($row['time_seconds'] / 60),
$row['time_seconds'] % 60
) ?>
</td>
</tr>
<?php endwhile; ?>
<?php else: ?>
<tr>
<td colspan="3">Belum ada data</td>
</tr>
<?php endif; ?>
</table>
</div>
<?php $conn->close(); ?>

13
save_scoee.php Normal file
View File

@ -0,0 +1,13 @@
<?php
session_start();
require "koneksi.php"; // sesuaikan dengan file koneksi DB kamu
if (!isset($_SESSION['username'])) exit;
$username = $_SESSION['username'];
$difficulty = $_POST['difficulty'];
$time = intval($_POST['time']);
$stmt = $conn->prepare("INSERT INTO leaderboard_sudoku (username, difficulty, time_seconds) VALUES (?, ?, ?)");
$stmt->bind_param("ssi", $username, $difficulty, $time);
$stmt->execute();

View File

@ -63,6 +63,15 @@ ALTER TABLE `users`
-- --
ALTER TABLE `users` ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7; MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
CREATE TABLE leaderboard_sudoku (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50),
difficulty VARCHAR(10),
time_seconds INT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
COMMIT; COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;