css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              <div class="big_circle">
  <div class='green_layer'>
    <button id='b1' class='green_button green'></button>
  </div>
  <div class='red_layer'>
    <button id='b2' class='red_button red'></button>
  </div>
  <div class='yellow_layer'>
    <button id='b3' class='yellow_button yellow'></button>
  </div>
  <div class='blue_layer'>
    <button id='b4' class='blue_button blue'></button>
  </div>
  <div class='center_background'>
    <div class='center_contents'>
      <p id='title'>Simone</p>
      <p id='on'>On</p>
      <div class='controls'>
        <div class='score'>
          <div class='strict-indicator'></div>
          <p id='score-display'></p>
        </div>
        <div class='switch'>     
          <div id='on-off-button'></div>
        </div>
        <div class='button-wrapper'>
          <p>Start</p>
          <p>Strict</p>
          <button class='start'></button>
          <button class='strict'></button>
        </div>
      </div>
      <p id='off'>Off</p>
    </div>
  </div>
</div>
<audio data-key="green" src="https://s3.amazonaws.com/simon-sounds/green.mp3"></audio> 
<audio data-key="red" src="https://s3.amazonaws.com/simon-sounds/red.mp3"></audio> 
<audio data-key="yellow" src="https://s3.amazonaws.com/simon-sounds/yellow.mp3"></audio> 
<audio data-key="blue" src="https://s3.amazonaws.com/simon-sounds/blue.mp3"></audio>
<audio data-key="wrong" src="https://s3.amazonaws.com/simon-sounds/wrong_5.mp3"></audio>
            
          
!
            
              /* Fonts */
@import url('https://fonts.googleapis.com/css?family=Passion+One:700');

@font-face {
    font-family: 'digital';
    src: url('https://dl.dropboxusercontent.com/s/yf8351upkn44ja1/digital-7__mono_.ttf?dl=0');
}

/*Variables*/
$gameBackground: 'https://dl.dropbox.com/s/ua6618ksmjihy36/bumpy-black-plastic-texture.jpg?dl=0';

$buttonBackground: 'https://dl.dropbox.com/s/mdnz7qglf0pgrrx/bumpy-white-plastic-texture.jpg?dl=0';

$widthHeight: 47%;

$border: 10px solid transparent;

$textColor: rgb(37, 34, 34);

/*Page background (wood)*/

body {
  background-image: url('https://dl.dropbox.com/s/diw61agg4mlxgzh/purty_wood.png?dl=0');
  display: flex;
  justify-content: center;
  margin-top: 2%;
  margin-bottom: 2%;
}

/*Game body*/

.big_circle {
  display: flex;
  flex-wrap: wrap;
  background-image: url($gameBackground);
  background-size: 100%;
  height: 90vmin;
  width: 90vmin;
  justify-content: space-around;
  align-items: center;
  padding: .3%;
  border-radius: 50%;
  position: relative;
  -webkit-box-shadow: 0px 0px 6px 3px rgba(0,0,0,0.75), inset 0px 0px 15px 0px rgba(69,67,69,1);
  -moz-box-shadow: 0px 0px 6px 3px rgba(0,0,0,0.75),inset 0px 0px 15px 0px rgba(69,67,69,1);
  box-shadow: 0px 0px 4px 2px rgba(0,0,0,0.75), inset 0px 0px 15px 0px rgba(69,67,69,1);
}

/*Big game buttons*/

//Green
.green_layer {
  background-image: url($buttonBackground);
  background-size: 130%;
  &:focus {
    outline: none;
  }
  height: $widthHeight;
  width: $widthHeight;
  border-top-left-radius: 100%;
}

.green_button, {
  height: 100%;
  width: 100%;
  border-top-left-radius: 100%;
  background: rgba(17, 116, 10, .8);
   &:active {
    background: rgba(49, 233, 36, .5);
  }
  &:focus {
    outline: none;
  }
}

.active_green {
    background: rgba(49, 233, 36, .5);
}

//Red
.red_layer {
  background-image: url($buttonBackground);
  background-size: 130%;
  &:focus {
    outline: none;
  }
  height: $widthHeight;
  width: $widthHeight;
  border-top-right-radius: 100%;
}

.red_button {
  height: 100%;
  width: 100%;
  border-top-right-radius: 100%;
  background: rgba(179, 19, 19, .8);
   &:active {
    background: rgba(238, 66, 32, .6);
  }
  &:focus {
    outline: none;
  }
}

.active_red {
    background: rgba(238, 66, 32, .6);
}

//Yellow
.yellow_layer {
  background-image: url($buttonBackground);
  background-size: 130%;
  &:focus {
    outline: none;
  }
  height: $widthHeight;
  width: $widthHeight;
  border-bottom-left-radius: 100%;
}

.yellow_button {
  height: 100%;
  width: 100%;
  border-bottom-left-radius: 100%;
  background: rgba(193, 196, 12, .8);
   &:active {
    background: rgba(238, 241, 59, .6);
  }
  &:focus {
    outline: none;
  }
}

.active_yellow {
    background: rgba(238, 241, 59, .6);
}

//Blue
.blue_layer {
  background-image: url($buttonBackground);
  background-size: 130%;
  &:focus {
    outline: none;
  }
  height: $widthHeight;
  width: $widthHeight;
  border-bottom-right-radius: 100%;
}

.blue_button {
  height: 100%;
  width: 100%;
  border-bottom-right-radius: 100%;
  background: rgba(22, 17, 150, .8);
   &:active {
    background: rgba(65, 60, 235, .6);
  }
  &:focus {
    outline: none;
  }
}

.active_blue {
    background: rgba(65, 60, 235, .6);
  }

.blue_button, .yellow_button, .red_button, .green_button {
 -webkit-box-shadow: inset 0px 0px 3px 3px rgba(40,40,40,0.75);
 -moz-box-shadow: inset 0px 0px 3px 3px rgba(40,40,40,0.75);
 box-shadow: inset 0px 0px 3px 3px rgba(40,40,40,0.75);
 border: none;
  &:active {
   -webkit-box-shadow: inset 0px 0px 4px 4px rgba(40,40,40,0.75);
   -moz-box-shadow: inset 0px 0px 4px 4px rgba(40,40,40,0.75);
   box-shadow: inset 0px 0px 4px 4px rgba(40,40,40,0.75);
  }
}

/*Center circle*/

.center_background {
  display: flex;
  position: absolute;
  width: 53%;
  height: 53%;
  border-radius: 50%;
  background-image: url($gameBackground);
  background-size: 200%;
  -webkit-box-shadow: inset 0px 0px 10px 5px rgba(40,40,40,0.75), 0px 0px 10px 5px rgba(40,40,40,0.75);
-moz-box-shadow: inset 0px 0px 10px 5px rgba(40,40,40,0.75), 0px 0px 10px 5px rgba(40,40,40,0.75);
box-shadow: inset 0px 0px 10px 5px rgba(40,40,40,0.75), 0px 0px 10px 5px rgba(40,40,40,0.75);
}

.center_contents {
  background-image: url('https://dl.dropbox.com/s/7owpfkwywhjqar2/Download%20this%20High%20Resolution%20Background%20Image..jpg?dl=0');
  background-size: 200%;
  width: 90%;
  height: 90%;
  border-radius: 50%;
  border: .1vmin solid black;
  margin: auto;
  #title {
    color: $textColor;
    text-align: center;
    font-family: 'Passion One', cursive;
    font-size: 10vmin;
    margin: 7vh 0 2vh 0;
  }
  #on, #off {
    color: $textColor;
    font-family: 'Passion One', cursive;
    text-align: center;
    font-size: 3vmin;
    margin: 0;
  }
}

.controls {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0 2vmin 0 2vmin;
}

.score {
  display: flex;
  width: 15vmin;
  height: 10vmin;
  background-color: black;
  border-radius: 25%;
  position: relative;
}

#score-display {
  background-color: rgba(124, 3, 7, .5);
  height: 9vmin;
  width: 14vmin;
  text-align: center;
  color: pink;
  margin: auto;
  font-family: 'digital';
  font-size: 7vmin;
  border-radius: 25%;
  line-height: 9vmin;
}

.strict-indicator {
  width: 10%;
  height: 15%;
  background-color: pink;
  border-radius: 50%;
  position: absolute;
  left: 13%;
  top: 10%;
  visibility: hidden;
}

.switch {
  display: flex;
  width: 3vmin;
  height: 10vmin;
  background-color: rgb(209, 37, 49);
  flex-direction: column-reverse;
  align-items: center;
  border: .2vmin solid black;
  border-radius: 10%;
  #on-off-button {
    height: 4vmin;
    width: 3vmin;
    background-color: $textColor;
    border: .1vmin solid black;
    border-radius: 10%;
  }
}

.button-wrapper {
  margin: 0;
  font-size: 3vmin;
  font-family: 'Passion One', cursive;
  display: flex;
  flex-wrap: wrap;
  width: 15vmin;
  justify-content: space-around;
  p {
    margin: 0 .1vmin 0 0;
  }
}

.start, .strict {
  display: inline;
  height: 5vmin;
  width: 5vmin;
  border-radius: 50%;
  border: none;
  margin: 0;
  outline: none;
  
}

.start {
  background-color: blue;
  -webkit-box-shadow: inset 0px 0px 10px 5px rgba(40,40,40,0.75);
  -moz-box-shadow: inset 0px 0px 10px 5px rgba(40,40,40,0.75);
  box-shadow: inset 0px 0px 4px 1px rgba(150,150,150,0.75);
  &:active {
    box-shadow: inset 0px 0px 9px 1px rgba(150,150,150,0.75);
  }
}

.strict {
  background-color: yellow;
  -webkit-box-shadow: inset 0px 0px 10px 5px rgba(40,40,40,0.75);
  -moz-box-shadow: inset 0px 0px 10px 5px rgba(40,40,40,0.75);
  box-shadow: inset 0px 0px 4px 1px rgba(40,40,40,0.75);
  &:active {
    box-shadow: inset 0px 0px 9px 1px rgba(40,40,40,0.75);
  }
}
            
          
!
            
              /* jshint esversion: 6*/
!function game() {
  
  //////******************TODO******************//////
   
  //Cosmetic fixes
  //Possibly add the code to speed up the sequence (code it into playSequence())
  //Possible special game start and winning button sequences
  //Organize code
         
  let gameOn = false;
  let start = false;
  let strict = false;
  let playerArray = [];
  let playerPosition = 0;
  let playerTurn = false;
  let sequenceArray = [];
  let computerPosition = 0;
  let computerTurn = false;
  let textPos = 0; //scroll
  
/////************GAME CODE************/////
  
  //Get a random number
  function randomNum(min , max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }
  
    //Generate the game sequence
  function generateSequence() {
    console.log('Begin Generate Sequence')
    computerPosition = 0;
    sequenceArray.push(randomNum(1,4));
    if (sequenceArray.length < 10) {
      displayUpdate('0' + sequenceArray.length);
    } else {
      displayUpdate(sequenceArray.length);
    }
    setTimeout(playSequence, 1000);
    console.log('End Generate Sequence')
  }
  
  //Play through the sequence array
  function playSequence() {
    console.log('Begin playSequence')
    if(!gameOn) {
      return
    }
    
    if(computerPosition == sequenceArray.length - 1) {
      $('#b'+ sequenceArray[computerPosition]).click();
    } else {
      $('#b'+ sequenceArray[computerPosition]).click();
      computerPosition++;
      setTimeout(playSequence, 500);
    }
    console.log('End playSequence');
  }
  
  //Check to see if the player selection matches the sequence
  let validate = () => {
    playerPosition = playerArray.length - 1; 
    if(playerArray[playerPosition] == sequenceArray[playerPosition]) {
      return true;
    } else {
      return false;
    }
  };
  
  //Update the display
  function displayUpdate(x) {
    $('#score-display').html(x);
  }
  
  //Scrolling Message
  function scroll(text) {
    let textArray = Array.from(text);   
    if(textPos < textArray.length -1){
      displayUpdate(textArray[textPos] + textArray[textPos+1]);
      textPos++;
      setTimeout(scroll, 600, text);
    } else if (sequenceArray.length < 1) {
      setTimeout(displayUpdate, 600, '01');
      textPos = 0;
    } else {
      return;
    }
  }
  
  //Resets all variables (used for on/off switch)
  function reset() {
    start = false;
    playerArray = [];
    playerPosition = 0;
    playerTurn = false;
    sequenceArray = [];
    computerPosition = 0;
  }
  
  //Do stuff when the correct button is pressed
  function playAudio(className) {    
    let audio = document.querySelector(`audio[data-key=${className}]`);
    audio.currentTime = 0;
    audio.playbackRate = 1;
    audio.play();
    $(`.${className}`).addClass(`active_${className}`);
    audio.addEventListener("ended", () => {
          $(`.${className}_button`).removeClass(`active_${className}`); 
    });
  }
  
  //Do stuff when the wrong button is pressed
  function playWrongAudio(className) {
    let wrongAudio = document.querySelector(`audio[data-key=${'wrong'}]`);
    wrongAudio.currentTime = 0;
    wrongAudio.playbackRate = 1;
    wrongAudio.play();
    $(`.${className}`).addClass(`active_${className}`);
    wrongAudio.addEventListener("ended", () => {
          $(`.${className}_button`).removeClass(`active_${className}`); 
    });
  }
  
/////*********BUTTONS CODE*********/////
  
  //Disable all buttons while the game is turned off
  $('button').prop('disabled', true);
  
  //Click handler for the on/off switch
  $('.switch').on('click', () => {
    if (gameOn){
      gameOn = false;
      strict = false;
      $('.switch').css({'background-color': 'rgb(209, 37, 49)', 'flex-direction': 'column-reverse'});
      $('button').prop('disabled', true);
      $('.strict-indicator').css('visibility', 'hidden');
      displayUpdate('');
      reset();
    } else {
      gameOn = true;
      $('.switch').css({'background-color': 'rgba(17, 116, 10, 1)', 'flex-direction': 'column'});
      $('button').prop('disabled', false);
      setTimeout(() => {displayUpdate('--')}, 500);
    } 
  });
  
  //Click Handlers for the Big Buttons
  function buttonClick() {
    console.log('CLICK START');
    console.log('playerTurn: ', playerTurn);
    console.log('playerArray: ', playerArray);
    
    let className = ($(this).attr('class').split(' ')[1]);
    
    //If it's the player's turn
    if(playerTurn){
      let buttonNumber = $(this).attr('id').split('')[1];
      playerArray.push(buttonNumber);
      //If the player gets it right on their 20th turn
      if(playerArray.length == sequenceArray.length && validate() && sequenceArray.length == 20) {
        console.log(1);
        playAudio(className);
        setTimeout(scroll, 1000, 'WINNER!!');
        setTimeout(displayUpdate, 7000, '--');
        setTimeout(reset, 7000);
        return;
      }
      //If the player makes a correct selection as the last choice for his/her turn
      if (playerArray.length == sequenceArray.length && validate()) {
        console.log(2);
        playAudio(className);
        playerPosition = 0;
        playerTurn = false;
        setTimeout(generateSequence, 500);
        playerArray = []; 
      //if it's the player's turn and he/she gets it wrong
      } else if (!validate()) {
        //If the game is in strict mode
        if(strict) {
          console.log(3);
          computerPosition = 0;
          playWrongAudio(className);
          reset();
          displayUpdate('--');
          
        //If the game is not in strict mode
        } else {
          console.log(4);
          computerPosition = 0;
          playWrongAudio(className);
          playerArray = [];
          playerTurn = false;
          setTimeout(playSequence, 2000);
        }
      } else {
        console.log(5);
        playAudio(className);
      }
    //If it isn't the player's turn
    } else {
      //and the computer has played the last selection in the sequence
      if (computerPosition == sequenceArray.length - 1) {
        console.log(6);
        playAudio(className);
        playerTurn = true;
      //If the computer presses a button  
      } else {
        console.log(7);
        playAudio(className);
      }
    }
    console.log('playerTurn: ', playerTurn);
    console.log('CLICK END');
  }

  //When a big button is clicked, run our button handler function
  $('.green_button, .red_button, .yellow_button, .blue_button').on('click', buttonClick);
  
  //Click Handler for start button
  $('.start').on('click', () => {
    if (gameOn && sequenceArray.length === 0 && !start){
      textPos = 0;
      setTimeout(generateSequence, 3500);
      scroll('START');
    }
    start = true;
  });
  
  //Click handler for strict button
    $('.strict').on('click', () => {
      if(strict) {
        strict = false;
        $('.strict-indicator').css('visibility', 'hidden');
      } else {
        strict = true;
        $('.strict-indicator').css('visibility', 'visible');
      }
  });
}();

            
          
!
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.
Loading ..................

Console