From 172ef9cac39cedfdcb41ea216d510eaed100c108 Mon Sep 17 00:00:00 2001
From: CodeXsubham <21cse062@glbitm.ac.in>
Date: Sat, 1 Jun 2024 14:43:26 +0530
Subject: [PATCH 1/3] Brain Card Game added
---
Games/Brain_card_game/index.html | 26 ++++++
Games/Brain_card_game/index.js | 148 +++++++++++++++++++++++++++++++
Games/Brain_card_game/style.css | 127 ++++++++++++++++++++++++++
3 files changed, 301 insertions(+)
create mode 100644 Games/Brain_card_game/index.html
create mode 100644 Games/Brain_card_game/index.js
create mode 100644 Games/Brain_card_game/style.css
diff --git a/Games/Brain_card_game/index.html b/Games/Brain_card_game/index.html
new file mode 100644
index 0000000000..b4bbd6c577
--- /dev/null
+++ b/Games/Brain_card_game/index.html
@@ -0,0 +1,26 @@
+
+
+
+
+ ${items.map(item => `
+
+ `).join('')}
+
+ `
+
+ const parser = new DOMParser().parseFromString(cards, 'text/html')
+
+ selectors.board.replaceWith(parser.querySelector('.board'))
+}
+
+const startGame = () => {
+ state.gameStarted = true
+ selectors.start.classList.add('disabled')
+
+ state.loop = setInterval(() => {
+ state.totalTime++
+
+ selectors.moves.innerText = `${state.totalFlips} moves`
+ selectors.timer.innerText = `time: ${state.totalTime} sec`
+ }, 1000)
+}
+
+const flipBackCards = () => {
+ document.querySelectorAll('.card:not(.matched)').forEach(card => {
+ card.classList.remove('flipped')
+ })
+
+ state.flippedCards = 0
+}
+
+const flipCard = card => {
+ state.flippedCards++
+ state.totalFlips++
+
+ if (!state.gameStarted) {
+ startGame()
+ }
+
+ if (state.flippedCards <= 2) {
+ card.classList.add('flipped')
+ }
+
+ if (state.flippedCards === 2) {
+ const flippedCards = document.querySelectorAll('.flipped:not(.matched)')
+
+ if (flippedCards[0].innerText === flippedCards[1].innerText) {
+ flippedCards[0].classList.add('matched')
+ flippedCards[1].classList.add('matched')
+ }
+
+ setTimeout(() => {
+ flipBackCards()
+ }, 100)
+ }
+
+ // If there are no more cards that we can flip, we won the game
+ if (!document.querySelectorAll('.card:not(.flipped)').length) {
+ setTimeout(() => {
+ selectors.boardContainer.classList.add('flipped')
+ selectors.win.innerHTML = `
+