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

Details

Privacy

Go PRO Window blinds lowered to protect code. Code Editor with window blinds (raised) and a light blub turned on.

Keep it secret; keep it safe.

Private Pens are hidden everywhere on CodePen, except to you. You can still share them and other people can see them, they just can't find them through searching or browsing.

Upgrade to PRO

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.

Template

Make Template?

Templates are Pens that can be used to start other Pens. You can view all of your templates, or learn more in the documentation.

Screenshot

Screenshots of Pens are shown in mobile browsers, RSS feeds, to users who chose images instead of iframes, and in social media sharing.

This Pen is using the default Screenshot, generated by CodePen. Upgrade to PRO to upload your own thumbnail that will be displayed on previews of this pen throughout the site and when sharing to social media.

Upgrade to PRO

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.

HTML

              
                <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Mutimehemäng</title>
</head>

<body>
  <main>
    <header class="pealkiri">

      <h1>Skoor: <span class="skoor">0</span></h1>
      <button class="nupp" onclick="stardiMänguga()">
                  Alusta mänguga
        </button>
    </header>
    <section class="mutimullaHunnikud">
      <div class="auk">
        <div class="mutt"></div>
      </div>
      <div class="auk">
        <div class="mutt"></div>
      </div>
      <div class="auk">
        <div class="mutt"></div>
      </div>
      <div class="auk">
        <div class="mutt"></div>
      </div>
      <div class="auk">
        <div class="mutt"></div>
      </div>
      <div class="auk">
        <div class="mutt"></div>
      </div>
    </section>
  </main>
</body>

</html>
              
            
!

CSS

              
                body {
    background-color: #1e8537;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='12' viewBox='0 0 20 12'%3E%3Cg fill-rule='evenodd'%3E%3Cg id='charlie-brown' fill='%23355237' fill-opacity='1'%3E%3Cpath d='M9.8 12L0 2.2V.8l10 10 10-10v1.4L10.2 12h-.4zm-4 0L0 6.2V4.8L7.2 12H5.8zm8.4 0L20 6.2V4.8L12.8 12h1.4zM9.8 0l.2.2.2-.2h-.4zm-4 0L10 4.2 14.2 0h-1.4L10 2.8 7.2 0H5.8z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  min-height: 150vh; 
  padding: 0;
  margin: 0;
  font-family: 'Amatic SC', cursive;
}

html {
  box-sizing: border-box;
  font-size: 10px;
}

*, *:before, *:after {
  box-sizing: inherit;
}



h1 {
  text-align: center;
  font-size: 10rem;
  line-height: 1;
  margin-bottom: 0;
}

.skoor {
  color: aliceblue;
}
.mutimullaHunnikud {
  width: 600px;
  height: 400px;
  display: flex;
  flex-wrap: wrap;
  margin: 0 auto;
  cursor: pointer;
}

.auk {
  flex: 1 0 30%;
  overflow: hidden;
  position: relative;
}

.auk:after {
  display: block;
  background: url('https://svgshare.com/i/BCM.svg') bottom center no-repeat;
  background-size: contain;
  content: '';
  width: 100%;
  height:70px;
  position: absolute;
  z-index: 2;
  bottom: -30px;
}

.mutt {
  background: url('https://svgshare.com/i/8iE.svg') bottom center no-repeat;
  background-size: 60%;
  position: absolute;
  top: 100%;
  width: 100%;
  height: 100%;
  transition:all 0.4s;
}

.auk.piilub .mutt {
  top: 0;
}



.nupp {
  cursor: pointer;
  color: aliceblue;
  border: 1px solid black;
  color: black;
  font-family: 'Amatic SC', cursive;
  font-size: 4rem;
  height: 10rem;
  width: 35rem;
  border-radius: 5px;
  
}

.pealkiri {
  display: flex;
  justify-content: center;
  flex-direction: column;
  align-items: center;
}
              
            
!

JS

              
                var augud = document.querySelectorAll(".auk"); // Augud, mis on väljakul
var edetabel = document.querySelector(".skoor"); // Skoor
var mutid = document.querySelectorAll(".mutt"); // Mutimehed.
var viimaneAuk; // Viimane auk, kust mutimees välja piilus.
var aegTäis = false; // Ütleb, kas mäng saab läbi või mitte.
var skoor = 0; // Mängija skoor
var äraVajutaMituKorda = false;

function suvalineAeg(min, max) {
  // See funktsioon annab meile juhusliku aja.
  return Math.round(Math.random() * (max - min) + min);
}

function suvalineAuk(augud) {
  // See funktsioon annab meile suvalise augu, kust mutimees välja hüppab.
  const indeks = Math.floor(Math.random() * augud.length);
  const auk = augud[indeks];
  if (auk === viimaneAuk) {
    // Meil võib tekkida olukord, kus meil mutionu piilub uuesti august välja, mida me ei soovi.
    return suvalineAuk(augud);
  }
  viimaneAuk = auk;
  return auk;
}

function mutiOnuPiilub() {
  const aeg = suvalineAeg(200, 1000); // Kutsume välja eelnevalt tehtud funktsiooni
  const auk = suvalineAuk(augud); // Kutsume välja eelnevalt tehtud funktsiooni
  // Lisame classi piilub mutile.
  auk.classList.add('piilub');
  setTimeout(function() {
     // Eemaldame classi piilub mutile.
     auk.classList.remove('piilub');
    if (!aegTäis) {
      mutiOnuPiilub();
    }
  }, aeg);
}

function stardiMänguga() {
  if (!äraVajutaMituKorda) {
    // 1. Tee nii, et skoor oleks võrdne nulliga.
    skoor=0;
    
    // 2. Muudame ka kuvatava skoori nulli.
    edetabel.textContent = skoor;
    
    // 3. Muudame muutuja valeks, mis kontrollib aega.
    aegTäis = false;
    
    
    
    
    // Allolev kood on selleks, et mäng töötaks.
    äraVajutaMituKorda = true;
    mutiOnuPiilub();

    setTimeout(function() {
      aegTäis = true;
      äraVajutaMituKorda = false;
    }, 10000);
  }
}

function pihtas(e) { // Kui saame hiirega vastu mutionu;

  // 1. Iga kord kui saad pihta lisa +1 skoorile.
  skoor++;
  // 2. eemalda mutionu platsilt
  this.parentNode.classList.remove('piilub');
  // 3. ja uuendame edetabeli skoori.
  edetabel.textContent = skoor;

}

mutid.forEach(mutt => mutt.addEventListener("click", pihtas));

              
            
!
999px
Be the developer your linter thinks you are.

Console