🎮ArcadeLab

低碳行为分类挑战

by PrismDolphin72
212 lines8.5 KB
▶ Play
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>低碳行为分类挑战</title>
<style>
  *{box-sizing:border-box}
  body{margin:0;padding:14px;font-family:"Microsoft YaHei",system-ui,sans-serif;
       background:#eef7f2;display:flex;justify-content:center}
  #wrap{width:100%;max-width:640px}
  h1{font-size:19px;text-align:center;color:#1f6f4a;margin:4px 0 8px}
  #hud{display:flex;justify-content:space-between;font-size:14px;color:#2b5c46;margin-bottom:4px}
  #bar{height:8px;background:#d6e9df;border-radius:6px;overflow:hidden;margin-bottom:10px}
  #barIn{height:100%;width:100%;background:#3fb27f;transition:width .2s linear}
  #stage{position:relative;height:340px;border:2px solid #b6dcc8;border-radius:14px;
         overflow:hidden;background:linear-gradient(#f4fcf7,#d9efe3);
         display:flex;align-items:center;justify-content:center}
  #card{width:80%;max-width:380px;padding:22px 16px;border-radius:16px;background:#fff;
        box-shadow:0 6px 18px rgba(0,0,0,.12);text-align:center;display:none;
        animation:pop .25s ease-out}
  @keyframes pop{from{transform:scale(.85);opacity:0}to{transform:scale(1);opacity:1}}
  #card .emoji{font-size:44px;line-height:1}
  #card .name{font-size:18px;color:#234;margin-top:8px;font-weight:bold}
  #card .tip{font-size:12px;color:#888;margin-top:6px;min-height:16px}
  .btnrow{display:flex;gap:12px;margin-top:14px}
  .btnrow button{flex:1;padding:12px;font-size:16px;border:none;border-radius:12px;
                 color:#fff;cursor:pointer;font-weight:bold}
  #lowBtn{background:#3fb27f}#lowBtn:hover{background:#349a6c}
  #highBtn{background:#e05a4f}#highBtn:hover{background:#c94940}
  #overlay{position:absolute;inset:0;background:rgba(255,255,255,.96);border-radius:12px;
           display:flex;flex-direction:column;align-items:center;justify-content:center;
           text-align:center;padding:18px}
  #overlay h2{color:#1f6f4a;margin:0 0 8px;font-size:19px}
  #overlay p{color:#41685a;font-size:14px;line-height:1.7;margin:3px 0}
  #overlay button{margin-top:14px;padding:10px 26px;font-size:16px;border:none;border-radius:999px;
                  background:#3fb27f;color:#fff;cursor:pointer}
  #overlay button:hover{background:#349a6c}
  .hide{display:none!important}
</style>
</head>
<body>
<div id="wrap">
  <h1>🌍 低碳行为分类挑战</h1>
  <div id="hud">
    <div>得分:<b id="score">0</b></div>
    <div>连击:<b id="combo">0</b></div>
    <div>剩余:<b id="time">40</b> 秒</div>
  </div>
  <div id="bar"><div id="barIn"></div></div>
  <div id="stage">
    <div id="card">
      <div class="emoji">🌱</div>
      <div class="name">准备中...</div>
      <div class="tip"></div>
    </div>
    <div id="overlay">
      <h2>低碳行为分类挑战</h2>
      <p>屏幕会出现一个行为,判断它是 <b style="color:#3fb27f">低碳</b> 还是 <b style="color:#e05a4f">高碳</b>。</p >
      <p>3秒内点击下方按钮,判断正确得分,连续正确有连击奖励!</p >
      <p>限时 40 秒,看看你能得多少分!</p >
      <button id="startBtn">开始游戏</button>
    </div>
  </div>
  <div class="btnrow">
    <button id="lowBtn">🌱 低碳</button>
    <button id="highBtn">🏭 高碳</button>
  </div>
</div>

<script>
(function(){
  const stage   = document.getElementById('stage');
  const card    = document.getElementById('card');
  const overlay = document.getElementById('overlay');
  const scoreEl = document.getElementById('score');
  const comboEl = document.getElementById('combo');
  const timeEl  = document.getElementById('time');
  const barIn   = document.getElementById('barIn');
  const lowBtn  = document.getElementById('lowBtn');
  const highBtn = document.getElementById('highBtn');
  const startBtn= document.getElementById('startBtn');

  const ITEMS = [
    {emoji:'🚲', name:'骑自行车上学', low:true},
    {emoji:'💡', name:'随手关灯', low:true},
    {emoji:'🛍️', name:'自带购物袋', low:true},
    {emoji:'🌳', name:'参与种树活动', low:true},
    {emoji:'☀️', name:'使用太阳能发电', low:true},
    {emoji:'🚿', name:'用洗菜水浇花', low:true},
    {emoji:'📄', name:'纸张双面打印', low:true},
    {emoji:'🚶', name:'步行去附近超市', low:true},
    {emoji:'❄️', name:'夏天空调开16度', low:false},
    {emoji:'💡', name:'长明灯不关', low:false},
    {emoji:'🥢', name:'使用一次性餐具', low:false},
    {emoji:'🚗', name:'短途也开车出行', low:false},
    {emoji:'📺', name:'电视待机不拔插头', low:false},
    {emoji:'🛍️', name:'大量使用塑料袋', low:false},
    {emoji:'💧', name:'水龙头一直开着', low:false},
    {emoji:'🍚', name:'经常浪费食物', low:false}
  ];

  let score=0, combo=0, timeLeft=40, running=false;
  let current=null, cardTimer=null, clockTimer=null, answered=false;
  let usedIndices=[];

  function updateHUD(){
    scoreEl.textContent = score;
    comboEl.textContent = combo;
    timeEl.textContent  = timeLeft;
    barIn.style.width   = Math.max(0, timeLeft/40*100) + '%';
  }

  function pickItem(){
    if(usedIndices.length >= ITEMS.length) usedIndices = [];
    let idx;
    do { idx = Math.floor(Math.random()*ITEMS.length); }
    while(usedIndices.includes(idx));
    usedIndices.push(idx);
    return ITEMS[idx];
  }

  function showCard(){
    if(!running) return;
    answered = false;
    current = pickItem();
    card.querySelector('.emoji').textContent = current.emoji;
    card.querySelector('.name').textContent  = current.name;
    card.querySelector('.tip').textContent   = '';
    card.style.display = 'block';
    card.style.animation = 'none';
    void card.offsetWidth;
    card.style.animation = 'pop .25s ease-out';

    clearTimeout(cardTimer);
    cardTimer = setTimeout(()=>{
      if(!answered && running) judge(null);
    }, 3000);
  }

  function judge(answer){
    if(!running || answered) return;
    answered = true;
    clearTimeout(cardTimer);

    if(answer === null){
      card.querySelector('.tip').textContent = '⏰ 超时!正确答案:' + (current.low?'低碳':'高碳');
      combo = 0;
      score = Math.max(0, score-5);
    } else if(answer === current.low){
      combo++;
      const gain = combo >= 3 ? 15 : 10;
      score += gain;
      card.querySelector('.tip').textContent = '✅ 正确!+' + gain + '分' + (combo>=3?'(连击奖励)':'');
    } else {
      combo = 0;
      score = Math.max(0, score-5);
      card.querySelector('.tip').textContent = '❌ 错误!正确答案:' + (current.low?'低碳':'高碳') + ',-5分';
    }

    updateHUD();
    setTimeout(()=>{
      if(running) showCard();
    }, 700);
  }

  function startGame(){
    score=0; combo=0; timeLeft=40; running=true; usedIndices=[];
    updateHUD();
    overlay.classList.add('hide');
    card.style.display = 'none';
    showCard();
    clearInterval(clockTimer);
    clockTimer = setInterval(()=>{
      timeLeft--;
      updateHUD();
      if(timeLeft <= 0) endGame();
    }, 1000);
  }

  function endGame(){
    running = false;
    clearTimeout(cardTimer);
    clearInterval(clockTimer);
    card.style.display = 'none';

    let level, tip;
    if(score >= 200){ level='🏆 低碳达人'; tip='判断非常准确!你已经是低碳生活小专家了。'; }
    else if(score >= 120){ level='🌿 低碳小能手'; tip='表现不错,再快一点就能拿满分啦!'; }
    else { level='🌱 环保新手'; tip='多留意生活中的低碳行为,继续加油!'; }

    overlay.innerHTML =
      '<h2>游戏结束</h2>' +
      '<p>最终得分:<b style="font-size:26px;color:#2e9e6b">'+score+'</b> 分</p >' +
      '<p>等级:'+level+'</p >' +
      '<p>'+tip+'</p >' +
      '<p style="font-size:12px;color:#888;margin-top:10px">' +
        '小知识:低碳生活从随手关灯、拧紧水龙头、绿色出行开始。' +
      '</p >' +
      '<button id="againBtn">再玩一次</button>';
    overlay.classList.remove('hide');
    document.getElementById('againBtn').addEventListener('click', startGame);
  }

  lowBtn.addEventListener('click', ()=>{ if(running && !answered) judge(true); });
  highBtn.addEventListener('click', ()=>{ if(running && !answered) judge(false); });
  startBtn.addEventListener('click', startGame);
  updateHUD();
})();
</script>
</body>
</html>

Game Source: 低碳行为分类挑战

Creator: PrismDolphin72

Libraries: none

Complexity: complex (212 lines, 8.5 KB)

The full source code is displayed above on this page.

Remix Instructions

To remix this game, copy the source code above and modify it. Add a ARCADELAB header at the top with "remix_of: game-prismdolphin72" to link back to the original. Then publish at arcadelab.ai/publish.