diff --git a/memoryPairGame/index.css b/memoryPairGame/index.css new file mode 100644 index 00000000..9a9c7ed5 --- /dev/null +++ b/memoryPairGame/index.css @@ -0,0 +1,74 @@ +#title{ + text-transform: capitalize; + color:gray; +} +.title{ + text-transform: capitalize; + color:gray; +} +.btn-yellow{ + background-color: yellow; +} +.btn-green{ + background-color: green; +} +.btn-blue{ + background-color: blue; +} +.btn-red{ + background-color:red; +} +.btnk{ + display: block; + padding: 60px 90px; + border: 3px solid black; + border-radius: 15px; +} +.kt{ + float: right; +} + + + +@media only screen and (max-width:403px) { + .btnk{ + padding: 50px 40px; + } + #score{ + padding: 10px 10px; + font-size: 25px; + } +} + + +.btnsw-yellow{ + background-color: rgba(255, 255, 0, 0.7); + border: 10px solid rgba(0, 0, 0, 0.616); +} +.btnsw-green{ + background-color: rgba(0, 128, 0, 0.7); + border: 10px solid rgba(0, 0, 0, 0.616); +} +.btnsw-blue{ + background-color: rgba(0, 0, 255, 0.7); + border: 10px solid rgba(0, 0, 0, 0.616); +} +.btnsw-red{ + background-color:rgba(255, 0, 0, 0.7); + border: 10px solid rgba(0, 0, 0, 0.616); +} + +.pressed { + box-shadow: 0 0 20px white; + background-color: grey; + } + + + #score{ + display: block; + color:gold; + padding: 24px 30px; + background: #333; + border: 2px solid yellow; + border-radius: 15px; +} \ No newline at end of file diff --git a/memoryPairGame/index.html b/memoryPairGame/index.html new file mode 100644 index 00000000..74e58a39 --- /dev/null +++ b/memoryPairGame/index.html @@ -0,0 +1,68 @@ + + + + Game + + + + + + +
+
+
+

Press S To Start The Game

+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+

Your Highest Score is

+
+
+
+ +
+
+
+ +
+
+
+
+ +
+
+
+ Made By Shivam Chaudhary For any Error Contact Me +
+
+
+ + + + + + + + \ No newline at end of file diff --git a/memoryPairGame/index.js b/memoryPairGame/index.js new file mode 100644 index 00000000..fa68efad --- /dev/null +++ b/memoryPairGame/index.js @@ -0,0 +1,129 @@ +var color = ["blue", "red", "yellow", "green"]; +var userEntery = []; +var random = []; +var started = false; +var level = 0; + +if (localStorage.getItem("score") == undefined) { + $("#score").css("display", "none"); +} else { + $("#score").css("display", "block"); + $("#score").text(`Your Highest Score is ${localStorage.getItem('score')}`); +} + + +function update() { + if (started) { + $("h1").html(`Round ${level}`); + $("h1").attr("class", "text-primary") + $("#alert").html(`Press !! all ${level} colours in order`); + + } + else { + if (level == 0) { $("h1").html(`Press S To Start The Game`); } + $("#alert").html("Rules !! Press S To Start Game (Remember order of color given by system)"); + $("h1").attr("class", "title") + } + +} +$(document).keypress(function (event) { + if (!started) { + if (event.key == "s" || event.key == "S") { + } + started = true; + $("#score").css("display", "none"); + gen(); + } +}) + +$("#s").click(()=>{ + if (!started) { + if (event.key == "s" || event.key == "S") { + } + started = true; + $("#score").css("display", "none"); + gen(); + } +}) + + +function gen() { + userEntery = []; + let temp = 0; + level = level + 1; + update(); + temp = Math.floor(Math.random() * (4 - 0) + 0); + random.push(color[temp]); + console.log(`${color[temp]}`) + $(`#${color[temp]}`).attr("class", `btnk btnsw-${color[temp]}`); + setTimeout(() => { $(`#${color[temp]}`).attr("class", `btnk btn-${color[temp]}`); }, 600); +} + + +$(".btnk").click(function () { + let userInputColor = $(this).attr("id"); + userEntery.push(userInputColor); + $(this).attr("class", "btnk btn-${userInputColor} pressed"); + setTimeout(() => { $(this).attr("class", `btnk btn-${userInputColor}`); }, 300); + soundplay(userInputColor); + checkAnswer(userEntery.length - 1); + +}) + +function checkAnswer(currentlevel) { + if (userEntery[currentlevel] == random[currentlevel]) { + if (random.length - 1 == currentlevel) { + setTimeout(gen,300); + + } + } else { + + soundplay("wrong"); + $("body").css("background-color", "red"); + setTimeout(function () { $("body").css("background-color", "white"); }, 300); + recordt(); + random = []; + level = 0; + userEntery = []; + started = false; + update(); + } +} + + +function soundplay(userInputColor) { + var audio = new Audio("sounds/" + userInputColor + ".mp3"); + audio.play(); +} + +function recordt() { + + let prev = localStorage.getItem("score"); + if (prev == undefined) { + + $("#score").text(`Your Score is ${level}`); + $("#score").css("display", "block"); + setTimeout(() => { $("#score").css("display", "none"); }, 5000); + localStorage.setItem("score", level); + } + if (level <= prev) { + + if(level==0){ + $("#score").html(`Press S To Start The Game First`); + $("#score").css("display", "block"); + setTimeout(() => { $("#score").css("display", "none"); }, 5000); + }else{ + $("#score").html(`Your Score is ${level} keep trying
Highest Score ${prev}`); + $("#score").css("display", "block"); + setTimeout(() => { $("#score").css("display", "none"); }, 5000); + } + + } else { + + $("#score").text(`Your Score Highest Score is ${level}`); + $("#score").css("display", "block"); + setTimeout(() => { $("#score").css("display", "none"); }, 5000); + localStorage.setItem("score", level); + } + +} \ No newline at end of file diff --git a/memoryPairGame/readme.md b/memoryPairGame/readme.md new file mode 100644 index 00000000..0f2e0fa2 --- /dev/null +++ b/memoryPairGame/readme.md @@ -0,0 +1,3 @@ +Just press S to start the game + +copy/Paste the code in your website for implementing the same \ No newline at end of file diff --git a/memoryPairGame/sounds/blue.mp3 b/memoryPairGame/sounds/blue.mp3 new file mode 100644 index 00000000..ae68cbae Binary files /dev/null and b/memoryPairGame/sounds/blue.mp3 differ diff --git a/memoryPairGame/sounds/green.mp3 b/memoryPairGame/sounds/green.mp3 new file mode 100644 index 00000000..896b9f96 Binary files /dev/null and b/memoryPairGame/sounds/green.mp3 differ diff --git a/memoryPairGame/sounds/red.mp3 b/memoryPairGame/sounds/red.mp3 new file mode 100644 index 00000000..e7738ae9 Binary files /dev/null and b/memoryPairGame/sounds/red.mp3 differ diff --git a/memoryPairGame/sounds/wrong.mp3 b/memoryPairGame/sounds/wrong.mp3 new file mode 100644 index 00000000..5ece8fd7 Binary files /dev/null and b/memoryPairGame/sounds/wrong.mp3 differ diff --git a/memoryPairGame/sounds/yellow.mp3 b/memoryPairGame/sounds/yellow.mp3 new file mode 100644 index 00000000..b360c086 Binary files /dev/null and b/memoryPairGame/sounds/yellow.mp3 differ