From 51e029865cf7db9e9d9b572dc436009278b663e1 Mon Sep 17 00:00:00 2001 From: kunal2812 Date: Sat, 1 Oct 2022 21:24:14 +0530 Subject: [PATCH 1/4] Card feature added --- index.html | 4 ++-- index.js | 38 ++++++++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/index.html b/index.html index 5fc16a2..38781d4 100644 --- a/index.html +++ b/index.html @@ -14,7 +14,7 @@

memory game

-

time:0

+

time:5

inosuke @@ -27,7 +27,7 @@

time:0

rengoku card cover -
+
mask card cover diff --git a/index.js b/index.js index a517b78..b95445a 100644 --- a/index.js +++ b/index.js @@ -3,16 +3,42 @@ const cards = document.querySelectorAll('.memory-card') const restartBtn = document.querySelector('#restart-btn') const timer = document.querySelector('#timer') let counter = 0; +let memoryCounter = 5; -//increasing the counter -const interval = setInterval(function(){ - counter++; - console.log() - timer.innerHTML = "" + counter + ""; +// Timing the counters +const decreaseTimer = setInterval(function(){ + if(memoryCounter>0){ + memoryCounter--; + viewAllCards(); + console.log() + timer.innerHTML = "" + memoryCounter + ""; + } + else{ + counter++; + console.log() + timer.innerHTML = "" + counter + ""; + } }, 1000); + +// To view all cards +function viewAllCards(){ + if(memoryCounter>0){ + cards.forEach(card=>{ + card.children[1].style.display="none"; + }) + } + else{ + cards.forEach(card=>{ + card.children[1].style.display="block"; + }) + } +} + + +// When the game restarts all cards are made visible for 5secs function restartGame(){ - window.location.reload() + window.location.reload(); } const flippedCards = [] From b01097ea50777aed53608be24888f0009b733ed6 Mon Sep 17 00:00:00 2001 From: kunal2812 Date: Sat, 1 Oct 2022 21:24:36 +0530 Subject: [PATCH 2/4] Updated CONTRIBUTORS.md --- CONTRIBUTORS.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f6962a5..069328e 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -13,6 +13,16 @@
+ + + KK +
+ + Kunal Katiyar + +
+
+ From acbc05e77f406ec39015b324a0a5ae05b70b1ed8 Mon Sep 17 00:00:00 2001 From: kunal2812 Date: Sat, 1 Oct 2022 21:56:50 +0530 Subject: [PATCH 3/4] Fixed few minor bugs --- index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index b95445a..e02fbf9 100644 --- a/index.js +++ b/index.js @@ -14,6 +14,11 @@ const decreaseTimer = setInterval(function(){ timer.innerHTML = "" + memoryCounter + ""; } else{ + if(counter==0){ + cards.forEach(card=>{ + card.addEventListener('click',flipCard); + }) + } counter++; console.log() timer.innerHTML = "" + counter + ""; @@ -56,7 +61,7 @@ function checkForMatch(){ if(matched===6) { alert("hurrah! you did it") - clearInterval(interval) + clearInterval(decreaseTimer) } else alert("woah! matched") @@ -85,9 +90,3 @@ function flipCard(e){ setTimeout(checkForMatch,0); } } - -cards.forEach(card=>{ - card.addEventListener('click',flipCard); -}) - - From 2187a7e9db12aa2f48ff511fb089ef21bcf365f1 Mon Sep 17 00:00:00 2001 From: kunal2812 Date: Sun, 2 Oct 2022 00:07:18 +0530 Subject: [PATCH 4/4] Resolved conflicts --- index.html | 2 +- index.js | 37 +++++++++++++++++-------------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/index.html b/index.html index 38781d4..34e3bec 100644 --- a/index.html +++ b/index.html @@ -14,7 +14,7 @@

memory game

-

time:5

+

time:0

inosuke diff --git a/index.js b/index.js index e02fbf9..f7f6052 100644 --- a/index.js +++ b/index.js @@ -5,39 +5,36 @@ const timer = document.querySelector('#timer') let counter = 0; let memoryCounter = 5; -// Timing the counters -const decreaseTimer = setInterval(function(){ - if(memoryCounter>0){ +// For modifying cards +const makeCardsClickable = setTimeout(function(){ + cards.forEach(card=>{ + card.addEventListener('click',flipCard); // Makes cards clickable after the timer expires + card.children[1].style.display="block"; // Hides them after the timer expires + }) +},memoryCounter*1000); + +// For timing the counters +const interval = setInterval(function(){ + if(memoryCounter>0){ // Makes a check on memoryCounter and stops after 5 secs memoryCounter--; viewAllCards(); - console.log() - timer.innerHTML = "" + memoryCounter + ""; + timer.innerHTML = "" + memoryCounter + ""; // Changes inner HTML } - else{ - if(counter==0){ - cards.forEach(card=>{ - card.addEventListener('click',flipCard); - }) - } - counter++; - console.log() - timer.innerHTML = "" + counter + ""; + else{ // Counter for timing the game + counter++; // This counter is set to motion only when the game starts i.e when memoryCounter expires + timer.innerHTML = "" + counter + ""; // Changes inner HTML } }, 1000); // To view all cards function viewAllCards(){ + // Cards are made viewable when memoryCounter is greater than 0 if(memoryCounter>0){ cards.forEach(card=>{ card.children[1].style.display="none"; }) } - else{ - cards.forEach(card=>{ - card.children[1].style.display="block"; - }) - } } @@ -61,7 +58,7 @@ function checkForMatch(){ if(matched===6) { alert("hurrah! you did it") - clearInterval(decreaseTimer) + clearInterval(interval) } else alert("woah! matched")