diff --git a/assets/gameboard-easy.js b/assets/gameboard-easy.js index c1d6ae8..757c8f5 100644 --- a/assets/gameboard-easy.js +++ b/assets/gameboard-easy.js @@ -18,7 +18,6 @@ function playSFX(audio) { } } -// Interaksi pertama untuk aktifkan suara document.addEventListener('click', function initAudio() { if(musicMuted) { musicMuted = false; @@ -41,9 +40,7 @@ toggleBtn.onclick = (e) => { }; // --- GAME LOGIC --- -// UBAHAN DISINI: Hanya pakai 6 Gambar (Fruit 1-6) -// 6 Gambar x 2 = 12 Kartu. -// Karena CSS kamu 4 kolom, maka otomatis jadi: 4 Samping x 3 Bawah. + const images = [ "images/fruit1.png", "images/fruit2.png", "images/fruit3.png", "images/fruit4.png", "images/fruit5.png", "images/fruit6.png" @@ -52,7 +49,7 @@ const images = [ let cards = [...images, ...images]; let flipped = []; let timerStarted = false; -let time = 60; +let time = 60; let moves = 0; let score = 0; let countdown; @@ -142,6 +139,20 @@ function showEndScreen(isWin) { document.getElementById("moveBonusEnd").textContent = "+" + moveBonus; document.getElementById("totalScoreEnd").textContent = total; document.getElementById("endScreen").style.display = "flex"; + + + if (isWin) { + let formData = new FormData(); + formData.append('score', total); + formData.append('difficulty', 'Easy'); + fetch('score.php', { + method: 'POST', + body: formData + }) + .then(response => response.text()) + .then(result => console.log("Status Database: " + result)) + .catch(error => console.error('Error:', error)); + } } function flipCard(card) { @@ -205,7 +216,9 @@ function startGame() { card.onclick = () => flipCard(card); board.appendChild(card); }); - time = 60; moves = 0; score = 0; combo = 1; + + time = 60; + moves = 0; score = 0; combo = 1; pendingMatch = false; flipped = []; timerStarted = false; document.getElementById("timer").textContent = time; document.getElementById("moves").textContent = moves; diff --git a/score.php b/score.php index e5d6264..6bf507b 100644 --- a/score.php +++ b/score.php @@ -1,45 +1,24 @@ >>>>>> 43b6ab58ae77611b561af08efaf30f5d542b0ebc $score = intval($_POST['score']); + $difficulty = $_POST['difficulty']; - // Masukkan ke database - $stmt = $conn->prepare("INSERT INTO scores (user_id, score) VALUES (?, ?)"); - $stmt->bind_param("ii", $user_id, $score); + $stmt = $conn->prepare("INSERT INTO scores (user_id, score, difficulty) VALUES (?, ?, ?)"); + + $stmt->bind_param("iis", $user_id, $score, $difficulty); if ($stmt->execute()) { -<<<<<<< HEAD - echo "Berhasil simpan skor untuk ID: " . $user_id; + echo "Sukses! Skor $score ($difficulty) tersimpan."; } else { echo "Gagal: " . $conn->error; } } else { - echo "Error: Belum login atau Data Session tidak sesuai."; -======= - echo "Berhasil"; - } else { - echo "Gagal"; - } ->>>>>>> 43b6ab58ae77611b561af08efaf30f5d542b0ebc + echo "Error: Data tidak lengkap."; } ?> \ No newline at end of file