123

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.

            
              <header class="app-header">
  <h1 class="app-title">
    <img src="https://admiring-bose-b87e16.netlify.com/title.png" class="title-image" alt="もぐらたたきゲーム">
  </h1>
  <div class="play-info">
    <div class="score-board">
      SCORE
      <output class="score">0</output>
    </div>
  </div>
  <div class="progress"></div>
</header>
<div class="grass">
  <ul class="hole-container">
    <li class="hole"></li>
    <li class="hole"></li>
    <li class="hole"></li>
    <li class="hole"></li>
    <li class="hole"></li>
    <li class="hole"></li>
  </ul>
  <button class="start-btn">START</button>
  <div class="result-wrap">
    <div class="result-inner">
      <p class="result-label">あなたのスコアは</p>
      <div class="result"></div>
      <small class="result-unit">点です!</small>
      <img src="https://admiring-bose-b87e16.netlify.com/mole_face.png" class="result-image" alt="もぐら">

    </div>
  </div>
</div>
            
          
!
            
              body {
  font-family: 'Hiragino Kaku Gothic ProN','ヒラギノ角ゴ ProN',Meiryo,メイリオ,Helvetica,Arial,sans-serif;
  margin: 0;
  background: #99c410;
  position: relative;
}
.app-header {
  background: #b3e5fc;
  padding: 42px 0 0;
}
.app-title {
  text-align: center;
  margin: 0 0 20px 0;
}
.title-image {
  max-width: 280px;
}
.score-board {
  font-family: 'Source Code Pro', monospace;
  padding: 2px 10px;
  color: #e53935;
  text-align: center;
  background: #263238;
  font-size: 12px;
  border-radius: 3px;
  width: 100px;
  margin: auto;
}
.score {
  font-size: 42px;
}
.progress {
  margin: 20px 0 0 0;
  height: 6px;
  background: #e53935;
}
.grass {
    padding: 20px;
}
.hole-container {
  margin: 0 auto 20px auto;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
}
.hole {
  width: 80px;
  height: 100px;
  margin: 10px;
  background: #381504;
  background: #99c410;
  border-radius: 0 0 40px 40px;
  overflow: hidden;
  position: relative;
}
.hole:before {
  content: "";
  width: 80px;
  height: 80px;
  position: absolute;
  bottom:0;
  background: #381504;
  border-radius: 40px;
}
.mole {
  width: 60px;
  height: 100px;
  border-radius: 30px 30px 0 0;
  background: url(https://admiring-bose-b87e16.netlify.com/mole.png) no-repeat;
  background-size: cover;
  cursor: pointer;
  position: absolute;
  left: 50%;
  transform: translate(-50%, 0);
/*   animation: apper_mole 1.2s; */
}
@keyframes motion_1 {
  0% {
    bottom: -100px;
  }
  35% {
    bottom: 0;
  }
  64% {
    bottom: 0;
  }  
  100% {
    bottom: -100px;
  }
}
@keyframes motion_2 {
  0% {
    bottom: -100px;
  }
  50% {
    bottom: 0;
  }
  100% {
    bottom: -100px;
  }
}
@keyframes motion_3 {
  0% {
    bottom: -100px;
  }
  40% {
    bottom: 0;
  }
  80% {
    bottom: -100px;
  }
  90% {
    bottom: 0;
  }
  100% {
    bottom: -100px;
  }  
}
@keyframes motion_4 {
  0% {
    bottom: -100px;
  }
  60% {
    bottom: -100px;
  }
  80% {
    bottom: 0;
  }  
  100% {
    bottom: -100px;
  }
}  
  
.start-btn {
  font-family: 'Source Code Pro', monospace;
  display: block;
  cursor: pointer;
  background: #e53935;
  padding: 10px;
  text-align: center;
  width: 200px;
  color: #fff;
  border: none;
  margin: auto;
  border-radius: 10px;
  font-size: 24px;
  box-shadow: 0 10px 0 #ab000d;
}
.start-btn:focus {
  outline: none;
}
.result-wrap {
  display: none;
  width: 100%;
  height: 100vh;
  position: absolute;
  background: rgba(255, 255, 255, .9);
  text-align: center;
  top: 0;
  left: 0;
  color: #e53935;
}
.result-wrap.finish {
  display: block;
}
.result-inner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
}
.result-label {
  font-weight: bold;
  font-size: 18px;
  margin: 0 auto 6px auto;
  display: inline-block;
}
.result-unit {
  font-weight: bold;
  font-size: 18px;
  display: inline-block;
}
.retry-btn {
  font-family: 'Source Code Pro', monospace;
  display: block;
  cursor: pointer;
  background: #ff8f00;
  padding: 10px;
  text-align: center;
  width: 200px;
  color: #fff;
  border: none;
  margin: 30px auto 0;
  border-radius: 10px;
  font-size: 24px;
  box-shadow: 0 10px 0 #c56000;
}
.result {
  font-size: 48px;
  line-height: 1;
  font-weight: bold;
  margin-bottom: 6px;
  display: inline-block;
}
.result-image {
  display: block;
  margin: 50px auto 0;
  width: 140px;
  margin-top: 10px;
}
            
          
!
            
              'use strict';
    {
      const hole = document.querySelectorAll('.hole');
      const score_board = document.querySelector('.score');
      const start_btn = document.querySelector('.start-btn');
      const result_layer = document.querySelector('.result-wrap');
      const result = document.querySelector('.result');
      const progress = document.querySelector('.progress');
      const time_limit = 25;
      const motions = ['motion_1', 'motion_2', 'motion_3', 'motion_4'];
      let start_time;
      let left_percentage;
      let count_time;
      let repeat_time;
      let score = 0;
      let interval = 1500;
      let appear_interval = 2000;
      let mode = 'easy';
      let mode_bar;


      // 制限時間を管理する処理
      const countDown = () => {
        const d = new Date(Date.now() - start_time);
        const m = d.getMinutes();
        const s = d.getSeconds();
        left_percentage = Math.floor(((time_limit - s)/time_limit)*100);
        progress.style.width = `${left_percentage}%`;
        changeMode(s);
      };

      // 残り時間によって難易度を変える処理
      const changeMode = (s) => {
        if (s > time_limit - 1) {
          timeOut();
        } else {
          if (s > time_limit/3 && time_limit*2/3 > s) {
            if (mode !== 'normal') {
              mode = 'normal';
              interval = 1100;
              appear_interval = 1300;
            }
          } else if (s > time_limit*2/3) {
            if(mode !== 'hard') {
              mode = 'hard';
              // interval = 800;
              interval = 1200;
              // appear_interval = 900;
              appear_interval = 1400;
            }
          }
          count_time = setTimeout(() => {
            countDown();
          }, 10);
        };
      };
      // STARTボタンを押した時の処理
      start_btn.addEventListener('click', () => {
          start_time = Date.now();
          countDown();
          repeatMoveMole();
      });
      // 時間ぎれになった時の処理
      const timeOut = () => {
        clearTimeout(count_time);
        clearTimeout(repeat_time);
        displayResult();
      };
      // 結果を表示する処理
      const displayResult = () => {
        result.textContent = score;
        result_layer.classList.add('finish');
      }
      // モグラが現れたり消えたりする処理
      const moveMole = () => {
        let out_num = Math.floor(Math.random() * 6);
        hole.forEach((item, index) => {
          const mole = document.createElement('div');
          mole.classList.add('mole');
          // モグラのアニメーションを制御する処理
          if (mode == 'easy') {
            mole.style.animation = `motion_1 ${appear_interval/1000}s`;
          } else if (mode == 'normal') {
            mode_bar = Math.floor(Math.random() * 2);
            mole.style.animation = `${motions[mode_bar]} ${appear_interval/1000}s`;
          } else if (mode == 'hard') {
            mode_bar = Math.floor(Math.random() * 4);
            mole.style.animation = `${motions[mode_bar]} ${appear_interval/1000}s`;
          }

          if (index == out_num) {
            // モグラを消す処理
            hole[index].appendChild(mole);
            setTimeout(() => {
              if (hole[index].hasChildNodes()){
                hole[index].removeChild(mole);
              }
            }, appear_interval);
            hitMole(index);
          }
        });
      };
      // モグラのタップした時の処理
      const hitMole = index => {
        const mole = hole[index].firstElementChild;
        mole.addEventListener('click', () => {
            if (hole[index].hasChildNodes()) {
              score++;
              score_board.textContent = score;
              hole[index].removeChild(mole);
            }
        });
      };
      // 一定時間おきにモグラが出たり入ったりを繰り返す処理
      const repeatMoveMole = () => {
        moveMole();
        repeat_time = setTimeout(repeatMoveMole, interval);
      };

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