Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <link href="https://fonts.googleapis.com/css?family=Cabin+Sketch" rel="stylesheet">
 
<div class="mainboard">
  <h1  data-toggle="tooltip" data-placement="right" title="Follow the pattern of lights and sounds and repeat the same combination to move on to the next round">Simon Game! </h1>
<div class="red board" id="1">

</div>
<div class="green board" id="2">

</div>
<div class="blue board" id="3">

</div>
<div class="yellow board" id="4">

</div>
 <div class="screen row">
   
   
   <div class="score col-xs-4"><h2>Level</h2>   
   </div>
   <div class="play col-xs-4"><h2>Start</h2> 
    </div>
     <div id="off" class="A col-xs-4"><h2>Restart</h2> 
     </div>
 
  </div>
</div> <!--  MAIN BOARD -->

            
          
!
            
              *{
  transition: all 1s;
  box-sizing: border-box;
}
h1{
  font-family: 'Cabin Sketch', cursive;
  font-size: 60px;
  
  text-align:center;
  padding-left:249px;
 margin-bottom:-80px;
}
h2{
  font-family: 'Cabin Sketch', cursive;
  cursor:pointer;
}
h2:hover{
  color:black;
}
.score:hover,.play:hover,.A:hover{
  
  box-shadow: 0px 0px 0px 1px #0074D9 inset, 0px 0px 0px 2px white inset,0px 0px 0px 2px white inset,0px 0px 0px 2px white inset;
}
body{
  background:khaki;
}
.mainboard{
  background:;
  height:200px;
  
  position: absolute;
  left: 40%;
  top: 15%;
  transform: translate(-50%, -50%);

  
}
.board{
  width: 250px;
  height: 200px;
  border:25px solid #000000;
  
  opacity:.8;
  position:relative;
  color:white;
  
  }
.board:hover{
  border:20px solid #1a0000 ;
  opacity:1;
  cursor:pointer;
  
}
.red{
 
  background:red;
  border-radius:0 100% 0 0;
  top:118px;
  left:420px;
  
}
.green{
  background:green;
  border-radius:100% 0 0 0;
  top:-82px;
  left:171px;
}
.blue{
  background:blue;
  border-radius:0 0  100% 0;
  left:420px;
}
.yellow{
  background:yellow;
   left:170px;
   top:-200px;
  border-radius:0 0  0 100% ;
}
.screen{
  position:relative;
  background:black;
  left:185px;
  border:1px solid black;
  top:-490px;
  height:100px;
  width: 500px;
  border-radius:1px;
  opacity:1;
}

.score,.play,.A{
  border:5px solid #1a0000;
  left:-5px;
   width: 250px;
  height: 200px;
  margin-left:15px;
  margin-top:0px;
  background:maroon;
  color:red;
  width: 150px;
  height: 100%;
  text-align:center;
  border-radius:17%;
  padding:8px;
  font-size:30px;
  letter-spacing:4px;
}

.highlight{
 border:20px solid #1a0000 ;
  opacity:1;
}
            
          
!
            
              $(document).ready(function() {
 
  $('[data-toggle="tooltip"]').tooltip(); 
  var $1 = $("#1");
  var $2 = $("#2");
  var $3 = $("#3");
  var $4 = $("#4");
  var delay = 400;
  var x = 0;
  var hs = 0;
  var playerplay = [];
  var level = 1;
  var playermoves = 0;
  var plays = [];
  var audios = ["http://s1download-universal-soundbank.com/mp3/sounds/20839.mp3"," http://s1download-universal-soundbank.com/mp3/sounds/20842.mp3", "http://s1download-universal-soundbank.com/mp3/sounds/20842.mp3", "http://s1download-universal-soundbank.com/mp3/sounds/20841.mp3"];

  $(".play").off('click').on('click', function() {
    var audio = new Audio(" http://s1download-universal-soundbank.com/mp3/sounds/20856.mp3");
   audio.play();
    $(audio).on("ended", function() {
    startGame();
});
       
    // timer = setInterval(startGame, delay);

    $("#off").off('click').on('click', function() {
      //console.log(timer);
      x = 0;

      playerplay = [];
      level = 1;
      playermoves = 0;
      plays = [];
     var audio = new Audio(" http://s1download-universal-soundbank.com/mp3/sounds/20856.mp3");
   audio.play();
    $(audio).on("ended", function() {
    startGame();
});
    });

  });

  function playerturn() {
   
    $(".board").off('click').on('click', function() {
 
      playermoves++;

      // console.log(playermoves < level, "level " + level);

      playerplay.push("#" + $(this).attr("id"));
      if (playerplay.length == level) {

//         console.log(playerplay, playermoves, "PLAYER INPUT");

//         console.log(arraysEqual(playerplay, plays), "EQUAL ARRAYS");

        if (arraysEqual(playerplay, plays)) {
          console.log("NEXT LEVEL");
          playermoves = 0;
          playerplay = [];
          if(level==14){
            delay=-300;
          }else if(level==20){
            var audio = new Audio("http://s1download-universal-soundbank.com/mp3/sounds/10968.mp3");
            $("h1").text("YOU WIN!");
   audio.play();
            
          }
          level++;

          // timer = setInterval(startGame, delay);

          startGame();

        } else {
          
           x = 0;

      playerplay = [];
      level = 1;
      playermoves = 0;
      plays = [];
          $(".score").text("You Lost!");
         var audio = new Audio(" http://s1download-universal-soundbank.com/mp3/sounds/12588.mp3");
     audio.play();
    $(audio).on("ended", function() {
    startGame();
});
          
  
      
        }

      }

    });

  }

  function startGame() {
     $(".score").text("Level: " + level);
    $("h1").text("Simon Game!");
    event.stopPropagation();
    console.log(x < level, "stargamelevel " + level, "X " + x);

    if (x < level) {
      x++;
      var move = Math.floor(Math.random() * 4 + 1);
      plays.push("#" + move);
      console.log(plays, x);
      animate(plays);
      startGame();

    } else {
       
      // clearInterval(timer);
      playerturn();
    }

  }
  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

  function animate(plays) {
    var i = 0;
    var interval = setInterval(function() {
      retry(plays[i]);
      i++;
      if (i >= plays.length) {
        clearInterval(interval);
      }
    }, delay*2);
  }

  function retry(x) {
    
    aux = x.replace(/\D/g,'');
    $(x).addClass("highlight");
    var audio = new Audio(audios[(aux)-1]);
   audio.play();
    window.setTimeout(function() {
      $(x).removeClass('highlight');
    }, delay+200);

  }

  //   function animate(x, i) {
  //       $(x).addClass("highlight") 
  //     window.setTimeout(function() {
  //  $(x).removeClass('highlight');
  //  }, delay);

  //  // console.log("animating",i,(delay+(delay*i)),x);
  //  // $(x).delay(delay+(delay*i)).queueAddClass("highlight").delay(delay).queueRemoveClass("highlight")

  //   }

  function arraysEqual(arr1, arr2) {
    if (arr1.length !== arr2.length)
      return false;
    for (var i = arr1.length; i--;) {
      if (arr1[i] !== arr2[i])
        return false;
    }

    return true;
  }

  $.fn.queueAddClass = function(className) {
    this.queue('fx', function(next) {
      $(this).addClass(className);
      next();
    });
    return this;
  };

  $.fn.queueRemoveClass = function(className) {
    this.queue('fx', function(next) {
      $(this).removeClass(className);
      next();
    });
    return this;
  };

});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console