From 7d293bbc0b2a6f31d95b43b9604ad8fcb6fffc82 Mon Sep 17 00:00:00 2001 From: abhishek Date: Sat, 12 Feb 2022 23:55:30 +0530 Subject: [PATCH 1/5] without ending --- index.html | 4 +- main.js | 200 +++++++++++++++++++++++++++++++++++++++++++--------- scenario.js | 122 ++++++++++++++++++++++++++++++++ style.css | 1 - 4 files changed, 291 insertions(+), 36 deletions(-) diff --git a/index.html b/index.html index bb03a42..ca3a2a3 100644 --- a/index.html +++ b/index.html @@ -17,7 +17,7 @@

- HACKER CARDS
+ HACKER CRDS
Choose the card to stop hackers' attack

@@ -61,7 +61,7 @@

- +
diff --git a/main.js b/main.js index f242959..157a270 100644 --- a/main.js +++ b/main.js @@ -8,19 +8,19 @@ // Your main work would be here, in main.js and would advice you to also pay a visit to the scenario.js - // Life of the player and the hacker. var playerLife = 5; var hackerLife = 5; - +var cardSelected=false; +var count=0; +var c=0; // Message to be displayed when the game is over -var hackerWinnerMessage = "Write the message here"; -var playerWinnerMessage = "Write the message here"; +var hackerWinnerMessage = "You have been defeated."; +var playerWinnerMessage = "Smart!Hacker has been arrested."; // ---------------Game code starts here ---------------// // declare a few handy variables like we've done :p - var playerStartLife = parseInt(playerLife); var hackerStartLife = parseInt(hackerLife); @@ -30,20 +30,27 @@ updateScores(); // you learnt DOM manipulation right? here's an example of the same. Go ahead and use manipulate the DOM! document.querySelector(".game-board").classList.add("before-game"); -var allCardElements = document.querySelectorAll(".card"); - -// Adds click handler to all player card elements so that your cards are actionable +var allCardElementsArr = Array.from(document.querySelectorAll(".card")); +var hackerCard = document.querySelector(".hacker-card"); +var playerCardsArr = Array.from(document.querySelectorAll(".player-card")); +playerCardsArr.forEach((el) => { + el.addEventListener("click", () => { + console.log("check my card is clicked"); + cardClicked(el); + }); +}); // An example of a function that controls what would happen when a card is clicked - -function cardClicked(cardEl) { - +function cardClicked(cardEl) + { + console.log("hji5"); if(cardSelected) { return; } cardSelected = true; - cardEl.classList.add("played-card"); + count++; + cardEl.classList.add("played-card"); document.querySelector(".game-board").classList.add("card-selected"); // Yes JS is cool and this would allow you to wait 500ms before revealing the hacker power @@ -62,63 +69,190 @@ function cardClicked(cardEl) { // Now write a function that shows the power level on the player card function revealPlayerPower(){ - + var playerCard = document.querySelector(".played-card"); + playerCard.classList.add("reveal-power"); + console.log("player power revealing"); } // Write a function that shows the power level on the hacker card function revealHackerPower(){ - + var hackerCard = document.querySelector(".hacker-card"); + hackerCard.classList.add("reveal-power"); + console.log("hacker power revealing"); } // Write a function to compare the cards. Here is where all your skills would come in handy! // P.S: We've added the 'disabled' attribute in the CSS file for the button and you should use it in case you want a certain element to just go away or 'vanish' at a certain time. For eg: You'd definitely want the 'Next' button to go away after a player chooses a card right? -function compareCards(){ +function compareCards() +{ + console.log("comparing the card"); + var playerCard = document.querySelector(".played-card"); + var playerPower=parseInt(playerCard.lastElementChild.innerText); + var hackerPower=parseInt(hackerCard.lastElementChild.innerText); + if(playerPower>hackerPower) + { + c=0; + hackerLife=hackerLife-(playerPower-hackerPower); + hackerCard.classList.add("worse-card"); + playerCard.classList.add("better-card"); + console.log( "hackerLife is:"); + console.log( hackerLife); + } + else + { + c=1; + playerLife=playerLife-(hackerPower-playerPower); + hackerCard.classList.add("better-card"); + playerCard.classList.add("worse-card"); + console.log( "plakerLife is:"); + console.log( playerLife); + } + + updateScores(); + + // setTimeout(function(){ + // restartGame(); + // },2000) + + // playTurn(); + // console.log("scores has been updated"); } //Use conditional statements and complete the function that shows the winner message -function gameOver(winner) { +function gameOver(winner) +{ } - // Write a function that starts the game -function startGame() { - -} - - -// Now write a function that starts the game over from scratch -function restartGame(){ - +function startGame() +{ + console.log("start the game"); + document.querySelector(".game-board").classList.remove("before-game"); + document.querySelector(".game-board").classList.add("during-game"); + firstplayTurn(); } // We've also used a cool life bar that displays the life left. Write a function that updates the displayed life bar and life totals // use innerHTML and a lot of other cool things to do this. -function updateScores(){ - +function updateScores() +{ // Here these update life totals for each player document.querySelector(".player-stats .life-total").innerHTML = playerLife; + document.querySelector(".hacker-stats .life-total").innerHTML = hackerLife; // We've added the code to update the player lifebar var playerPercent = playerLife / playerStartLife * 100; - if (playerPercent < 0) { + if (playerPercent < 0) + { playerPercent = 0; } document.querySelector(".player-stats .life-left").style.height = playerPercent + "%"; // Now you write the code to update the hacker lifebar + // done the task + var hackerPercent = hackerLife / hackerStartLife * 100; + if (hackerPercent < 0) + { + hackerPercent = 0; + } + document.querySelector(".hacker-stats .life-left").style.height = hackerPercent + "%"; +} +// Write a function that Plays one turn of the game +function firstplayTurn() +{ + console.log("time game"); + console.log("count is 0"); + cardSelected = false; + + hackerCard.firstElementChild.innerText = scenarios[count].hackerCard.description; + hackerCard.lastElementChild.innerText = scenarios[count].hackerCard.power; + + hackerCard.classList.add("showCard"); + + playerCardsArr.forEach((el) => { + el.classList.add("showCard");}); + + playerCardsArr[0].firstElementChild.innerText = scenarios[count].playerCards[0].description; + playerCardsArr[1].firstElementChild.innerText = scenarios[count].playerCards[1].description; + playerCardsArr[2].firstElementChild.innerText = scenarios[count].playerCards[2].description; + + playerCardsArr[0].lastElementChild.innerText = scenarios[count].playerCards[0].power; + playerCardsArr[1].lastElementChild.innerText = scenarios[count].playerCards[1].power; + playerCardsArr[2].lastElementChild.innerText = scenarios[count].playerCards[2].power; } +function restartGame() +{ + // setTimeout(function(){ + // rer(); + // },5000) + + // function rer(){ + // var hackerCard = document.querySelector(".hacker-card"); + // hackerCard.classList.remove("showCard"); + // console.log("showing 2nd one"); + // } +} +function playTurn() +{ + console.log("count is :"); + console.log(count); + cardSelected = false; + var playerCard = document.querySelector(".played-card"); + var hackerCard = document.querySelector(".hacker-card"); + if(c==0) + { + hackerCard.classList.remove("worse-card"); + playerCard.classList.remove("better-card"); + console.log("removed tags1"); + } + else + { + hackerCard.classList.remove("better-card"); + playerCard.classList.remove("worse-card"); + console.log( "removed tags2"); + } + + playerCard.classList.remove("reveal-power"); + hackerCard.classList.remove("reveal-power"); -// Write a function that Plays one turn of the game -function playTurn() { + var playerCard = document.querySelector(".played-card"); + playerCard.classList.remove("played-card"); -} + document.querySelector(".game-board").classList.remove("card-selected"); + hackerCard.classList.remove("showCard"); + + playerCardsArr.forEach((el) => { + el.classList.remove("showCard");}); + + + hackerCard.classList.add("showCard"); + playerCardsArr.forEach((el) => { + el.classList.add("showCard");}); -// Finally write the function that reveals the cards. Use -function revealCards(){ + // setTimeout(function(){ + // rer(); + // },5000) + // function rer(){ + // var hackerCard = document.querySelector(".hacker-card"); + // hackerCard.classList.add("showCard"); + // console.log("showing 2nd one"); + // } + + + hackerCard.firstElementChild.innerText = scenarios[count].hackerCard.description; + hackerCard.lastElementChild.innerText = scenarios[count].hackerCard.power; + + playerCardsArr[0].firstElementChild.innerText = scenarios[count].playerCards[0].description; + playerCardsArr[1].firstElementChild.innerText = scenarios[count].playerCards[1].description; + playerCardsArr[2].firstElementChild.innerText = scenarios[count].playerCards[2].description; + + playerCardsArr[0].lastElementChild.innerText = scenarios[count].playerCards[0].power; + playerCardsArr[1].lastElementChild.innerText = scenarios[count].playerCards[1].power; + playerCardsArr[2].lastElementChild.innerText = scenarios[count].playerCards[2].power; } \ No newline at end of file diff --git a/scenario.js b/scenario.js index f926d60..19e1764 100644 --- a/scenario.js +++ b/scenario.js @@ -48,4 +48,126 @@ var scenarios = [ } ] }, + { + hackerCard : { + description : "3rd", + power : 3, + }, + playerCards : [ + { + description : "I c.", + power : 5, + }, + { + description : "I n.", + power : 4, + }, + { + description : "I s", + power : 1, + } + ] + }, + { // add the text you'd want should appear on the hacker's card + hackerCard : { + description : "4th", + power : 4, + }, + // add 3 card descriptions you'd want should appear on the player's card. Keeping in mind that at least ONE of them should be an apt counter! + playerCards : [ + { + description : " public", + power : 5, + }, + { + description : "never ", + power : 3, + }, + { + description : "private", + power : 1, + } + ] + }, + { // add the text you'd want should appear on the hacker's card + hackerCard : { + description : "I5th card.", + power : 4, + }, + // add 3 card descriptions you'd want should appear on the player's card. Keeping in mind that at least ONE of them should be an apt counter! + playerCards : [ + { + description : " never", + power : 5, + }, + { + description : " the web, .", + power : 3, + }, + { + description : "I conn.", + power : 1, + } + ] + }, + { + hackerCard : { + description : "7th", + power : 3, + }, + playerCards : [ + { + description : "bank.", + power : 5, + }, + { + description : "I ", + power : 4, + }, + { + description : "I sent", + power : 1, + } + ] + }, + { + hackerCard : { + description : "8th.", + power : 3, + }, + playerCards : [ + { + description : "I checked .", + power : 5, + }, + { + description : "I give .", + power : 4, + }, + { + description : "I sent ", + power : 1, + } + ] + }, + { + hackerCard : { + description : "9th.", + power : 3, + }, + playerCards : [ + { + description : " bank.", + power : 5, + }, + { + description : "email.", + power : 4, + }, + { + description : " account.", + power : 1, + } + ] + }, ]; \ No newline at end of file diff --git a/style.css b/style.css index 9ceaaee..70ec6bf 100644 --- a/style.css +++ b/style.css @@ -409,7 +409,6 @@ button[disabled=true] { background: none; } - @keyframes showPower { 0% { background: none; From 22c04b5b83b2cdccfd073ffb1bca558767c3a28d Mon Sep 17 00:00:00 2001 From: abhishek Date: Sun, 13 Feb 2022 02:04:00 +0530 Subject: [PATCH 2/5] finally basic is ready --- index.html | 2 +- main.js | 42 +++++++++++++++++++++++++++++------------- style.css | 3 ++- 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/index.html b/index.html index ca3a2a3..f44f39b 100644 --- a/index.html +++ b/index.html @@ -61,7 +61,7 @@

- + diff --git a/main.js b/main.js index 157a270..47de191 100644 --- a/main.js +++ b/main.js @@ -109,7 +109,7 @@ function compareCards() } updateScores(); - + gameOver(); // setTimeout(function(){ // restartGame(); // },2000) @@ -120,9 +120,26 @@ function compareCards() } //Use conditional statements and complete the function that shows the winner message -function gameOver(winner) +function gameOver() { + console.log("gameover initial"); + if(playerLife <= 0) + { + document.querySelector(".winner-section").style.display = "block"; + document.querySelector(".next-turn").style.display = "none"; + document.querySelector(".winner-message").innerHTML = hackerWinnerMessage; + console.log("gameover"); + restartGame(); + } + else if(hackerLife <= 0) + { + document.querySelector(".winner-section").style.display = "block"; + document.querySelector(".next-turn").style.display = "none"; + document.querySelector(".winner-message").innerHTML = playerWinnerMessage; + console.log("gameover"); + restartGame(); + } } // Write a function that starts the game @@ -186,15 +203,13 @@ function firstplayTurn() function restartGame() { - // setTimeout(function(){ - // rer(); - // },5000) - - // function rer(){ - // var hackerCard = document.querySelector(".hacker-card"); - // hackerCard.classList.remove("showCard"); - // console.log("showing 2nd one"); - // } + + playerLife = 5; + hackerLife = 5; + cardSelected=false; + count=0; + c=0; +console.log("NEW GAME"); } function playTurn() @@ -204,6 +219,8 @@ function playTurn() cardSelected = false; var playerCard = document.querySelector(".played-card"); var hackerCard = document.querySelector(".hacker-card"); + + if(c==0) { hackerCard.classList.remove("worse-card"); @@ -228,7 +245,7 @@ function playTurn() playerCardsArr.forEach((el) => { el.classList.remove("showCard");}); - + hackerCard.classList.add("showCard"); playerCardsArr.forEach((el) => { @@ -244,7 +261,6 @@ function playTurn() // console.log("showing 2nd one"); // } - hackerCard.firstElementChild.innerText = scenarios[count].hackerCard.description; hackerCard.lastElementChild.innerText = scenarios[count].hackerCard.power; diff --git a/style.css b/style.css index 70ec6bf..4c6e0fd 100644 --- a/style.css +++ b/style.css @@ -183,7 +183,8 @@ button:active { animation: winnerAppear .4s ease-out; } -.winner-section button { +.winner-section button +{ margin-left: 15px; } From 6ba191a43adedeba6f80338356b48132a4533caf Mon Sep 17 00:00:00 2001 From: abhishek Date: Sun, 13 Feb 2022 02:31:00 +0530 Subject: [PATCH 3/5] timeout --- main.js | 65 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 48 insertions(+), 17 deletions(-) diff --git a/main.js b/main.js index 47de191..c89482b 100644 --- a/main.js +++ b/main.js @@ -76,7 +76,7 @@ function revealPlayerPower(){ // Write a function that shows the power level on the hacker card function revealHackerPower(){ - var hackerCard = document.querySelector(".hacker-card"); + // var hackerCard = document.querySelector(".hacker-card"); hackerCard.classList.add("reveal-power"); console.log("hacker power revealing"); } @@ -226,15 +226,26 @@ function playTurn() hackerCard.classList.remove("worse-card"); playerCard.classList.remove("better-card"); console.log("removed tags1"); + + playerCard.classList.remove("reveal-power"); + hackerCard.classList.remove("reveal-power"); + + var playerCard = document.querySelector(".played-card"); + playerCard.classList.remove("played-card"); + + document.querySelector(".game-board").classList.remove("card-selected"); + hackerCard.classList.remove("showCard"); + + playerCardsArr.forEach((el) => { + el.classList.remove("showCard");}); } - else + else if(c=1) { hackerCard.classList.remove("better-card"); playerCard.classList.remove("worse-card"); console.log( "removed tags2"); - } - - playerCard.classList.remove("reveal-power"); + + playerCard.classList.remove("reveal-power"); hackerCard.classList.remove("reveal-power"); var playerCard = document.querySelector(".played-card"); @@ -245,21 +256,41 @@ function playTurn() playerCardsArr.forEach((el) => { el.classList.remove("showCard");}); - + } + + // playerCard.classList.remove("reveal-power"); + // hackerCard.classList.remove("reveal-power"); - hackerCard.classList.add("showCard"); - playerCardsArr.forEach((el) => { - el.classList.add("showCard");}); + // var playerCard = document.querySelector(".played-card"); + // playerCard.classList.remove("played-card"); - // setTimeout(function(){ - // rer(); - // },5000) + // document.querySelector(".game-board").classList.remove("card-selected"); + // hackerCard.classList.remove("showCard"); - // function rer(){ - // var hackerCard = document.querySelector(".hacker-card"); - // hackerCard.classList.add("showCard"); - // console.log("showing 2nd one"); - // } + // playerCardsArr.forEach((el) => { + // el.classList.remove("showCard");}); + + + + // playerCardsArr.forEach((el) => { + // el.classList.add("showCard");}); + + setTimeout(function(){ + prrer(); + },1100) + function prrer(){ + playerCardsArr.forEach((el) => { + el.classList.add("showCard");}); + console.log("showing 2nd one"); + } + + setTimeout(function(){ + her(); + },600) + function her(){ + hackerCard.classList.add("showCard"); + console.log("showing 2nd one"); + } hackerCard.firstElementChild.innerText = scenarios[count].hackerCard.description; hackerCard.lastElementChild.innerText = scenarios[count].hackerCard.power; From 7c3ed88674464387c8c8418310dddc4afb2c15c9 Mon Sep 17 00:00:00 2001 From: abhishek Date: Sun, 13 Feb 2022 02:38:06 +0530 Subject: [PATCH 4/5] final js --- main.js | 58 ++++++--------------------------------------------------- 1 file changed, 6 insertions(+), 52 deletions(-) diff --git a/main.js b/main.js index c89482b..a0060db 100644 --- a/main.js +++ b/main.js @@ -13,7 +13,7 @@ var playerLife = 5; var hackerLife = 5; var cardSelected=false; var count=0; -var c=0; +var c=2; // Message to be displayed when the game is over var hackerWinnerMessage = "You have been defeated."; var playerWinnerMessage = "Smart!Hacker has been arrested."; @@ -113,16 +113,13 @@ function compareCards() // setTimeout(function(){ // restartGame(); // },2000) - // playTurn(); - - // console.log("scores has been updated"); + console.log("scores has been updated"); } //Use conditional statements and complete the function that shows the winner message function gameOver() { - console.log("gameover initial"); if(playerLife <= 0) { @@ -148,7 +145,7 @@ function startGame() console.log("start the game"); document.querySelector(".game-board").classList.remove("before-game"); document.querySelector(".game-board").classList.add("during-game"); - firstplayTurn(); + playTurn(); } // We've also used a cool life bar that displays the life left. Write a function that updates the displayed life bar and life totals @@ -177,33 +174,8 @@ function updateScores() document.querySelector(".hacker-stats .life-left").style.height = hackerPercent + "%"; } -// Write a function that Plays one turn of the game -function firstplayTurn() -{ - console.log("time game"); - console.log("count is 0"); - cardSelected = false; - - hackerCard.firstElementChild.innerText = scenarios[count].hackerCard.description; - hackerCard.lastElementChild.innerText = scenarios[count].hackerCard.power; - - hackerCard.classList.add("showCard"); - - playerCardsArr.forEach((el) => { - el.classList.add("showCard");}); - - playerCardsArr[0].firstElementChild.innerText = scenarios[count].playerCards[0].description; - playerCardsArr[1].firstElementChild.innerText = scenarios[count].playerCards[1].description; - playerCardsArr[2].firstElementChild.innerText = scenarios[count].playerCards[2].description; - - playerCardsArr[0].lastElementChild.innerText = scenarios[count].playerCards[0].power; - playerCardsArr[1].lastElementChild.innerText = scenarios[count].playerCards[1].power; - playerCardsArr[2].lastElementChild.innerText = scenarios[count].playerCards[2].power; -} - function restartGame() { - playerLife = 5; hackerLife = 5; cardSelected=false; @@ -220,7 +192,6 @@ function playTurn() var playerCard = document.querySelector(".played-card"); var hackerCard = document.querySelector(".hacker-card"); - if(c==0) { hackerCard.classList.remove("worse-card"); @@ -239,7 +210,7 @@ function playTurn() playerCardsArr.forEach((el) => { el.classList.remove("showCard");}); } - else if(c=1) + else if(c==1) { hackerCard.classList.remove("better-card"); playerCard.classList.remove("worse-card"); @@ -257,27 +228,10 @@ function playTurn() playerCardsArr.forEach((el) => { el.classList.remove("showCard");}); } - - // playerCard.classList.remove("reveal-power"); - // hackerCard.classList.remove("reveal-power"); - - // var playerCard = document.querySelector(".played-card"); - // playerCard.classList.remove("played-card"); - - // document.querySelector(".game-board").classList.remove("card-selected"); - // hackerCard.classList.remove("showCard"); - - // playerCardsArr.forEach((el) => { - // el.classList.remove("showCard");}); - - - - // playerCardsArr.forEach((el) => { - // el.classList.add("showCard");}); setTimeout(function(){ prrer(); - },1100) + },1000) function prrer(){ playerCardsArr.forEach((el) => { el.classList.add("showCard");}); @@ -286,7 +240,7 @@ function playTurn() setTimeout(function(){ her(); - },600) + },400) function her(){ hackerCard.classList.add("showCard"); console.log("showing 2nd one"); From 16d8c46b2a3e89368ed42a9b1188b355d2ade770 Mon Sep 17 00:00:00 2001 From: abhishek Date: Mon, 14 Feb 2022 01:11:14 +0530 Subject: [PATCH 5/5] scenarios --- scenario.js | 52 +++++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/scenario.js b/scenario.js index 19e1764..61e86a4 100644 --- a/scenario.js +++ b/scenario.js @@ -50,86 +50,88 @@ var scenarios = [ }, { hackerCard : { - description : "3rd", + description : "Hello hello ,your bank account will be closed if you dont tell your OTP!!! ", power : 3, }, playerCards : [ { - description : "I c.", + description : "I will not tell OTP to strangers.", power : 5, }, { - description : "I n.", + description : "Wait a little,You are from which bank?", power : 4, }, { - description : "I s", + description : "Yes my OTP is 620936.", power : 1, } ] }, { // add the text you'd want should appear on the hacker's card hackerCard : { - description : "4th", + description : "Hey,I am leaking your facebook photo", power : 4, }, // add 3 card descriptions you'd want should appear on the player's card. Keeping in mind that at least ONE of them should be an apt counter! playerCards : [ { - description : " public", - power : 5, + description : " Please dont public it.", + power : 1, }, { - description : "never ", + description : "I am deactivating my account.", power : 3, }, { - description : "private", - power : 1, + description : "Haha!My account is private", + power : 5, } ] }, - { // add the text you'd want should appear on the hacker's card + + { hackerCard : { - description : "I5th card.", + description : "I sent a fraud link in message.", power : 4, }, - // add 3 card descriptions you'd want should appear on the player's card. Keeping in mind that at least ONE of them should be an apt counter! playerCards : [ { - description : " never", - power : 5, + description : "I opened the link but only checked it.", + power : 3, }, { - description : " the web, .", - power : 3, + description : "I ignored the message as we should not click random link.", + power : 5, }, { - description : "I conn.", + description : "I filled the form in link.", power : 1, } ] }, - { + { // add the text you'd want should appear on the hacker's card hackerCard : { - description : "7th", - power : 3, + description : "I set up a fake Wi-Fi station to steal people’s email and track them online.", + power : 4, }, + // add 3 card descriptions you'd want should appear on the player's card. Keeping in mind that at least ONE of them should be an apt counter! playerCards : [ { - description : "bank.", + description : "I never use public wifi networks.", power : 5, }, { - description : "I ", - power : 4, + description : "I browse the web, but I never do any personal business on a public wifi network.", + power : 3, }, { - description : "I sent", + description : "I connect to any wifi network I can use in public.", power : 1, } ] }, + { hackerCard : { description : "8th.",