diff --git a/Background.jpg b/Background.jpg
new file mode 100644
index 0000000..a802b9d
Binary files /dev/null and b/Background.jpg differ
diff --git a/Sudoku.php b/Sudoku.php
index 081ac6f..961570a 100644
--- a/Sudoku.php
+++ b/Sudoku.php
@@ -5,15 +5,6 @@ if (!isset($_SESSION['username'])) {
exit;
}
?>
-
-
-
-
Pilih Tingkat Kesulitan
@@ -730,7 +724,8 @@ if (!isset($_SESSION['username'])) {
}
stopTimer();
-
+ saveScore();
+
let diffText = document.getElementById('difficulty-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--; }
}
}
+
+ function saveScore() {
+ fetch("save_score.php", {
+ method: "POST",
+ headers: { "Content-Type": "application/x-www-form-urlencoded" },
+ body: `difficulty=${currentDifficulty}&time=${secondsElapsed}`
+ });
+}
+
\ No newline at end of file
diff --git a/leaderboard.php b/leaderboard.php
new file mode 100644
index 0000000..b5f0958
--- /dev/null
+++ b/leaderboard.php
@@ -0,0 +1,74 @@
+query($sql);
+?>
+
+
+
+
+
🏆 Leaderboard
+
+
+
+ | User |
+ Level |
+ Time |
+
+
+ num_rows > 0): ?>
+ fetch_assoc()): ?>
+
+ | = htmlspecialchars($row['username']) ?> |
+ = strtoupper($row['difficulty']) ?> |
+
+ = sprintf(
+ "%02d:%02d",
+ floor($row['time_seconds'] / 60),
+ $row['time_seconds'] % 60
+ ) ?>
+ |
+
+
+
+
+ | Belum ada data |
+
+
+
+
+
+close(); ?>
+
\ No newline at end of file
diff --git a/save_scoee.php b/save_scoee.php
new file mode 100644
index 0000000..7e77f43
--- /dev/null
+++ b/save_scoee.php
@@ -0,0 +1,13 @@
+prepare("INSERT INTO leaderboard_sudoku (username, difficulty, time_seconds) VALUES (?, ?, ?)");
+$stmt->bind_param("ssi", $username, $difficulty, $time);
+$stmt->execute();
diff --git a/sudoku.sql b/sudoku.sql
index 37f3859..ea8b819 100644
--- a/sudoku.sql
+++ b/sudoku.sql
@@ -63,6 +63,15 @@ ALTER TABLE `users`
--
ALTER TABLE `users`
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;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;