leaderboard
This commit is contained in:
parent
6fc5352be1
commit
25f5d864d3
BIN
Background.jpg
Normal file
BIN
Background.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 737 B |
56
Sudoku.php
56
Sudoku.php
@ -5,15 +5,6 @@ if (!isset($_SESSION['username'])) {
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>Sudoku</title>
|
||||
<style>
|
||||
/*CSS kamu tetap sama*/
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<html>
|
||||
<head>
|
||||
<title>Sudoku</title>
|
||||
@ -32,17 +23,15 @@ if (!isset($_SESSION['username'])) {
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Roboto', 'Segoe UI', sans-serif;
|
||||
background-color: var(--bg-color);
|
||||
color: var(--text-color);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
}
|
||||
font-family: 'Roboto', 'Segoe UI', sans-serif;
|
||||
background: url("Background.jpg") no-repeat center center fixed;
|
||||
background-size: cover;
|
||||
color: var(--text-color);
|
||||
margin: 0;
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
|
||||
.screen {
|
||||
display: none;
|
||||
@ -52,7 +41,7 @@ if (!isset($_SESSION['username'])) {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
position: absolute;
|
||||
background-color: var(--bg-color);
|
||||
background-color: transparent;
|
||||
animation: fadeIn 0.3s ease-in-out;
|
||||
}
|
||||
|
||||
@ -385,12 +374,17 @@ if (!isset($_SESSION['username'])) {
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="screen-menu" class="screen active">
|
||||
<img src="Sudoku icon.jpg" alt="Logo" class="logo-img">
|
||||
<div class="app-title">Sudoku</div>
|
||||
|
||||
<button class="btn-main" onclick="showLevelScreen()">Permainan Baru</button>
|
||||
|
||||
<button class="btn-main" onclick="window.location.href='leaderboard.php'">
|
||||
Leaderboard
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id="screen-menu" class="screen active">
|
||||
<img src="Sudoku icon.jpg" alt="Logo" class="logo-img">
|
||||
<div class="app-title">Sudoku</div>
|
||||
<button class="btn-main" onclick="showLevelScreen()">Permainan Baru</button>
|
||||
</div>
|
||||
|
||||
<div id="screen-level" class="screen">
|
||||
<div class="level-title">Pilih Tingkat Kesulitan</div>
|
||||
@ -730,6 +724,7 @@ 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}`
|
||||
});
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
74
leaderboard.php
Normal file
74
leaderboard.php
Normal 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
13
save_scoee.php
Normal 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();
|
||||
@ -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 */;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user