diff --git a/age-as-a-lesn.css b/age-as-a-lesn.css index cdfff79..3498c86 100644 --- a/age-as-a-lesn.css +++ b/age-as-a-lesn.css @@ -67,7 +67,7 @@ @media (orientation: portrait) { #bg-video { width: auto; - height: 100%; + height: 100vh; max-width: 100%; } } @@ -86,7 +86,7 @@ /* Tablets */ @media (max-width: 768px) { .video-section { - height: 80vh; + height: 100vh; } .overlay-content { @@ -103,7 +103,7 @@ /* Large phones */ @media (max-width: 576px) { .video-section { - height: 70vh; + height: 90vh; } .overlay-content { @@ -121,7 +121,7 @@ /* Small phones */ @media (max-width: 375px) { .video-section { - height: 60vh; + height: 80vh; } .overlay-content { diff --git a/cards-age.js b/cards-age.js index 1ee277f..a397130 100644 --- a/cards-age.js +++ b/cards-age.js @@ -1,121 +1,126 @@ -var errors = 0; -var score = 0; -var matchedPairs = 0; // Track matched pairs -var totalPairs = 8; // Total pairs in the game -var startTime, timerInterval; -var cardList = ["2", "3", "4", "5", "6", "7", "8", "9"]; -var cardSet, board = []; -var rows = 4, columns = 4; -var card1Selected, card2Selected; -var flipTimeout; +const flipSound = new Audio("flipcard.mp3"); + const matchSound = new Audio("match.mp3"); + const winSound = new Audio("win.mp3"); -window.onload = function() { - shuffleCards(); - startGame(); - document.getElementById("timer").innerText = "Time: 0s"; // Initialize timer display -} + var errors = 0; + var score = 0; + var matchedPairs = 0; + var totalPairs = 8; + var startTime, timerInterval; + var cardList = ["2", "3", "4", "5", "6", "7", "8", "9"]; + var cardSet, board = []; + var rows = 4, columns = 4; + var card1Selected, card2Selected; + var flipTimeout; -function shuffleCards() { - cardSet = cardList.concat(cardList); - for (let i = 0; i < cardSet.length; i++) { - let j = Math.floor(Math.random() * cardSet.length); - [cardSet[i], cardSet[j]] = [cardSet[j], cardSet[i]]; // Swap - } -} + window.onload = function() { + shuffleCards(); + startGame(); + document.getElementById("timer").innerText = "Time: 0s"; + } -function startGame() { - for (let r = 0; r < rows; r++) { - let row = []; - for (let c = 0; c < columns; c++) { - let cardImg = cardSet.pop(); - row.push(cardImg); - let card = document.createElement("img"); - card.id = `${r}-${c}`; - card.src = cardImg + ".png"; - card.classList.add("card"); - card.addEventListener("click", selectCard); - document.getElementById("board").append(card); + function shuffleCards() { + cardSet = cardList.concat(cardList); + for (let i = 0; i < cardSet.length; i++) { + let j = Math.floor(Math.random() * cardSet.length); + [cardSet[i], cardSet[j]] = [cardSet[j], cardSet[i]]; + } } - board.push(row); - } - setTimeout(hideCards, 10); -} -function hideCards() { - for (let r = 0; r < rows; r++) { - for (let c = 0; c < columns; c++) { - document.getElementById(`${r}-${c}`).src = "back.png"; + function startGame() { + for (let r = 0; r < rows; r++) { + let row = []; + for (let c = 0; c < columns; c++) { + let cardImg = cardSet.pop(); + row.push(cardImg); + let card = document.createElement("img"); + card.id = `${r}-${c}`; + card.src = cardImg + ".png"; + card.classList.add("card"); + card.addEventListener("click", selectCard); + document.getElementById("board").append(card); + } + board.push(row); + } + setTimeout(hideCards, 10); } - } -} -function startTimer() { - startTime = new Date(); - timerInterval = setInterval(() => { - let timeElapsed = Math.floor((new Date() - startTime) / 1000); - document.getElementById("timer").innerText = `Time: ${timeElapsed}s`; - }, 1000); -} + function hideCards() { + for (let r = 0; r < rows; r++) { + for (let c = 0; c < columns; c++) { + document.getElementById(`${r}-${c}`).src = "back.png"; + } + } + } -function stopTimer() { - clearInterval(timerInterval); -} + function startTimer() { + startTime = new Date(); + timerInterval = setInterval(() => { + let timeElapsed = Math.floor((new Date() - startTime) / 1000); + document.getElementById("timer").innerText = `Time: ${timeElapsed}s`; + }, 1000); + } -function selectCard() { - if (!startTime) startTimer(); // Start timer only on first card click - - if (this.src.includes("back") && !card2Selected) { // Only proceed if a card pair isn’t being processed - if (flipTimeout) clearTimeout(flipTimeout); // Clear any pending timeout to avoid freezing - - if (!card1Selected) { - card1Selected = this; - revealCard(card1Selected); - } else if (this != card1Selected) { - card2Selected = this; - revealCard(card2Selected); - flipTimeout = setTimeout(checkMatch, 500); // Check for match after a short delay + function stopTimer() { + clearInterval(timerInterval); } - } -} -function revealCard(card) { - let [r, c] = card.id.split("-").map(Number); - card.src = board[r][c] + ".png"; -} + function selectCard() { + if (!startTime) startTimer(); // Start timer only on first card click + + if (this.src.includes("back") && !card2Selected) { // Only proceed if a card pair isn’t being processed + if (flipTimeout) clearTimeout(flipTimeout); // Clear any pending timeout to avoid freezing + + if (!card1Selected) { + card1Selected = this; + revealCard(card1Selected); + matchSound.play(); // Play flip sound + } else if (this != card1Selected) { + card2Selected = this; + revealCard(card2Selected); + matchSound.play(); // Play flip sound + flipTimeout = setTimeout(checkMatch, 500); // Check for match after a short delay + } + } + } + + function revealCard(card) { + let [r, c] = card.id.split("-").map(Number); + card.src = board[r][c] + ".png"; + } -function checkMatch() { - if (card1Selected && card2Selected) { // Proceed only if both cards are selected - if (card1Selected.src === card2Selected.src) { - let timeTaken = Math.floor((new Date() - startTime) / 1000); - let tempScore = 50 - (errors * 5) - (timeTaken * 0.2); - score += tempScore < 5 ? 5 : tempScore; - errors = 0; - document.getElementById("score").innerText = score; - matchedPairs++; // Increment matched pairs + function checkMatch() { + if (card1Selected && card2Selected) { + if (card1Selected.src === card2Selected.src) { + let timeTaken = Math.floor((new Date() - startTime) / 1000); + let tempScore = 50 - (errors * 5) - (timeTaken * 0.2); + score += tempScore < 5 ? 5 : tempScore; + errors = 0; + document.getElementById("score").innerText = score; + matchedPairs++; - if (matchedPairs === totalPairs) { // Check if all pairs are matched - endGame(); + matchSound.play(); // Play match sound + + if (matchedPairs === totalPairs) { + endGame(); + } + } else { + card1Selected.src = "back.png"; + card2Selected.src = "back.png"; + errors++; + } + card1Selected = null; + card2Selected = null; } - } else { - card1Selected.src = "back.png"; - card2Selected.src = "back.png"; - errors++; } - card1Selected = null; - card2Selected = null; - } -} - -function endGame() { - stopTimer(); - document.getElementById("finalScore").innerText = score; - document.getElementById("endModal").style.display = "flex"; // Show modal -} -function restartGame() { - location.reload(); // Reload the page to restart the game -} + function endGame() { + stopTimer(); + document.getElementById("finalScore").innerText = score; + document.getElementById("endModal").style.display = "flex"; + winSound.play(); // Play win sound + } -function revealTheme() { - alert("The theme is 'Age as a Lens' – exploring how different age groups perceive life differently!"); -} + function restartGame() { + location.reload(); + } \ No newline at end of file diff --git a/flipcard.mp3 b/flipcard.mp3 new file mode 100644 index 0000000..a670876 Binary files /dev/null and b/flipcard.mp3 differ diff --git a/index.html b/index.html index ac0519f..4c5b178 100644 --- a/index.html +++ b/index.html @@ -154,7 +154,7 @@
DATE

- 5:30 PM, 8th Nov, 2024 + 6:00 PM, 8th Nov, 2024

@@ -627,7 +627,7 @@