Compare commits

..

No commits in common. "d329da9993ad024154aa9e1ce4a6b65b974d6ea8" and "ec6c46fe118f5303d435afec1370fda323f09ff4" have entirely different histories.

View File

@ -19,8 +19,9 @@ body {
align-items: center; align-items: center;
padding: 8px 14px; padding: 8px 14px;
background: rgba(255, 255, 255, 0.45); background: rgba(255, 255, 255, 0.45);
border-bottom: 2px solid rgba(39, 35, 35, 0.6); border-bottom: 2px solid rgba(255, 255, 255, 0.6);
backdrop-filter: blur(14px); backdrop-filter: blur(14px);
position: sticky; position: sticky;
top: 0; top: 0;
z-index: 50; z-index: 50;
@ -50,6 +51,7 @@ body {
backdrop-filter: blur(8px); backdrop-filter: blur(8px);
color: #003366; color: #003366;
font-weight: 600; font-weight: 600;
box-shadow: box-shadow:
0 3px 6px rgba(0,0,0,0.20), 0 3px 6px rgba(0,0,0,0.20),
inset 0 0 6px rgba(255,255,255,0.6); inset 0 0 6px rgba(255,255,255,0.6);
@ -59,18 +61,18 @@ body {
font-size: 18px; font-size: 18px;
} }
/* GAMEBOARD & CARD */
.gameboard { .gameboard {
display: grid; display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); grid-template-columns: repeat(4, 100px); /* 4 kolom */
gap: 25px; grid-template-rows: repeat(3, 120px); /* 3 baris */
justify-content: center; justify-content: center;
gap: 15px;
margin: 20px auto; margin: 20px auto;
} }
.card { .card {
width: 140px; width: 120px;
height: 180px; height: 140px;
perspective: 1000px; perspective: 1000px;
cursor: pointer; cursor: pointer;
} }
@ -100,7 +102,7 @@ body {
} }
.front { .front {
font-size: 55px; font-size: 45px;
font-weight: 700; font-weight: 700;
color: #ff6a4d; color: #ff6a4d;
} }
@ -110,8 +112,8 @@ body {
} }
.back img { .back img {
max-width: 85%; max-width: 75%;
max-height: 85%; max-height: 75%;
filter: drop-shadow(0 3px 4px rgba(0,0,0,0.45)); filter: drop-shadow(0 3px 4px rgba(0,0,0,0.45));
} }
@ -132,25 +134,15 @@ body {
0 0 30px rgba(122,255,214,0.8); 0 0 30px rgba(122,255,214,0.8);
} }
/* RESPONSIVE */
@media (max-width: 600px) { @media (max-width: 600px) {
.gameboard { .gameboard {
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)); grid-template-columns: repeat(3, 90px);
gap: 15px; gap: 14px;
} }
.card { .card {
width: 100px; width: 90px;
height: 130px; height: 110px;
}
.front {
font-size: 40px;
}
.back img {
max-width: 80%;
max-height: 80%;
} }
} }
</style> </style>
@ -159,6 +151,7 @@ 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 class="icon"></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 class="icon"></span><span id="score">0</span></div> <div class="pill"><span class="icon"></span><span id="score">0</span></div>
@ -169,6 +162,7 @@ body {
<div id="game-board" class="gameboard"></div> <div id="game-board" class="gameboard"></div>
<script> <script>
const images = [ const images = [
"asset/alpukat.jpg", "asset/alpukat.jpg",
"asset/anggur.jpg", "asset/anggur.jpg",
@ -198,8 +192,10 @@ let countdown;
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!");
@ -210,15 +206,20 @@ function startTimer() {
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;
@ -236,19 +237,28 @@ function flipCard(card) {
function startGame() { function startGame() {
const board = document.getElementById("game-board"); const board = document.getElementById("game-board");
board.innerHTML = ""; board.innerHTML = "";
shuffle(cards).forEach(image => { shuffle(cards).forEach(image => {
const card = document.createElement("div"); const card = document.createElement("div");
card.className = "card"; card.className = "card";
card.innerHTML = ` card.innerHTML = `
<div class="inner"> <div class="inner">
<div class="front">?</div> <div class="front">?</div>
<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);
}); });
time = 60; moves = 0; score = 0; flipped = []; timerStarted = false;
time = 60;
moves = 0;
score = 0;
flipped = [];
timerStarted = false;
document.getElementById("timer").textContent = time; document.getElementById("timer").textContent = time;
document.getElementById("moves").textContent = moves; document.getElementById("moves").textContent = moves;
document.getElementById("score").textContent = score; document.getElementById("score").textContent = score;