低碳小管家
by SonicGecko8057 lines5.2 KB
<!DOCTYPE html><html><head><meta charset="utf-8"><title>低碳小管家</title>
<style>
body{margin:0;padding:16px;font-family:"Microsoft YaHei",sans-serif;background:#eef7f2;display:flex;justify-content:center}
#w{width:100%;max-width:680px}h1{font-size:20px;text-align:center;color:#1f6f4a}
#h{display:flex;justify-content:space-between;font-size:15px;color:#2b5c46;margin-bottom:6px}
#b{height:10px;background:#d6e9df;border-radius:6px;overflow:hidden;margin-bottom:10px}
#bi{height:100%;width:100%;background:#3fb27f;transition:width .3s}
#s{position:relative;height:420px;border:2px solid #b6dcc8;border-radius:14px;overflow:hidden;background:linear-gradient(#eaf9f1,#d3eede)}
.i{position:absolute;width:76px;height:76px;border-radius:50%;background:#fff;box-shadow:0 3px 8px rgba(0,0,0,.12);display:flex;flex-direction:column;align-items:center;justify-content:center;cursor:pointer;user-select:none;transition:transform .1s}
.i:active{transform:scale(.9)}.i span{font-size:11px;color:#555;margin-top:2px}
.f{position:absolute;font-size:14px;font-weight:bold;pointer-events:none;animation:u .8s ease-out forwards;white-space:nowrap}
@keyframes u{to{transform:translateY(-44px);opacity:0}}
#o{position:absolute;inset:0;background:rgba(255,255,255,.95);border-radius:12px;display:flex;flex-direction:column;align-items:center;justify-content:center;text-align:center;padding:20px}
#o h2{color:#1f6f4a;margin:0 0 10px;font-size:20px}#o p{color:#41685a;font-size:14px;line-height:1.7;margin:4px 0}
button{margin-top:16px;padding:10px 28px;font-size:16px;border:none;border-radius:999px;background:#3fb27f;color:#fff;cursor:pointer}
button:hover{background:#349a6c}.hide{display:none!important}
</style></head><body>
<div id="w"><h1>🌍 低碳小管家</h1>
<div id="h"><div>得分:<b id="sc">0</b></div><div>连击:<b id="co">0</b></div><div>剩余:<b id="ti">30</b> 秒</div></div>
<div id="b"><div id="bi"></div></div>
<div id="s"><div id="o"><h2>找出身边的“浪费行为”!</h2>
<p>点击 💡长明灯、🚰漏水龙头、📺待机电视 → <b>+10分</b></p>
<p>别点 🌳种树、☀️太阳能、🚲骑车 → 点错 <b>-5分</b></p>
<p>限时30秒,看看你能得多少分!</p>
<button id="btn">开始游戏</button></div></div></div>
<script>
(function(){
const S=document.getElementById('s'),SC=document.getElementById('sc'),CO=document.getElementById('co'),TI=document.getElementById('ti'),BI=document.getElementById('bi'),O=document.getElementById('o');
const BAD=[{i:'💡',n:'长明灯',t:'随手关灯'},{i:'🚰',n:'漏水龙头',t:'拧紧龙头'},{i:'📺',n:'待机电视',t:'不用就断电'},{i:'❄️',n:'空调太低',t:'空调26℃'},{i:'🛍️',n:'塑料袋',t:'自带环保袋'}];
const GOOD=[{i:'🌳',n:'种树',t:'低碳行为,别点!'},{i:'☀️',n:'太阳能',t:'低碳行为,别点!'},{i:'🚲',n:'骑车出行',t:'低碳行为,别点!'}];
let score=0,combo=0,time=30,run=false,st=null,ct=null;
function hud(){SC.textContent=score;CO.textContent=combo;TI.textContent=time;BI.style.width=Math.max(0,time/30*100)+'%';}
function ft(x,y,txt,c){const d=document.createElement('div');d.className='f';d.textContent=txt;d.style.left=x+'px';d.style.top=y+'px';d.style.color=c;S.appendChild(d);setTimeout(()=>d.remove(),800);}
function spawn(){if(!run)return;const bad=Math.random()<.7,p=bad?BAD:GOOD,d=p[Math.floor(Math.random()*p.length)];
const el=document.createElement('div');el.className='i';if(!bad)el.style.background='#e6f7ee';
el.innerHTML='<div style="font-size:30px;line-height:1">'+d.i+'</div><span>'+d.n+'</span>';
const W=Math.max(60,S.clientWidth-86),H=Math.max(60,S.clientHeight-86);
el.style.left=(Math.random()*W)+'px';el.style.top=(Math.random()*H)+'px';S.appendChild(el);
let alive=true;const t=setTimeout(()=>{alive=false;el.remove();},1400);
el.onclick=()=>{if(!run||!alive)return;alive=false;clearTimeout(t);
const x=parseFloat(el.style.left)+38,y=parseFloat(el.style.top);
if(bad){combo++;const g=combo>=3?15:10;score+=g;ft(x,y,'+'+g+' '+d.t,'#2e9e6b');}
else{combo=0;score-=5;ft(x,y,'-5 '+d.t,'#d9534f');}
el.remove();hud();};}
function start(){score=0;combo=0;time=30;run=true;hud();O.classList.add('hide');
S.querySelectorAll('.i,.f').forEach(n=>n.remove());
clearInterval(st);clearInterval(ct);st=setInterval(spawn,620);
ct=setInterval(()=>{time--;hud();if(time<=0)end();},1000);}
function end(){run=false;clearInterval(st);clearInterval(ct);S.querySelectorAll('.i').forEach(n=>n.remove());
let lv,tip;if(score>=150){lv='🏆 低碳达人';tip='环保意识超棒!继续带动身边的人一起低碳生活。';}
else if(score>=90){lv='🌿 低碳小能手';tip='已经很不错了,手速再快一点就满分啦!';}
else{lv='🌱 环保新手';tip='多留意身边的浪费行为,随手关灯、关水龙头就是低碳!';}
O.innerHTML='<h2>游戏结束</h2><p>最终得分:<b style="font-size:24px;color:#2e9e6b">'+score+'</b> 分</p><p>等级:'+lv+'</p><p>'+tip+'</p><p style="font-size:12px;color:#888;margin-top:10px">小知识:关掉1盏长明灯一年约省电60度;拧紧1个漏水龙头一年可省水3吨。</p><button id="b2">再玩一次</button>';
O.classList.remove('hide');document.getElementById('b2').onclick=start;}
document.getElementById('btn').onclick=start;hud();
})();
</script></body></html>Game Source: 低碳小管家
Creator: SonicGecko80
Libraries: none
Complexity: moderate (57 lines, 5.2 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-sonicgecko80" to link back to the original. Then publish at arcadelab.ai/publish.