Merge branch 'main' of https://git-eng.ukwms.ac.id/2526-web/Kelompok02-Memory-Card
This commit is contained in:
commit
2bc754abb3
@ -1,10 +1,9 @@
|
|||||||
<!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;
|
||||||
@ -21,14 +20,13 @@ body {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
padding: 6px 10px;
|
padding: 6px 10px;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
background: rgb(255, 255, 255);
|
background: rgba(255, 255, 255, 0.6);
|
||||||
backdrop-filter: blur white(14px);
|
backdrop-filter: blur(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;
|
||||||
@ -38,13 +36,11 @@ 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;
|
||||||
@ -57,42 +53,89 @@ 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 class="gameboard">
|
<div id="game-board" class="gameboard">
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const imageList = [
|
const imageList = [
|
||||||
"alpukat.jpg",
|
"alpukat.jpg",
|
||||||
"anggur.jpg",
|
"anggur.jpg",
|
||||||
"apel.jpg",
|
"apel.jpg",
|
||||||
@ -105,12 +148,11 @@ body {
|
|||||||
"semangka.jpg"
|
"semangka.jpg"
|
||||||
];
|
];
|
||||||
|
|
||||||
let images = [...imageList, ...imageList]; // double for pairs
|
let images = [...imageList, ...imageList];
|
||||||
|
|
||||||
|
|
||||||
// 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--;
|
||||||
@ -119,7 +161,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");
|
||||||
@ -130,7 +172,6 @@ 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;
|
||||||
@ -138,7 +179,6 @@ 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!");
|
||||||
@ -147,7 +187,6 @@ function startTimer() {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FLIP CARD FUNCTION
|
|
||||||
function flipCard(card) {
|
function flipCard(card) {
|
||||||
if (!timerStarted) startTimer();
|
if (!timerStarted) startTimer();
|
||||||
|
|
||||||
@ -178,7 +217,6 @@ 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 = "";
|
||||||
@ -200,7 +238,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;
|
||||||
@ -210,8 +248,8 @@ function startGame() {
|
|||||||
scoreElement.textContent = score;
|
scoreElement.textContent = score;
|
||||||
}
|
}
|
||||||
|
|
||||||
startGame();
|
|
||||||
|
|
||||||
|
startGame();
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user