adding score
This commit is contained in:
parent
8f5b89a32e
commit
43b6ab58ae
@ -99,6 +99,7 @@ function startTimer() {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- FUNGSI END SCREEN (YANG DI-UPDATE) ---
|
||||||
function showEndScreen(isWin) {
|
function showEndScreen(isWin) {
|
||||||
clearInterval(countdown);
|
clearInterval(countdown);
|
||||||
bgMusic.pause();
|
bgMusic.pause();
|
||||||
@ -117,6 +118,24 @@ function showEndScreen(isWin) {
|
|||||||
document.getElementById("timeBonusEnd").textContent = "+" + (isWin ? timeBonus : 0);
|
document.getElementById("timeBonusEnd").textContent = "+" + (isWin ? timeBonus : 0);
|
||||||
document.getElementById("moveBonusEnd").textContent = "+" + (isWin ? moveBonus : 0);
|
document.getElementById("moveBonusEnd").textContent = "+" + (isWin ? moveBonus : 0);
|
||||||
document.getElementById("totalScoreEnd").textContent = isWin ? total : baseScore;
|
document.getElementById("totalScoreEnd").textContent = isWin ? total : baseScore;
|
||||||
|
|
||||||
|
// --- KIRIM SCORE KE DATABASE ---
|
||||||
|
if (isWin) {
|
||||||
|
// Bungkus data score
|
||||||
|
let formData = new FormData();
|
||||||
|
formData.append('score', total);
|
||||||
|
|
||||||
|
// Kirim ke score.php (tanpa reload halaman)
|
||||||
|
fetch('score.php', {
|
||||||
|
method: 'POST',
|
||||||
|
body: formData
|
||||||
|
})
|
||||||
|
.then(response => response.text())
|
||||||
|
.then(result => console.log("Status Simpan Score: " + result))
|
||||||
|
.catch(error => console.error('Error:', error));
|
||||||
|
}
|
||||||
|
// ------------------------------
|
||||||
|
|
||||||
document.getElementById("endScreen").style.display = "flex";
|
document.getElementById("endScreen").style.display = "flex";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
20
score.php
Normal file
20
score.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
include 'Config.php'; // Sambungkan ke database
|
||||||
|
|
||||||
|
if (isset($_SESSION['user_id']) && isset($_POST['score'])) {
|
||||||
|
|
||||||
|
$user_id = $_SESSION['user_id'];
|
||||||
|
$score = intval($_POST['score']);
|
||||||
|
|
||||||
|
// Masukkan ke database
|
||||||
|
$stmt = $conn->prepare("INSERT INTO scores (user_id, score) VALUES (?, ?)");
|
||||||
|
$stmt->bind_param("ii", $user_id, $score);
|
||||||
|
|
||||||
|
if ($stmt->execute()) {
|
||||||
|
echo "Berhasil";
|
||||||
|
} else {
|
||||||
|
echo "Gagal";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
?>
|
||||||
Loading…
x
Reference in New Issue
Block a user