| 30 | } |
| 31 | |
| 32 | function LetsPlay(evt){ |
| 33 | |
| 34 | //debugger |
| 35 | if(level == 0){ |
| 36 | seq.push(evt.id); |
| 37 | count++; |
| 38 | clicks++; |
| 39 | } |
| 40 | else if(evt.id != seq[clicks++]){ //Game Over!!! |
| 41 | |
| 42 | var audio = new Audio("sounds/"+"wrong"+".mp3"); |
| 43 | audio.play(); |
| 44 | $("body").addClass("game-over"); |
| 45 | setTimeout(function(){ |
| 46 | $("body").removeClass("game-over") |
| 47 | },300); |
| 48 | $("h1").text( "Game Over, Press Any Key to Restart"); |
| 49 | document.addEventListener("keyup",function(){ |
| 50 | startOver(); |
| 51 | }) |
| 52 | return; |
| 53 | } |
| 54 | if(clicks==count){ //Next Level |
| 55 | var randval = Math.floor(Math.random()*4); //Generating next color |
| 56 | seq.push(colors[randval]); |
| 57 | count++; |
| 58 | level++; |
| 59 | clicks = 0; |
| 60 | $("h1").text("LEVEL "+level); |
| 61 | for(var i=0;i<seq.length;i++) |
| 62 | highlight(i); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | |
| 67 | |