diff --git a/GameLogic.js b/GameLogic.js
index e0f89f9..6c4f085 100644
--- a/GameLogic.js
+++ b/GameLogic.js
@@ -234,29 +234,53 @@ function PenambahanTembok() {
}
}
-//set dan update score
-function UpdateScore(amount) {
- score = amount > 0 ? score + amount : 0;
- highscore = score > highscore ? score : highscore;
-
- Text.innerHTML =
- "Score: " + score + "
Highscore: " + highscore + "
Speed: " + speed;
+ //set dan update score
+ function UpdateScore(amount) {
+ score = amount > 0 ? score + amount : 0;
+ console.log("UPDATE SCORE , score:",score);
+ highscore = score > highscore ? score : highscore;
+ Text.innerHTML =
+ "Score: " +
+ score +
+ "
Highscore: " +
+ highscore +
+ "
Speed: " +
+ speed;
PenambahanTembok();
}
-//tampilin gameover
-function GameOver() {
- GameStart = false;
- ClearCanvas();
+ //tampilin gameover
+ function GameOver() {
+ GameStart = false;
+ ClearCanvas();
+
+ // Simpan score ke database
+ saveScore(score);
- const GameMode = ModeH ? "Tambahan" : "Normal";
- if (score > 0) {
- }
-
- ScoreMain.innerHTML = "Score: " + score;
- UpDead.style.display = "flex";
-}
+ // TAMPILKAN POP-UP GAME OVER
+ ScoreMain.innerHTML = "Score: " + score;
+ UpDead.style.display = "flex";
+ }
+
+ //fungsi untuk menyimpan score ke database
+ function saveScore(finalScore) {
+ console.log("SAVING SCORE , score:",finalScore);
+ // Buat form tersembunyi untuk submit score
+ var form = document.createElement('form');
+ form.method = 'POST';
+ form.action = 'simpan_score.php';
+ form.style.display = 'none';
+
+ var scoreInput = document.createElement('input');
+ scoreInput.type = 'hidden';
+ scoreInput.name = 'score';
+ scoreInput.value = finalScore;
+
+ form.appendChild(scoreInput);
+ document.body.appendChild(form);
+ form.submit();
+ }
//reset isi canvas doang
function ClearCanvas() {
diff --git a/api_score.php b/api_score.php
new file mode 100644
index 0000000..7f418b0
--- /dev/null
+++ b/api_score.php
@@ -0,0 +1,28 @@
+ true, 'message' => 'Score saved', 'score' => $score]);
+ } else {
+ echo json_encode(['success' => false, 'message' => 'Database error']);
+ }
+ } else {
+ echo json_encode(['success' => false, 'message' => 'Invalid data']);
+ }
+} else {
+ echo json_encode(['success' => false, 'message' => 'Method not allowed']);
+}
+?>
\ No newline at end of file
diff --git a/game.php b/game.php
new file mode 100644
index 0000000..380f295
--- /dev/null
+++ b/game.php
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Start Game?
+
Silakan Pilih Mode
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/index.php b/index.php
index 8273ac7..165f425 100644
--- a/index.php
+++ b/index.php
@@ -1,8 +1,9 @@
@@ -57,23 +58,23 @@ if(!isset($_SESSION['users'])) {
Logout -->
- Selamat datang,
+ Selamat datang,
diff --git a/leaderboard.php b/leaderboard.php
index 0262f84..0964813 100644
--- a/leaderboard.php
+++ b/leaderboard.php
@@ -1,22 +1,22 @@
0) {
$row = mysqli_fetch_assoc($resultMe);
- $score = $row['score'];
+ $score = (int)$row['score'];
}
}
@@ -24,7 +24,7 @@ $sql = "SELECT username, score FROM users ORDER BY score DESC LIMIT 10";
$result = mysqli_query($koneksi, $sql);
$leaderboard = [];
-if($result) {
+if($result && mysqli_num_rows($result) > 0) {
$leaderboard = mysqli_fetch_all($result, MYSQLI_ASSOC);
}
?>
@@ -57,7 +57,7 @@ if($result) {
@@ -65,7 +65,7 @@ if($result) {
|
|
- PTS |
+ PTS |
diff --git a/login.php b/login.php
index 1472553..1f4bab8 100644
--- a/login.php
+++ b/login.php
@@ -11,7 +11,7 @@ if(isset($_POST['username'])) {
if(mysqli_num_rows($query) > 0) {
$data = mysqli_fetch_array($query);
$_SESSION['users'] = $data;
- $_SESSION['username'] = $data = ['username'];
+ $_SESSION['username'] = $data['username'];
echo '';
} else {
echo '';
diff --git a/save_score.php b/save_score.php
new file mode 100644
index 0000000..10e184e
--- /dev/null
+++ b/save_score.php
@@ -0,0 +1,38 @@
+ false, 'message' => 'User not logged in']);
+ exit;
+ }
+
+ $username = $_SESSION['users']['username'];
+
+ // Update score jika lebih tinggi dari score sebelumnya
+ $sql = "UPDATE users SET score = ? WHERE username = ? AND score < ?";
+ $stmt = mysqli_prepare($koneksi, $sql);
+
+ if ($stmt) {
+ mysqli_stmt_bind_param($stmt, "isi", $score, $username, $score);
+ mysqli_stmt_execute($stmt);
+
+ if (mysqli_stmt_affected_rows($stmt) > 0) {
+ echo json_encode(['success' => true, 'message' => 'Score updated']);
+ } else {
+ echo json_encode(['success' => false, 'message' => 'Score not higher than current']);
+ }
+ mysqli_stmt_close($stmt);
+ } else {
+ echo json_encode(['success' => false, 'message' => 'Database error']);
+ }
+} else {
+ echo json_encode(['success' => false, 'message' => 'Invalid request method']);
+}
+?>
\ No newline at end of file
diff --git a/simpan_score.php b/simpan_score.php
new file mode 100644
index 0000000..0429b91
--- /dev/null
+++ b/simpan_score.php
@@ -0,0 +1,19 @@
+console.log('Score $score tersimpan untuk $username');";
+ }
+}
+
+// Redirect kembali ke game
+echo "";
+?>
\ No newline at end of file
diff --git a/users.sql b/users (2).sql
similarity index 73%
rename from users.sql
rename to users (2).sql
index 2ff7650..42bd7a2 100644
--- a/users.sql
+++ b/users (2).sql
@@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Host: localhost:3306
--- Generation Time: Dec 03, 2025 at 05:17 AM
+-- Generation Time: Dec 14, 2025 at 08:58 AM
-- Server version: 8.0.30
-- PHP Version: 8.1.10
@@ -32,7 +32,7 @@ CREATE TABLE `users` (
`nama` varchar(255) DEFAULT NULL,
`username` varchar(225) DEFAULT NULL,
`password` varchar(255) DEFAULT NULL,
- `score` int NOT NULL
+ `score` int NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
--
@@ -41,7 +41,13 @@ CREATE TABLE `users` (
INSERT INTO `users` (`id_user`, `nama`, `username`, `password`, `score`) VALUES
(1, 'Chris Daud Koroh', 'daudkoroh', '88d602f1ad6d62b9a11c688ab47fed22', 20),
-(2, 'Zefanya Isaac', 'zefanya', 'de413c0365e3c88d8b3315f9d90b98ae', 68);
+(2, 'Zefanya Isaac', 'zefanya', 'de413c0365e3c88d8b3315f9d90b98ae', 68),
+(4, 'ygygyg', 'yatim', 'c929fedbfce1bdc014ed835a0cdf35f4', 0),
+(5, 'hentai', 'untung', '25f9e794323b453885f5181f1b624d0b', 0),
+(6, 'kepin', 'kepin', '202cb962ac59075b964b07152d234b70', 0),
+(8, 'ayam', 'ayam', '202cb962ac59075b964b07152d234b70', 2),
+(9, 'ayam2', 'ayam2', '289dff07669d7a23de0ef88d2f7129e7', 35),
+(10, 'terserah', 'terserah', '698d51a19d8a121ce581499d7b701668', 12);
--
-- Indexes for dumped tables
@@ -61,7 +67,7 @@ ALTER TABLE `users`
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
- MODIFY `id_user` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
+ MODIFY `id_user` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
COMMIT;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;