diff --git a/Rishab Dakhale/README.md b/Rishab Dakhale/README.md new file mode 100644 index 0000000..e69de29 diff --git a/Rishab Dakhale/app.js b/Rishab Dakhale/app.js new file mode 100644 index 0000000..62f5035 --- /dev/null +++ b/Rishab Dakhale/app.js @@ -0,0 +1,96 @@ +let gameseq = []; +let userseq = []; + +let game = false; +let level = 0; + + +let btns = ['red','yellow','green','purple']; + +let h2 = document.querySelector('h2'); + +document.addEventListener('keypress',function(){ + if(game == false){ + console.log('game was started'); + game = true; + } + + levelup (); +}) + +function gameflash (btn){ + btn.classList.add('flash'); + setTimeout(function(){ + btn.classList.remove('flash'); + },250); +} + +function userflash (btn){ + btn.classList.add('userflash'); + setTimeout(function(){ + btn.classList.remove('userflash'); + },250); +} + +let highScore = 0; + +function levelup (){ + userseq = []; + level++; + h2.innerText = (`Level ${level}`); + + let randidx = Math.floor(Math.random() *3); + let randcolor = btns[randidx]; + let randbtn = document.querySelector(`.${randcolor}`); + + gameflash(randbtn); + + gameseq.push(randcolor); + console.log(gameseq); +} + +function checkans(idx){ + if(userseq[idx] === gameseq[idx]) { + if(userseq.length == gameseq.length){ + setTimeout(levelup,1000); + } + }else{ + if (level > highScore) { + highScore = level; + } + h2.innerHTML = `Game over! Your score was ${level}
High score was ${highScore}
Press any key to start the game.`; + let body = document.querySelector('body').style.backgroundColor = 'red'; + + setTimeout(function(){ + document.querySelector('body').style.backgroundColor = 'white'; + },250); + + + + reset (); + } +} + +function btnpress (){ + let btn = this; + userflash(btn); + + usercolor = btn.getAttribute('id'); + userseq.push(usercolor); + + checkans(userseq.length-1); +} + +let allbtns = document.querySelectorAll('.button'); +for(btn of allbtns){ + btn.addEventListener('click', btnpress); +} + +function reset (){ + gameseq = []; + userseq = []; + level = 0; +} + + + diff --git a/Rishab Dakhale/index.html b/Rishab Dakhale/index.html new file mode 100644 index 0000000..49f943a --- /dev/null +++ b/Rishab Dakhale/index.html @@ -0,0 +1,27 @@ + + + + + + + Simon Say Game + + + + +

Simon Game

+

press any key to start Game

+
+
+
+
+
+
+
+
+
+
+ + + + \ No newline at end of file diff --git a/Rishab Dakhale/style.css b/Rishab Dakhale/style.css new file mode 100644 index 0000000..1545ab0 --- /dev/null +++ b/Rishab Dakhale/style.css @@ -0,0 +1,40 @@ +body{ + text-align: center; +} + +.btn-container{ + display: flex; + justify-content: center; +} + +.button{ + height: 200px; + width: 200px; + border-radius: 20%; + border: 10px solid black; + margin: 2.5rem; +} + +.red{ + background-color: #d95980; +} + +.yellow{ + background-color: #f99b45; +} + +.green{ + background-color: #819ff9; +} + +.purple{ + background-color: #63aac0; +} + +.flash{ + background-color: white; +} + +.userflash{ + background-color: green; +} \ No newline at end of file