Merge branch 'main' of https://git-eng.ukwms.ac.id/2526-web/Kelompok02-Memory-Card
This commit is contained in:
commit
5fbb8a2431
@ -3,14 +3,13 @@
|
|||||||
<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 Premium</title>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
background: linear-gradient(135deg, #8929ff 30%, #ff419b 100%);
|
||||||
background: linear-gradient(135deg, #8a2be2 40%, #f11997 100%);
|
|
||||||
background-attachment: fixed;
|
background-attachment: fixed;
|
||||||
background-size: cover;
|
|
||||||
font-family: "Poppins", sans-serif;
|
font-family: "Poppins", sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,22 +17,23 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 6px 10px;
|
padding: 8px 14px;
|
||||||
width: 100%;
|
|
||||||
background: rgba(255, 255, 255, 0.6);
|
background: rgba(255, 255, 255, 0.45);
|
||||||
|
border-bottom: 2px solid rgba(255, 255, 255, 0.6);
|
||||||
backdrop-filter: blur(14px);
|
backdrop-filter: blur(14px);
|
||||||
border-top: 2px solid rgba(255, 255, 255, 0.4);
|
|
||||||
border-bottom: 2px solid rgba(255, 255, 255, 0.4);
|
position: sticky;
|
||||||
box-sizing: border-box;
|
top: 0;
|
||||||
|
z-index: 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
.back-btn {
|
.back-btn {
|
||||||
|
font-size: 28px;
|
||||||
background: none;
|
background: none;
|
||||||
border: none;
|
border: none;
|
||||||
font-size: 26px;
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: #1a1a1a;
|
color: #222;
|
||||||
padding-left: 6px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.right-info {
|
.right-info {
|
||||||
@ -44,33 +44,36 @@ body {
|
|||||||
.pill {
|
.pill {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 5px;
|
gap: 6px;
|
||||||
padding: 4px 10px;
|
padding: 5px 12px;
|
||||||
|
background: rgba(255,255,255,0.45);
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
background: rgba(173, 216, 255, 0.45);
|
border: 2px solid rgba(255,255,255,0.8);
|
||||||
backdrop-filter: blur(10px);
|
backdrop-filter: blur(8px);
|
||||||
border: 1.8px solid rgba(255, 255, 255, 0.8);
|
color: #003366;
|
||||||
font-size: 16px;
|
font-weight: 600;
|
||||||
color: #002a60;
|
|
||||||
box-shadow: 0 2px 4px rgba(0,0,0,0.15),
|
box-shadow:
|
||||||
inset 0 0 4px rgba(255,255,255,0.5);
|
0 3px 6px rgba(0,0,0,0.20),
|
||||||
|
inset 0 0 6px rgba(255,255,255,0.6);
|
||||||
}
|
}
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
.gameboard {
|
.gameboard {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: repeat(5, 100px);
|
grid-template-columns: repeat(5, 120px);
|
||||||
|
gap: 18px;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
gap: 15px;
|
margin: 30px auto;
|
||||||
margin: 20px auto;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.card {
|
.card {
|
||||||
width: 100px;
|
width: 120px;
|
||||||
height: 120px;
|
height: 140px;
|
||||||
perspective: 1000px;
|
perspective: 1000px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
@ -80,7 +83,7 @@ body {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
position: relative;
|
position: relative;
|
||||||
transform-style: preserve-3d;
|
transform-style: preserve-3d;
|
||||||
transition: transform 0.5s;
|
transition: transform 0.55s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.front, .back {
|
.front, .back {
|
||||||
@ -91,165 +94,184 @@ body {
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
font-size: 24px;
|
border-radius: 18px;
|
||||||
border-radius: 10px;
|
background: linear-gradient(135deg, #7a28ff 20%, #eb2bbf 80%);
|
||||||
background: rgba(255,255,255,0.8);
|
border: 3px solid rgba(255,255,255,0.55);
|
||||||
|
box-shadow:
|
||||||
|
0 5px 12px rgba(0,0,0,0.25),
|
||||||
|
inset 0 0 12px rgba(255,255,255,0.45);
|
||||||
|
}
|
||||||
|
|
||||||
|
.front {
|
||||||
|
font-size: 45px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: #ff6a4d;
|
||||||
}
|
}
|
||||||
|
|
||||||
.back {
|
.back {
|
||||||
transform: rotateY(180deg);
|
transform: rotateY(180deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.back img {
|
||||||
|
max-width: 75%;
|
||||||
|
max-height: 75%;
|
||||||
|
filter: drop-shadow(0 3px 4px rgba(0,0,0,0.45));
|
||||||
|
}
|
||||||
|
|
||||||
|
/* HOVER EFFECT */
|
||||||
|
.card:not(.flipped):hover .front {
|
||||||
|
transform: scale(1.05);
|
||||||
|
transition: 0.25s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* FLIP ANIMATION */
|
||||||
.card.flipped .inner {
|
.card.flipped .inner {
|
||||||
transform: rotateY(180deg);
|
transform: rotateY(180deg);
|
||||||
}
|
}
|
||||||
|
|
||||||
.back img {
|
/* MATCHED GLOW */
|
||||||
max-width: 70%;
|
.card.matched .front,
|
||||||
max-height: 70%;
|
.card.matched .back {
|
||||||
|
border-color: #7affd6;
|
||||||
|
box-shadow:
|
||||||
|
0 0 15px #7affd6,
|
||||||
|
0 0 30px rgba(122,255,214,0.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
.gameboard {
|
||||||
|
grid-template-columns: repeat(4, 90px);
|
||||||
|
gap: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
width: 90px;
|
||||||
|
height: 110px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="container">
|
|
||||||
<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" id="score">
|
<header class="topbar">
|
||||||
<span class="icon">⭐</span> 0
|
<button class="back-btn" onclick="history.back()">←</button>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="pill" id="move-count">
|
<div class="right-info">
|
||||||
<span class="icon">🎯</span> 0
|
<div class="pill"><span class="icon">⏱</span><span id="timer">60</span>s</div>
|
||||||
</div>
|
<div class="pill"><span class="icon">⭐</span><span id="score">0</span></div>
|
||||||
</div>
|
<div class="pill"><span class="icon">🎯</span><span id="moves">0</span></div>
|
||||||
</header>
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
<div id="game-board" class="gameboard">
|
<div id="game-board" class="gameboard"></div>
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const imageList = [
|
const images = [
|
||||||
"alpukat.jpg",
|
"alpukat.jpg", "anggur.jpg", "apel.jpg", "buah naga.jpg", "jambu.jpg",
|
||||||
"anggur.jpg",
|
"jeruk.jpg", "lemon.jpg", "nanas.jpg", "pisang.jpg", "semangka.jpg"
|
||||||
"apel.jpg",
|
|
||||||
"buah naga.jpg",
|
|
||||||
"jambu.jpg",
|
|
||||||
"jeruk.jpg",
|
|
||||||
"lemon.jpg",
|
|
||||||
"nanas.jpg",
|
|
||||||
"pisang.jpg",
|
|
||||||
"semangka.jpg"
|
|
||||||
];
|
];
|
||||||
|
|
||||||
let images = [...imageList, ...imageList];
|
let cards = [...images, ...images];
|
||||||
|
|
||||||
|
function shuffle(arr) {
|
||||||
function shuffle(array) {
|
let i = arr.length, j;
|
||||||
let currentIndex = array.length, randomIndex;
|
while (i > 0) {
|
||||||
while (currentIndex !== 0) {
|
j = Math.floor(Math.random() * i--);
|
||||||
randomIndex = Math.floor(Math.random() * currentIndex);
|
[arr[i], arr[j]] = [arr[j], arr[i]];
|
||||||
currentIndex--;
|
}
|
||||||
[array[currentIndex], array[randomIndex]] = [array[randomIndex], array[currentIndex]];
|
return arr;
|
||||||
}
|
|
||||||
return array;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let flipped = [];
|
||||||
let time = 60;
|
|
||||||
let timerElement = document.getElementById("timer");
|
|
||||||
let movesElement = document.getElementById("move-count");
|
|
||||||
let scoreElement = document.getElementById("score");
|
|
||||||
let timerStarted = false;
|
let timerStarted = false;
|
||||||
let countdown;
|
let time = 60;
|
||||||
let moves = 0;
|
let moves = 0;
|
||||||
let score = 0;
|
let score = 0;
|
||||||
let flippedCards = [];
|
let countdown;
|
||||||
|
|
||||||
|
/* ========================
|
||||||
|
START TIMER
|
||||||
|
======================== */
|
||||||
function startTimer() {
|
function startTimer() {
|
||||||
if (timerStarted) return;
|
timerStarted = true;
|
||||||
timerStarted = true;
|
|
||||||
|
|
||||||
countdown = setInterval(() => {
|
countdown = setInterval(() => {
|
||||||
time--;
|
document.getElementById("timer").textContent = --time;
|
||||||
timerElement.textContent = time;
|
|
||||||
if (time <= 0) {
|
|
||||||
clearInterval(countdown);
|
|
||||||
alert("Waktu Habis!");
|
|
||||||
document.querySelectorAll(".card").forEach(card => card.classList.add("flipped"));
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
function flipCard(card) {
|
if (time <= 0) {
|
||||||
if (!timerStarted) startTimer();
|
clearInterval(countdown);
|
||||||
|
alert("Waktu habis!");
|
||||||
if (flippedCards.length >= 2 || card.classList.contains("matched") || flippedCards.includes(card)) return;
|
document.querySelectorAll(".card").forEach(c => c.classList.add("flipped"));
|
||||||
|
|
||||||
card.classList.add("flipped");
|
|
||||||
flippedCards.push(card);
|
|
||||||
|
|
||||||
if (flippedCards.length === 2) {
|
|
||||||
moves++;
|
|
||||||
movesElement.textContent = moves;
|
|
||||||
|
|
||||||
const firstImg = flippedCards[0].querySelector(".back img").src;
|
|
||||||
const secondImg = flippedCards[1].querySelector(".back img").src;
|
|
||||||
|
|
||||||
if (firstImg === secondImg) {
|
|
||||||
flippedCards[0].classList.add("matched");
|
|
||||||
flippedCards[1].classList.add("matched");
|
|
||||||
score += 10;
|
|
||||||
scoreElement.textContent = score;
|
|
||||||
flippedCards = [];
|
|
||||||
} else {
|
|
||||||
setTimeout(() => {
|
|
||||||
flippedCards.forEach(c => c.classList.remove("flipped"));
|
|
||||||
flippedCards = [];
|
|
||||||
}, 800);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ========================
|
||||||
|
FLIP LOGIC
|
||||||
|
======================== */
|
||||||
|
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;
|
||||||
|
flipped = [];
|
||||||
|
} else {
|
||||||
|
setTimeout(() => {
|
||||||
|
flipped.forEach(c => c.classList.remove("flipped"));
|
||||||
|
flipped = [];
|
||||||
|
}, 800);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function startGame() {
|
function startGame() {
|
||||||
const board = document.getElementById("game-board");
|
const board = document.getElementById("game-board");
|
||||||
board.innerHTML = "";
|
board.innerHTML = "";
|
||||||
|
|
||||||
const shuffled = shuffle([...images]);
|
shuffle(cards).forEach(image => {
|
||||||
|
const card = document.createElement("div");
|
||||||
|
card.className = "card";
|
||||||
|
|
||||||
shuffled.forEach(img => {
|
card.innerHTML = `
|
||||||
const card = document.createElement("div");
|
<div class="inner">
|
||||||
card.classList.add("card");
|
<div class="front">?</div>
|
||||||
|
<div class="back"><img src="${image}"></div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
card.innerHTML = `
|
card.onclick = () => flipCard(card);
|
||||||
<div class="inner">
|
board.appendChild(card);
|
||||||
<div class="front">?</div>
|
});
|
||||||
<div class="back"><img src="${img}"></div>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
|
|
||||||
card.onclick = () => flipCard(card);
|
time = 60;
|
||||||
board.appendChild(card);
|
moves = 0;
|
||||||
});
|
score = 0;
|
||||||
|
flipped = [];
|
||||||
|
timerStarted = false;
|
||||||
|
|
||||||
|
document.getElementById("timer").textContent = time;
|
||||||
time = 60;
|
document.getElementById("moves").textContent = moves;
|
||||||
timerElement.textContent = time;
|
document.getElementById("score").textContent = score;
|
||||||
timerStarted = false;
|
|
||||||
moves = 0;
|
|
||||||
score = 0;
|
|
||||||
movesElement.textContent = moves;
|
|
||||||
scoreElement.textContent = score;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
startGame();
|
startGame();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user