Kelompok02-Memory-Card/gameboard-easy.html

244 lines
5.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Memory Card Premium</title>
<style>
html, body {
margin: 0;
height: 100%;
overflow: hidden; /* hilangkan scroll */
font-family: "Poppins", sans-serif;
}
body {
background: linear-gradient(135deg, #8929ff 30%, #ff419b 100%);
display: flex;
flex-direction: column;
}
/* Top bar */
.topbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 8px 14px;
background: rgba(255, 255, 255, 0.45);
border-bottom: 2px solid rgba(39, 35, 35, 0.6);
backdrop-filter: blur(14px);
z-index: 50;
}
.back-btn {
font-size: 28px;
background: none;
border: none;
cursor: pointer;
color: #222;
}
.right-info {
display: flex;
gap: 10px;
}
.pill {
display: flex;
align-items: center;
gap: 6px;
padding: 5px 12px;
background: rgba(255,255,255,0.45);
border-radius: 20px;
border: 2px solid rgba(255,255,255,0.8);
backdrop-filter: blur(8px);
color: #003366;
font-weight: 600;
box-shadow: 0 3px 6px rgba(0,0,0,0.2), inset 0 0 6px rgba(255,255,255,0.6);
}
.icon { font-size: 18px; }
/* Gameboard */
.gameboard {
flex: 1;
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-template-rows: repeat(3, 1fr);
gap: 10px;
padding: 10px;
box-sizing: border-box;
}
/* Card */
.card {
width: 100%;
height: 100%;
perspective: 1000px;
cursor: pointer;
}
.inner {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
transition: transform 0.55s ease;
border-radius: 12px;
}
.front, .back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
display: flex;
justify-content: center;
align-items: center;
border-radius: 12px;
background: linear-gradient(135deg, #7a28ff 20%, #eb2bbf 80%);
border: 2px solid rgba(255,255,255,0.55);
box-shadow: 0 3px 6px rgba(0,0,0,0.25), inset 0 0 6px rgba(255,255,255,0.45);
}
.front {
font-size: calc(10px + 3vw);
font-weight: 700;
color: #ff6a4d;
}
.back {
transform: rotateY(180deg);
}
.back img {
width: 90%;
height: 90%;
object-fit: contain;
filter: drop-shadow(0 3px 4px rgba(0,0,0,0.45));
}
.card:not(.flipped):hover .front {
transform: scale(1.05);
transition: 0.25s;
}
.card.flipped .inner { transform: rotateY(180deg); }
.card.matched .front,
.card.matched .back {
border-color: #7affd6;
box-shadow: 0 0 15px #7affd6, 0 0 30px rgba(122,255,214,0.8);
}
</style>
</head>
<body>
<header class="topbar">
<button class="back-btn" onclick="window.location.href='mainboard.html'"></button>
<div class="right-info">
<div class="pill"><span class="icon"></span><span id="timer">60</span>s</div>
<div class="pill"><span class="icon"></span><span id="score">0</span></div>
<div class="pill"><span class="icon">🎯</span><span id="moves">0</span></div>
</div>
</header>
<div id="game-board" class="gameboard"></div>
<script>
const images = [
"asset/alpukat.jpg",
"asset/anggur.jpg",
"asset/apel.jpg",
"asset/buah naga.jpg",
"asset/jambu.jpg",
"asset/jeruk.jpg"
];
let cards = [...images, ...images];
let flipped = [];
let timerStarted = false;
let time = 60;
let moves = 0;
let score = 0;
let countdown;
function startTimer() {
timerStarted = true;
countdown = setInterval(() => {
document.getElementById("timer").textContent = --time;
if(time <= 0){
clearInterval(countdown);
alert("Waktu habis!");
document.querySelectorAll(".card").forEach(c => c.classList.add("flipped"));
}
}, 1000);
}
function flipCard(card){
if(!timerStarted) startTimer();
if(flipped.length === 2 || card.classList.contains("matched") || card.classList.contains("flipped"))
return;
card.classList.add("flipped");
flipped.push(card);
if(flipped.length === 2){
moves++;
document.getElementById("moves").textContent = moves;
let img1 = flipped[0].querySelector(".back img").src;
let img2 = flipped[1].querySelector(".back img").src;
if(img1 === img2){
flipped.forEach(c => c.classList.add("matched"));
score += 10;
document.getElementById("score").textContent = score;
time += 5; // tambah 5 detik jika cocok
document.getElementById("timer").textContent = time;
flipped = [];
} else {
setTimeout(()=>{
flipped.forEach(c=>c.classList.remove("flipped"));
flipped = [];
}, 800);
}
}
}
function startGame(){
const board = document.getElementById("game-board");
board.innerHTML = "";
// tetap urutan (tidak shuffle)
cards.forEach(image => {
const card = document.createElement("div");
card.className = "card";
card.innerHTML = `
<div class="inner">
<div class="front">?</div>
<div class="back"><img src="${image}"></div>
</div>
`;
card.onclick = ()=>flipCard(card);
board.appendChild(card);
});
time = 60;
moves = 0;
score = 0;
flipped = [];
timerStarted = false;
document.getElementById("timer").textContent = time;
document.getElementById("moves").textContent = moves;
document.getElementById("score").textContent = score;
}
startGame();
</script>
</body>
</html>