Compare commits

..

No commits in common. "f2a2345b659ca765c9bcf7e299f356538d2f6cb4" and "3bd80afe30f57eb22d9f6a32e03275399c27c426" have entirely different histories.

View File

@ -1,9 +1,10 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<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</title> <title>Memory Card</title>
<style> <style>
body { body {
margin: 0; margin: 0;
@ -20,13 +21,14 @@ body {
align-items: center; align-items: center;
padding: 6px 10px; padding: 6px 10px;
width: 100%; width: 100%;
background: rgba(255, 255, 255, 0.6); background: rgb(255, 255, 255);
backdrop-filter: blur(14px); backdrop-filter: blur white(14px);
border-top: 2px solid rgba(255, 255, 255, 0.4); border-top: 2px solid rgba(255, 255, 255, 0.4);
border-bottom: 2px solid rgba(255, 255, 255, 0.4); border-bottom: 2px solid rgba(255, 255, 255, 0.4);
box-sizing: border-box; box-sizing: border-box;
} }
.back-btn { .back-btn {
background: none; background: none;
border: none; border: none;
@ -36,11 +38,13 @@ body {
padding-left: 6px; padding-left: 6px;
} }
.right-info { .right-info {
display: flex; display: flex;
gap: 10px; gap: 10px;
} }
.pill { .pill {
display: flex; display: flex;
align-items: center; align-items: center;
@ -53,89 +57,42 @@ body {
font-size: 16px; font-size: 16px;
color: #002a60; color: #002a60;
box-shadow: 0 2px 4px rgba(0,0,0,0.15), box-shadow: 0 2px 4px rgba(0,0,0,0.15),
inset 0 0 4px rgba(255,255,255,0.5); inset 0 0 4px rgba(255,255,255,0.5);
} }
.icon { .icon {
font-size: 18px; font-size: 18px;
} }
.gameboard {
display: grid;
grid-template-columns: repeat(5, 100px);
justify-content: center;
gap: 15px;
margin: 20px auto;
}
.card {
width: 100px;
height: 120px;
perspective: 1000px;
cursor: pointer;
}
.inner {
width: 100%;
height: 100%;
position: relative;
transform-style: preserve-3d;
transition: transform 0.5s;
}
.front, .back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
border-radius: 10px;
background: rgba(255,255,255,0.8);
}
.back {
transform: rotateY(180deg);
}
.card.flipped .inner {
transform: rotateY(180deg);
}
.back img {
max-width: 70%;
max-height: 70%;
}
</style> </style>
</head> </head>
<body> <body>
<div id="container"> <div id = "container">
<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"> <div class="pill">
<span class="icon"></span> <span id="timer">60</span>s <span class="icon"></span> <span id="timer">60</span>s
</div> </div>
<div class="pill" id="score"> <div class="pill" id="score">
<span class="icon"></span> 0 <span class="icon"></span> 0
</div> </div>
<div class="pill" id="move-count"> <div class="pill" id="move-count">
<span class="icon">🎯</span> 0 <span class="icon">🎯</span> 0
</div> </div>
</div> </div>
</header> </header>
<div id="game-board" class="gameboard"> <div class="gameboard">
</div>
</div> </div>
</div>
<script> <script>
const imageList = [ const imageList = [
"alpukat.jpg", "alpukat.jpg",
"anggur.jpg", "anggur.jpg",
"apel.jpg", "apel.jpg",
@ -148,11 +105,12 @@ const imageList = [
"semangka.jpg" "semangka.jpg"
]; ];
let images = [...imageList, ...imageList]; let images = [...imageList, ...imageList]; // double for pairs
// SHUFFLE FUNCTION
function shuffle(array) { function shuffle(array) {
let currentIndex = array.length, randomIndex; let currentIndex = array.length, randomIndex;
while (currentIndex !== 0) { while (currentIndex !== 0) {
randomIndex = Math.floor(Math.random() * currentIndex); randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--; currentIndex--;
@ -161,7 +119,7 @@ function shuffle(array) {
return array; return array;
} }
// VARIABLES
let time = 60; let time = 60;
let timerElement = document.getElementById("timer"); let timerElement = document.getElementById("timer");
let movesElement = document.getElementById("move-count"); let movesElement = document.getElementById("move-count");
@ -172,6 +130,7 @@ let moves = 0;
let score = 0; let score = 0;
let flippedCards = []; let flippedCards = [];
// TIMER
function startTimer() { function startTimer() {
if (timerStarted) return; if (timerStarted) return;
timerStarted = true; timerStarted = true;
@ -179,6 +138,7 @@ function startTimer() {
countdown = setInterval(() => { countdown = setInterval(() => {
time--; time--;
timerElement.textContent = time; timerElement.textContent = time;
if (time <= 0) { if (time <= 0) {
clearInterval(countdown); clearInterval(countdown);
alert("Waktu Habis!"); alert("Waktu Habis!");
@ -187,6 +147,7 @@ function startTimer() {
}, 1000); }, 1000);
} }
// FLIP CARD FUNCTION
function flipCard(card) { function flipCard(card) {
if (!timerStarted) startTimer(); if (!timerStarted) startTimer();
@ -217,6 +178,7 @@ function flipCard(card) {
} }
} }
// START GAME
function startGame() { function startGame() {
const board = document.getElementById("game-board"); const board = document.getElementById("game-board");
board.innerHTML = ""; board.innerHTML = "";
@ -238,7 +200,7 @@ function startGame() {
board.appendChild(card); board.appendChild(card);
}); });
// reset stats
time = 60; time = 60;
timerElement.textContent = time; timerElement.textContent = time;
timerStarted = false; timerStarted = false;
@ -248,8 +210,8 @@ function startGame() {
scoreElement.textContent = score; scoreElement.textContent = score;
} }
startGame(); startGame();
</script> </script>
</body> </body>
</html> </html>