Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="tab-pane text-center fade show active" id="simon" role="tabpanel" aria-labelledby="simon-tab">

      <!-- <h2 class="">Simon Game</h2> -->

      <div class="container">

        <div class="row justify-content-center mt-2">


          <div class="simonContainer">

            <div data-index-number="0" class="simonTab one p1"></div>

            <div data-index-number="1" class="simonTab two p2"></div>

            <div data-index-number="2" class="simonTab three p3"></div>

            <div data-index-number="3" class="simonTab four p4"></div>

            <div class="circle">
              <div class="container">
                <h2 class="mt-4 mb-4">Simon</h2>

                <div class="row smallDevice no-gutters">
                  <div class="col">
                    <p id="levelP">
                      <span id="level">1</span>
                    </p>
                  </div>
                  <div class="col">
                    <p class="simonBtn">
                      <span data-start="1" id="start"> </span>
                    </p>
                  </div>
                  <div class="col">
                    <p class="simonBtn">
                      <span data-strict="1" id="strict"> </span>
                    </p>
                  </div>
                </div>
                <div class="row no-gutters">
                  <div class="col">
                    <p>Count</p>
                  </div>
                  <div class="col">
                    <p>Start</p>
                  </div>
                  <div class="col">
                    <p>Strict</p>
                  </div>
                </div>
                <div class="row mt-3 justify-content-center">
                  <div class="form-group">
                    <label for="checkBox" class="switch">
                      <input id="checkBox" type="checkbox" name="checkBox">
                      <span class="slider round"></span>
                    </label>
                  </div>
                </div>
              </div>
            </div>

          </div>


        </div>



      </div>
    </div>
              
            
!

CSS

              
                .one {
  background-color: rgb(0, 255, 0);
  border-radius: 500px 0 0 0;
}

.two {
  background-color: rgb(0, 17, 255);
  border-radius: 0 500px 0 0;
}

.three {
  background-color: rgb(255, 230, 0);
  border-radius: 0 0 0 500px;
}

.four {
  background-color: rgb(255, 0, 0);
  border-radius: 0 0 500px 0;
}

.simonTab {
  width: 300px;
  height: 300px;
  opacity: 0.5;
  display: inline-block;
}

.simonTab:hover {
  cursor: pointer;
}

.simonContainer {
  position: relative;
  width: 660px;
  height: 660px;
  padding: 27px;
  border-radius: 100%;
  background: #f6f8f9;
  background: radial-gradient(
    ellipse at center,
    #f6f8f9 0%,
    #e5ebee 50%,
    #b6b6b6 80%,
    #555 100%
  );
}

.activatePanel {
  box-shadow: 0px 0 40px rgba(0, 0, 0, 0.7) !important;
  opacity: 1 !important;
}

.circle {
  width: 330px;
  height: 330px;
  border-radius: 100%;
  background-color: rgb(255, 255, 255);
  position: absolute;
  top: 167px;
  left: 166px;
  border: 7px solid #ececec;
}

.circle p {
  padding: 0;
  margin-top: 8px;
}

#level {
  padding: 6px 16px 6px 16px;
  background-color: red;
  border-radius: 20%;
  color: white;
  font-size: 1.3rem;
  font-weight: bold;
  border: 3px solid rgb(182, 182, 182);
}

#start,
#strict {
  padding: 6px 24px 6px 24px;
  background-color: rgb(145, 145, 145);
  border-radius: 50%;
  color: white;
  font-size: 1.3rem;
  font-weight: bold;
  border: 3px solid rgb(224, 224, 224);
  box-shadow: 0 4px 4px rgb(94, 94, 94);
}

.simonBtn:active {
  margin-top: 11px;
  margin-bottom: 17px;
}

.simonBtn:active #start {
  box-shadow: 0 0px 0px rgb(94, 94, 94) !important;
}

.simonBtn:active #strict {
  box-shadow: 0 0px 0px rgb(94, 94, 94) !important;
}

#start:active,
#strict:active ~ .col p {
  margin-top: 10px;
}

.activeButton {
  background-color: rgb(49, 219, 15) !important;
}

#start:hover,
#strict:hover {
  padding: 6px 24px 6px 24px;
  background-color: rgb(49, 219, 15);
  border-radius: 50%;
  color: white;
  font-size: 1.3rem;
  font-weight: bold;
  border: 3px solid rgb(224, 224, 224);
  cursor: pointer;
}

@media (max-width: 768px) {
  .circle {
    width: 200px;
    height: 200px;
    border-radius: 100%;
    background-color: rgb(255, 255, 255);
    position: absolute;
    top: 85px;
    left: 85px;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.2);
    border: 7px solid rgb(116, 116, 116);
  }
  .simonContainer {
    margin-top: 60px;
    position: relative;
    width: 375px;
    height: 375px;
    background-color: radial-gradient(
      circle,
      rgb(235, 235, 235),
      rgb(119, 119, 119)
    );
    padding: 15px;
    border-radius: 100%;
  }
  .simonTab {
    width: 167px;
    height: 167px;
    display: inline-block;
  }
  .smallDevice {
    z-index: -54;
    margin-top: 220px;
  }
  #start,
  #strict {
    padding: 6px 10px 6px 24px;
    background-color: rgb(133, 133, 133);
    border-radius: 50%;
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    border: 3px solid rgb(224, 224, 224);
    cursor: pointer;
  }
  #start:hover,
  #strict:hover {
    padding: 6px 10px 6px 24px;
    background-color: rgb(49, 219, 15);
    border-radius: 50%;
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    border: 3px solid rgb(224, 224, 224);
    cursor: pointer;
  }
  #levelP {
    margin-top: 12px;
  }
  #level {
    margin-top: 5px;
    padding: 3px 10px 3px 10px;
    background-color: red;
    border-radius: 20%;
    color: white;
    font-size: 1rem;
    font-weight: bold;
    border: 3px solid rgb(182, 182, 182);
  }
}

.switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.switch input {
  display: none;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  -webkit-transition: 0.4s;
  transition: 0.4s;
}

* {
  -webkit-transition: all 0.4s;
  transition: all 0.4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  -webkit-transition: 0.4s;
  transition: 0.4s;
}

input:checked + .slider {
  background-color: #2196f3;
}

input:focus + .slider {
  box-shadow: 0 0 1px #2196f3;
}

input:checked + .slider:before {
  -webkit-transform: translateX(26px);
  -ms-transform: translateX(26px);
  transform: translateX(26px);
}

/* Rounded sliders */

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

              
            
!

JS

              
                var allSominTabs = document.querySelectorAll(".simonTab");
var levelID = document.getElementById("level");
var startID = document.getElementById("start");
var strictID = document.getElementById("strict");
var switchID = document.getElementsByClassName("switch");
var strict = false;
var start = false;
var stopAll = false;
var playerMoves = [];
var actualMoves = [];
var level = 1;

document.addEventListener("DOMContentLoaded", function() {
  document.querySelector("#checkBox").addEventListener("change", changeHandler);
});

Array.from(allSominTabs).forEach(function(simonTab) {
  simonTab.addEventListener("mouseover", mouseIn);
});
Array.from(allSominTabs).forEach(function(simonTab) {
  simonTab.addEventListener("mouseout", mouseOut);
});
Array.from(allSominTabs).forEach(function(simonTab) {
  simonTab.addEventListener("click", mouseClick);
});

function mouseIn(simonTab) {
  simonTab.target.style.opacity = "0.8";
}

function mouseOut(simonTab) {
  simonTab.target.style.opacity = "0.5";
  simonTab.target.style.boxShadow = "0px 0 0px rgb(0, 183, 255)";
}

function mouseClick(simonTab) {
  if (stopAll) {
    return 0;
  }
  var index = Number(simonTab.target.dataset.indexNumber);
  simonTab.target.style.opacity = "1";
  playerMoves.push(index);
  sounds[index].sound.play();

  var tempArr = [];
  for (var i = 0; i < playerMoves.length; i++) {
    tempArr.push(actualMoves[i]);
  }

  // If wrong move...
  if (!arraysEqual(tempArr, playerMoves)) {
    simonTab.target.style.boxShadow = "0px 0 30px rgb(255, 0, 0)";
    wrongTab();
    startSecuence("NoChange");
  } else {
    simonTab.target.style.boxShadow = "0px 0 30px rgb(0, 183, 255)";
  }

  if (playerMoves.length === actualMoves.length) {
    if (arraysEqual(actualMoves, playerMoves)) {
      level++;
      levelID.textContent = level;
      startSecuence();
    } else {
      level = 1;
      actualMoves = [];
      wrongTab();
    }
  }
}

function wrongTab() {
  levelID.textContent = "Wrong!";
  sounds[4].sound.play();
  setTimeout(() => {
    levelID.textContent = level;
  }, 1000);
}

function flashTab(sTab) {
  setTimeout(() => {
    sounds[sTab].sound.play();
    allSominTabs[sTab].classList.toggle("activatePanel");
    setTimeout(() => {
      allSominTabs[sTab].classList.toggle("activatePanel");
    }, 500);
  }, 500);
}

function changeHandler() {
  if (checkBox.checked) {
    strictID.onclick = turnStrictOn;

    function turnStrictOn() {
      if (this.dataset.strict) {
        if (strict == false) {
          strict = true;
        } else {
          strict = false;
        }
      }
      this.classList.toggle("activeButton");
    }

    startID.onclick = turnStartOn;

    function turnStartOn() {
      if (this.dataset.start) {
        if (start == false) {
          stopAll = false;
          start = true;
          level = 1;
          actualMoves = [];
          startSecuence();
        } else {
          start = false;
          stopAll = true;
        }
      }
      this.classList.toggle("activeButton");
    }
  } else {
    level = 1;
    actualMoves = [];
  }
}

function startSecuence(str) {
  // 21 because level starts from 1 and ends in 21
  // same as from 0 to 20
  if (level == 21) {
    alert("You WON!!!");
    return 0;
  }
  if (str == "NoChange" && strict) {
    str = "Strict";
  }
  switch (str) {
    case "NoChange":
      break;

    case "Strict":
      resetAll();
      actualMoves.push(randomNr());
      break;

    default:
      actualMoves.push(randomNr());
      break;
  }

  playerMoves = [];
  var flashCounter = 0;
  var interval = setInterval(() => {
    flashTab(actualMoves[flashCounter]);

    if (flashCounter < actualMoves.length - 1) {
      flashCounter++;
    } else {
      clearInterval(interval);
    }
  }, 1000);
}

function resetAll() {
  level = 1;
  levelID.textContent = level;
  actualMoves = [];
}

function randomNr() {
  return Math.floor(Math.random() * 4);
}

var sounds = [
  {
    sound: new Howl({
      src: ["https://raw.githubusercontent.com/dardandemiri/arcade-games/gh-pages/assets/simon-sounds/simonSound1.mp3"]
    })
  },
  {
    sound: new Howl({
      src: ["https://raw.githubusercontent.com/dardandemiri/arcade-games/gh-pages/assets/simon-sounds/simonSound2.mp3"]
    })
  },
  {
    sound: new Howl({
      src: ["https://raw.githubusercontent.com/dardandemiri/arcade-games/gh-pages/assets/simon-sounds/simonSound3.mp3"]
    })
  },
  {
    sound: new Howl({
      src: ["https://raw.githubusercontent.com/dardandemiri/arcade-games/gh-pages/assets/simon-sounds/simonSound4.mp3"]
    })
  },
  {
    sound: new Howl({
      src: ["https://raw.githubusercontent.com/dardandemiri/arcade-games/gh-pages/assets/simon-sounds/wrong.wav"]
    })
  }
];

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;
}

              
            
!
999px

Console