Compare commits
2 Commits
8131f3b8c0
...
ae7eb37ee9
| Author | SHA1 | Date | |
|---|---|---|---|
| ae7eb37ee9 | |||
| 29a80531eb |
@ -4,13 +4,12 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Memory Card Premium</title>
|
<title>Memory Card Premium</title>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
html, body {
|
html, body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
font-family: "Poppins", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;
|
font-family: "Poppins", sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
@ -19,13 +18,12 @@ body {
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Top bar */
|
|
||||||
.topbar {
|
.topbar {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 8px 14px;
|
padding: 8px 14px;
|
||||||
background: rgba(255, 255, 255, 0.45);
|
background: rgb(255, 255, 255);
|
||||||
border-bottom: 2px solid rgba(39, 35, 35, 0.6);
|
border-bottom: 2px solid rgba(39, 35, 35, 0.6);
|
||||||
backdrop-filter: blur(14px);
|
backdrop-filter: blur(14px);
|
||||||
z-index: 50;
|
z-index: 50;
|
||||||
@ -49,7 +47,7 @@ body {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 6px;
|
gap: 6px;
|
||||||
padding: 5px 12px;
|
padding: 5px 12px;
|
||||||
background: rgba(255,255,255,0.45);
|
background: rgb(255, 255, 255);
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
border: 2px solid rgba(255,255,255,0.8);
|
border: 2px solid rgba(255,255,255,0.8);
|
||||||
backdrop-filter: blur(8px);
|
backdrop-filter: blur(8px);
|
||||||
@ -58,22 +56,23 @@ body {
|
|||||||
box-shadow: 0 3px 6px rgba(0,0,0,0.2), inset 0 0 6px rgba(255,255,255,0.6);
|
box-shadow: 0 3px 6px rgba(0,0,0,0.2), inset 0 0 6px rgba(255,255,255,0.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Gameboard */
|
.icon { font-size: 18px; }
|
||||||
|
|
||||||
|
|
||||||
.gameboard {
|
.gameboard {
|
||||||
|
flex: 1;
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(4, 85px); /* 4 kolom */
|
grid-template-columns: repeat(4, 1fr);
|
||||||
grid-template-rows: repeat(3, 105px); /* 3 baris */
|
grid-template-rows: repeat(3, 1fr);
|
||||||
gap: 22px; /* jarak diperbesar */
|
gap: 10px;
|
||||||
justify-content: center;
|
|
||||||
align-content: center;
|
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
margin: auto;
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Card */
|
|
||||||
.card {
|
.card {
|
||||||
width: 85px;
|
width: 100%;
|
||||||
height: 105px;
|
height: 100%;
|
||||||
perspective: 1000px;
|
perspective: 1000px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
@ -102,7 +101,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.front {
|
.front {
|
||||||
font-size: 22px;
|
font-size: calc(10px + 3vw);
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: #ff6a4d;
|
color: #ff6a4d;
|
||||||
}
|
}
|
||||||
@ -118,6 +117,11 @@ body {
|
|||||||
filter: drop-shadow(0 3px 4px rgba(0,0,0,0.45));
|
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.flipped .inner { transform: rotateY(180deg); }
|
||||||
|
|
||||||
.card.matched .front,
|
.card.matched .front,
|
||||||
@ -131,23 +135,21 @@ body {
|
|||||||
|
|
||||||
<header class="topbar">
|
<header class="topbar">
|
||||||
<button class="back-btn" onclick="window.location.href='mainboard.html'">←</button>
|
<button class="back-btn" onclick="window.location.href='mainboard.html'">←</button>
|
||||||
|
|
||||||
<div class="right-info">
|
<div class="right-info">
|
||||||
<div class="pill"><span>⏱</span> <span id="timer">60</span>s</div>
|
<div class="pill"><span class="icon">⏱</span><span id="timer">60</span>s</div>
|
||||||
<div class="pill"><span>⭐</span> <span id="score">0</span></div>
|
<div class="pill"><span class="icon">⭐</span><span id="score">0</span></div>
|
||||||
<div class="pill"><span>🎯</span> <span id="moves">0</span></div>
|
<div class="pill"><span class="icon">🎯</span><span id="moves">0</span></div>
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div id="game-board" class="gameboard"></div>
|
<div id="game-board" class="gameboard"></div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// 6 gambar → total kartu 12 (3x4 pas)
|
|
||||||
const images = [
|
const images = [
|
||||||
"asset/alpukat.jpg",
|
"asset/alpukat.jpg",
|
||||||
"asset/anggur.jpg",
|
"asset/anggur.jpg",
|
||||||
"asset/apel.jpg",
|
"asset/apel.jpg",
|
||||||
"asset/buah_naga.jpg", // pastikan tidak pakai spasi
|
"asset/buah naga.jpg",
|
||||||
"asset/jambu.jpg",
|
"asset/jambu.jpg",
|
||||||
"asset/jeruk.jpg"
|
"asset/jeruk.jpg"
|
||||||
];
|
];
|
||||||
@ -160,12 +162,20 @@ let moves = 0;
|
|||||||
let score = 0;
|
let score = 0;
|
||||||
let countdown;
|
let countdown;
|
||||||
|
|
||||||
|
// Fungsi shuffle (Fisher-Yates)
|
||||||
|
function shuffleArray(array) {
|
||||||
|
for (let i = array.length - 1; i > 0; i--) {
|
||||||
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
|
[array[i], array[j]] = [array[j], array[i]];
|
||||||
|
}
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
function startTimer() {
|
function startTimer() {
|
||||||
timerStarted = true;
|
timerStarted = true;
|
||||||
countdown = setInterval(() => {
|
countdown = setInterval(() => {
|
||||||
document.getElementById("timer").textContent = --time;
|
document.getElementById("timer").textContent = --time;
|
||||||
|
if(time <= 0){
|
||||||
if (time <= 0) {
|
|
||||||
clearInterval(countdown);
|
clearInterval(countdown);
|
||||||
alert("Waktu habis!");
|
alert("Waktu habis!");
|
||||||
document.querySelectorAll(".card").forEach(c => c.classList.add("flipped"));
|
document.querySelectorAll(".card").forEach(c => c.classList.add("flipped"));
|
||||||
@ -173,45 +183,47 @@ function startTimer() {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function flipCard(card) {
|
function flipCard(card){
|
||||||
if (!timerStarted) startTimer();
|
if(!timerStarted) startTimer();
|
||||||
if (flipped.length === 2 || card.classList.contains("matched") || card.classList.contains("flipped"))
|
if(flipped.length === 2 || card.classList.contains("matched") || card.classList.contains("flipped"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
card.classList.add("flipped");
|
card.classList.add("flipped");
|
||||||
flipped.push(card);
|
flipped.push(card);
|
||||||
|
|
||||||
if (flipped.length === 2) {
|
if(flipped.length === 2){
|
||||||
moves++;
|
moves++;
|
||||||
document.getElementById("moves").textContent = moves;
|
document.getElementById("moves").textContent = moves;
|
||||||
|
|
||||||
let img1 = flipped[0].querySelector(".back img").src;
|
let img1 = flipped[0].querySelector(".back img").src;
|
||||||
let img2 = flipped[1].querySelector(".back img").src;
|
let img2 = flipped[1].querySelector(".back img").src;
|
||||||
|
|
||||||
if (img1 === img2) {
|
if(img1 === img2){
|
||||||
flipped.forEach(c => c.classList.add("matched"));
|
flipped.forEach(c => c.classList.add("matched"));
|
||||||
score += 10;
|
score += 10;
|
||||||
document.getElementById("score").textContent = score;
|
document.getElementById("score").textContent = score;
|
||||||
|
|
||||||
time += 5; // bonus waktu
|
time += 5; // tambah 5 detik jika cocok
|
||||||
document.getElementById("timer").textContent = time;
|
document.getElementById("timer").textContent = time;
|
||||||
|
|
||||||
flipped = [];
|
flipped = [];
|
||||||
} else {
|
} else {
|
||||||
setTimeout(() => {
|
setTimeout(()=> {
|
||||||
flipped.forEach(c => c.classList.remove("flipped"));
|
flipped.forEach(c=>c.classList.remove("flipped"));
|
||||||
flipped = [];
|
flipped = [];
|
||||||
}, 800);
|
}, 800);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tidak shuffle → tetap 3x4 urutan kartu
|
function startGame(){
|
||||||
function startGame() {
|
|
||||||
const board = document.getElementById("game-board");
|
const board = document.getElementById("game-board");
|
||||||
board.innerHTML = "";
|
board.innerHTML = "";
|
||||||
|
|
||||||
cards.forEach(image => {
|
// Shuffle kartu sebelum ditampilkan
|
||||||
|
const shuffledCards = shuffleArray([...cards]);
|
||||||
|
|
||||||
|
shuffledCards.forEach(image => {
|
||||||
const card = document.createElement("div");
|
const card = document.createElement("div");
|
||||||
card.className = "card";
|
card.className = "card";
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
@ -220,7 +232,7 @@ function startGame() {
|
|||||||
<div class="back"><img src="${image}"></div>
|
<div class="back"><img src="${image}"></div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
card.onclick = () => flipCard(card);
|
card.onclick = ()=>flipCard(card);
|
||||||
board.appendChild(card);
|
board.appendChild(card);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user