🎮ArcadeLab

Vocab Quest - 单词勇者

by BraveGecko37
261 lines16.2 KB
▶ Play
<!--
ARCADELAB
title: Vocab Quest - 单词勇者
description: CET-4 单词闯关 RPG,剧情冒险 + 连击战斗 + 动画演出,纯单文件无依赖。
libraries:
-->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vocab Quest - 单词勇者</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Arial', 'Microsoft YaHei'; min-height: 100vh; background: #0a0a1a; overflow: hidden; user-select: none; -webkit-user-select: none; }

.scene { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; transition: opacity .8s; }
.hidden { opacity: 0; pointer-events: none; }

/* 菜单 */
#menu { background: radial-gradient(ellipse at center, #1a1a3e 0%, #0a0a1a 70%); }
#menu h1 { font-size: clamp(32px, 8vw, 56px); background: linear-gradient(135deg,#feca57,#ff6b6b,#48dbfb,#ff9ff3,#feca57); background-size: 300% 300%; -webkit-background-clip: text; -webkit-text-fill-color: transparent; animation: flow 3s ease infinite; }
@keyframes flow { 0%,100%{background-position:0 50%} 50%{background-position:100% 50%} }
.sub { color: #8899aa; letter-spacing: 4px; margin: 12px 0 36px; font-size: 14px; }
.btn { padding: 16px 44px; font-size: 20px; border: none; border-radius: 50px; cursor: pointer; font-weight: bold; background: linear-gradient(135deg,#feca57,#ff9f43); color: #2c2c2c; box-shadow: 0 8px 30px rgba(254,202,87,.4); transition: transform .2s; }
.btn:hover { transform: translateY(-4px) scale(1.04); }
.btn:active { transform: scale(0.96); }

/* 舞台 */
#stage { background: linear-gradient(180deg,#87CEEB 0%,#98FB98 55%,#90EE90 100%); }
#stage.night { background: linear-gradient(180deg,#0c0c2e 0%,#1a1a4e 60%,#2d2d6e 100%); }
.ground { position: absolute; bottom: 0; width: 100%; height: 22%; background: linear-gradient(180deg,#4a7c59,#2d5016); }
.char { position: absolute; bottom: 20%; font-size: clamp(48px,12vw,90px); transition: all .4s; z-index: 5; }
.player { left: 14%; }
.enemy { right: 14%; font-size: clamp(56px,14vw,110px); }
.walk { animation: walk .4s ease infinite; }
@keyframes walk { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-14px)} }
.eidle { animation: eidle 2s ease infinite; }
@keyframes eidle { 0%,100%{transform:translateY(0) rotate(0)} 25%{transform:translateY(-10px) rotate(-3deg)} 75%{transform:translateY(-10px) rotate(3deg)} }
.atk { animation: atk .4s ease; }
@keyframes atk { 0%{transform:translateX(0)} 50%{transform:translateX(90px) scale(1.2)} 100%{transform:translateX(0)} }
.hit { animation: hk .3s ease; }
@keyframes hk { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-14px)} 75%{transform:translateX(14px)} }
.die { animation: die .8s ease forwards; }
@keyframes die { to { transform: scale(0) rotate(180deg); opacity: 0; } }

/* 血条 */
.hpbars { position: absolute; top: 16px; left: 16px; right: 16px; display: flex; justify-content: space-between; gap: 12px; z-index: 20; }
.hpw { flex: 1; max-width: 240px; }
.hpl { color: #fff; font-weight: bold; text-shadow: 1px 1px 2px #000; margin-bottom: 4px; font-size: 13px; }
.bar { height: 16px; background: rgba(0,0,0,.5); border: 2px solid #fff; border-radius: 10px; overflow: hidden; }
.fill { height: 100%; transition: width .4s; }
.fp { background: linear-gradient(90deg,#56ab2f,#a8e6cf); }
.fe { background: linear-gradient(90deg,#f5576c,#ff6b6b); }

/* 战斗问答 */
#battle { background: linear-gradient(180deg,#1a1a2e,#16213e); }
.q { position: absolute; top: 14%; left: 50%; transform: translateX(-50%); text-align: center; width: 92%; z-index: 20; }
.cn { font-size: clamp(34px,9vw,52px); font-weight: 900; color: #fff; text-shadow: 0 4px 20px rgba(0,0,0,.5); }
.pos { color: #8899aa; margin-top: 4px; font-size: 14px; }
.opts { position: absolute; top: 34%; left: 50%; transform: translateX(-50%); width: 92%; max-width: 620px; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; z-index: 20; }
.ob { padding: 14px; border: 3px solid rgba(255,255,255,.2); border-radius: 12px; background: rgba(255,255,255,.08); color: #fff; font-size: clamp(14px,4vw,17px); font-weight: bold; cursor: pointer; transition: all .15s; pointer-events: auto; }
.ob:hover { border-color: #feca57; transform: translateY(-2px); }
.ob:active { transform: scale(0.96); }
.ob.correct { border-color: #56ab2f !important; background: linear-gradient(135deg,#56ab2f,#3d8b20) !important; pointer-events: none; }
.ob.wrong { border-color: #f5576c !important; background: linear-gradient(135deg,#f5576c,#c0392b) !important; pointer-events: none; }
.ob.reveal { border-color: #feca57 !important; background: linear-gradient(135deg,#feca57,#f39c12) !important; pointer-events: none; }

/* 对话 */
#dialog { position: absolute; bottom: 24px; left: 50%; transform: translateX(-50%); width: 90%; max-width: 680px; background: rgba(0,0,0,.9); border: 2px solid #feca57; border-radius: 16px; padding: 18px 22px; color: #fff; z-index: 100; cursor: pointer; }
#dialog:active { transform: translateX(-50%) scale(0.98); }
.dname { color: #feca57; font-weight: bold; margin-bottom: 6px; font-size: 15px; }
.dtext { font-size: clamp(14px,4vw,17px); line-height: 1.6; }
.dhint { color: #8899aa; font-size: 11px; text-align: right; margin-top: 8px; animation: blink 1s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

/* 特效 */
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 200; }
.slash { position: absolute; font-size: 54px; animation: sl .5s ease forwards; }
@keyframes sl { 0%{opacity:1;transform:scale(.5) rotate(0)} 50%{opacity:1;transform:scale(1.5) rotate(180deg)} 100%{opacity:0;transform:scale(2) rotate(360deg)} }
.float { position: absolute; font-size: 32px; font-weight: bold; animation: fu 1.1s ease forwards; }
@keyframes fu { to { opacity: 0; transform: translateY(-90px) scale(1.4); } }
.warn { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); font-size: clamp(40px,10vw,72px); color: #f5576c; font-weight: 900; text-shadow: 0 0 30px #f5576c; z-index: 300; animation: bw 2s ease; }
@keyframes bw { 0%{opacity:0;transform:translate(-50%,-50%) scale(0)} 20%{opacity:1;transform:translate(-50%,-50%) scale(1.4)} 80%{opacity:1} 100%{opacity:0;transform:translate(-50%,-50%) scale(.6)} }
.trans { position: fixed; inset: 0; background: #000; color: #fff; display: flex; align-items: center; justify-content: center; font-size: 26px; z-index: 500; opacity: 0; transition: opacity .6s; pointer-events: none; }
.trans.show { opacity: 1; }

/* 结果 */
#result { background: radial-gradient(ellipse at center,#1a2a4e,#0a0a1a); }
.rc { background: rgba(255,255,255,.05); border: 2px solid #feca57; border-radius: 20px; padding: 32px; text-align: center; max-width: 460px; width: 90%; }
.rc h2 { color: #feca57; font-size: 28px; margin-bottom: 16px; }
.stat { display: flex; justify-content: space-around; margin: 20px 0; }
.stat b { font-size: 30px; color: #feca57; display: block; }
.stat span { color: #8899aa; font-size: 12px; }
</style>
</head>
<body>

<div class="scene" id="menu">
  <h1>⚔️ Vocab Quest ⚔️</h1>
  <p class="sub">单 词 勇 者 之 旅</p>
  <button class="btn" id="startBtn">▶ 开始冒险</button>
</div>

<div class="scene hidden" id="stage">
  <div class="ground"></div>
  <div class="char player walk" id="player">🧙‍♂️</div>
  <div class="char enemy eidle" id="enemy">👾</div>
</div>

<div class="scene hidden" id="battle">
  <div class="hpbars">
    <div class="hpw"><div class="hpl">🧙‍♂️ 勇者 HP</div><div class="bar"><div class="fill fp" id="pHp" style="width:100%"></div></div></div>
    <div class="hpw" style="text-align:right"><div class="hpl" id="eName">👾 遗忘史莱姆</div><div class="bar"><div class="fill fe" id="eHp" style="width:100%"></div></div></div>
  </div>
  <div class="q"><div class="cn" id="qCn"></div><div class="pos" id="qPos"></div></div>
  <div class="opts" id="opts"></div>
</div>

<div class="scene hidden" id="result"><div class="rc" id="rc"></div></div>

<div id="dialog" class="hidden">
  <div class="dname" id="dName"></div>
  <div class="dtext" id="dText"></div>
  <div class="dhint">点击继续 ▼</div>
</div>

<div class="fx" id="fx"></div>
<div class="trans" id="trans"></div>

<script>
var STORY = [
  { name:"序章·记忆校园", enemy:"👾", eName:"遗忘史莱姆", night:false,
    dialogs:[
      {n:"🧙‍♂️ 你", t:"遗忘大陆边境——记忆校园。四级单词正在被遗忘魔王侵蚀……"},
      {n:"📖 导师", t:"用「艾宾浩斯之剑」斩断诅咒:每答对一词,就是一记重击。"},
      {n:"📖 导师", t:"连续答对触发连击,越快伤害越高。答错会掉血,准备战斗!"}
    ]},
  { name:"第一章·拼写森林", enemy:"🦹‍♂️", eName:"拼写哥布林", night:false,
    dialogs:[
      {n:"🦹‍♂️ 哥布林", t:"嘿嘿,你的单词表我要没收!"},
      {n:"🧙‍♂️ 你", t:"看我的大招——词义匹配斩!"}
    ]},
  { name:"终章·遗忘城堡", enemy:"🐉", eName:"遗忘魔王", night:true,
    dialogs:[
      {n:"🐉 魔王", t:"凡人,没复习的知识终归虚无!"},
      {n:"🧙‍♂️ 你", t:"艾宾浩斯之力,觉醒!"},
      {n:"📖 导师", t:"BOSS血厚,撑住连击!"}
    ]}
];

var WORDS = [
  {s:"vacation",c:"假期",pos:"n."},{s:"campus",c:"校园",pos:"n."},{s:"curriculum",c:"课程",pos:"n."},
  {s:"dormitory",c:"宿舍",pos:"n."},{s:"nutrition",c:"营养",pos:"n."},{s:"appetite",c:"食欲",pos:"n."},
  {s:"interview",c:"面试",pos:"n."},{s:"resume",c:"简历",pos:"n."},{s:"recruit",c:"招聘",pos:"v."},
  {s:"colleague",c:"同事",pos:"n."},{s:"digital",c:"数字的",pos:"adj."},{s:"algorithm",c:"算法",pos:"n."},
  {s:"innovation",c:"创新",pos:"n."},{s:"sustainable",c:"可持续的",pos:"adj."},{s:"pollution",c:"污染",pos:"n."},
  {s:"recycle",c:"回收",pos:"v."},{s:"companion",c:"同伴",pos:"n."},{s:"harmony",c:"和谐",pos:"n."}
];

var stage=0, pHp=100, eHp=50, eMax=50, pMax=100, combo=0, maxCombo=0, score=0;
var qs=[], qi=0, answered=false, dq=[], dcb=null;

function show(id){ document.querySelectorAll('.scene').forEach(function(s){s.classList.add('hidden');}); document.getElementById(id).classList.remove('hidden'); }
function trans(txt, cb){ var t=document.getElementById('trans'); t.textContent=txt; t.classList.add('show'); setTimeout(function(){cb&&cb(); setTimeout(function(){t.classList.remove('show');},300);},1100); }

function dialog(list, cb){
  dq=list.slice(); dcb=cb; document.getElementById('dialog').classList.remove('hidden'); nextD();
}
function nextD(){
  if(!dq.length){ document.getElementById('dialog').classList.add('hidden'); dcb&&dcb(); dcb=null; return; }
  var d=dq.shift(); document.getElementById('dName').textContent=d.n; document.getElementById('dText').textContent=d.t;
}

// 对话框点击 - 直接绑定,不用全局事件
document.getElementById('dialog').addEventListener('click', function(e){ e.stopPropagation(); nextD(); });
document.getElementById('dialog').addEventListener('touchend', function(e){ e.preventDefault(); nextD(); });

// 开始按钮
document.getElementById('startBtn').addEventListener('click', function(){ startJourney(); });

function startJourney(){
  stage=0; pHp=100; combo=0; maxCombo=0; score=0;
  show('stage');
  var s=STORY[0]; document.getElementById('enemy').textContent=s.enemy;
  document.getElementById('stage').classList.toggle('night', s.night);
  dialog(s.dialogs, function(){enterBattle(0);});
}

function enterBattle(i){
  stage=i; var s=STORY[i];
  eMax = i===2 ? 160 : 50 + i*30; eHp=eMax; pMax=100; pHp=100; combo=0; maxCombo=0; score=0;
  document.getElementById('eName').textContent=s.eName;
  document.getElementById('enemy').textContent=s.enemy;
  show('battle');
  if(i===2){ var w=document.createElement('div'); w.className='warn'; w.textContent='⚠️ BOSS WARNING'; document.body.appendChild(w); setTimeout(function(){w.remove();},2000); }
  buildQs(); nextQ();
}

function buildQs(){
  qs=[]; var n = stage===2?12:8;
  for(var i=0;i<n;i++){ var w=WORDS[Math.floor(Math.random()*WORDS.length)]; var o=[w.s]; while(o.length<4){var x=WORDS[Math.floor(Math.random()*WORDS.length)].s; if(!o.includes(x))o.push(x);} qs.push({w:w,o:o.sort(function(){return Math.random()-.5;})}); }
  qi=0;
}

function nextQ(){
  if(qi>=qs.length || eHp<=0 || pHp<=0){ endBattle(); return; }
  answered=false; var q=qs[qi];
  document.getElementById('qCn').textContent=q.w.c;
  document.getElementById('qPos').textContent=q.w.pos;
  var box=document.getElementById('opts'); box.innerHTML='';
  for(var j=0;j<q.o.length;j++){
    (function(op){
      var b=document.createElement('button'); b.className='ob'; b.textContent=op; b.onclick=function(){ans(op,b);}; box.appendChild(b);
    })(q.o[j]);
  }
  updateHp();
}

function ans(op, btn){
  if(answered) return; answered=true; var q=qs[qi]; var ok=op===q.w.s;
  if(ok){
    combo++; if(combo>maxCombo)maxCombo=combo; var dmg=10+combo*2; eHp=Math.max(0,eHp-dmg); score+=10+combo*2;
    btn.classList.add('correct'); float('-'+dmg,'#7CFC00',btn); slash(btn); atkAnim();
    if(combo>=3) float('🔥'+combo+'连击','#feca57',document.getElementById('enemy'));
  } else {
    combo=0; pHp=Math.max(0,pHp-15); btn.classList.add('wrong'); float('-15','#ff6b6b',document.getElementById('player')); enemyAtk();
    var allOpts=document.querySelectorAll('.ob'); for(var k=0;k<allOpts.length;k++){ if(allOpts[k].textContent===q.w.s)allOpts[k].classList.add('reveal'); }
  }
  updateHp(); qi++; setTimeout(nextQ,1200);
}

function atkAnim(){ var p=document.getElementById('player'); p.classList.add('atk'); setTimeout(function(){p.classList.remove('atk');},400); var e=document.getElementById('enemy'); setTimeout(function(){e.classList.add('hit'); setTimeout(function(){e.classList.remove('hit');},300);},200); }
function enemyAtk(){ var e=document.getElementById('enemy'); e.classList.add('atk'); setTimeout(function(){e.classList.remove('atk');},400); var p=document.getElementById('player'); setTimeout(function(){p.classList.add('hit'); setTimeout(function(){p.classList.remove('hit');},300);},200); }

function updateHp(){ document.getElementById('pHp').style.width=(pHp/pMax*100)+'%'; document.getElementById('eHp').style.width=(eHp/eMax*100)+'%'; }

function float(txt,color,el){ var r=el.getBoundingClientRect(); var f=document.createElement('div'); f.className='float'; f.textContent=txt; f.style.color=color; f.style.left=(r.left+r.width/2-20)+'px'; f.style.top=(r.top-10)+'px'; document.getElementById('fx').appendChild(f); setTimeout(function(){f.remove();},1100); }
function slash(el){ var r=el.getBoundingClientRect(); var s=document.createElement('div'); s.className='slash'; s.textContent=['⚡','💥','✨','🔥'][Math.floor(Math.random()*4)]; s.style.left=r.left+'px'; s.style.top=r.top+'px'; document.getElementById('fx').appendChild(s); setTimeout(function(){s.remove();},500); }

function endBattle(){
  if(eHp<=0){
    var e=document.getElementById('enemy'); e.classList.add('die');
    setTimeout(function(){
      if(stage<2){ trans('第'+(stage+2)+'章', function(){ var ns=STORY[stage+1]; show('stage'); document.getElementById('enemy').textContent=ns.enemy; document.getElementById('stage').classList.toggle('night',ns.night); dialog(ns.dialogs, function(){enterBattle(stage+1);}); }); }
      else showResult(true);
    },900);
  } else showResult(false);
}

function showResult(win){
  show('result');
  if(win){
    document.getElementById('rc').innerHTML='<h2>🏆 通关!遗忘魔王已败</h2><p style="color:#8899aa;margin:10px 0">你守护了单词大陆的记忆</p><div class="stat"><div><b>'+score+'</b><span>总分</span></div><div><b>'+maxCombo+'</b><span>最大连击</span></div></div><button class="btn" onclick="show(\'menu\')">🔄 再玩一次</button>';
  } else {
    document.getElementById('rc').innerHTML='<h2>💀 勇者倒下</h2><p style="color:#8899aa;margin:10px 0">遗忘太强,再战一次!</p><div class="stat"><div><b>'+score+'</b><span>得分</span></div></div><button class="btn" onclick="show(\'menu\')">🔄 重新挑战</button>';
  }
}
</script>
</body>
</html>

Game Source: Vocab Quest - 单词勇者

Creator: BraveGecko37

Libraries: none

Complexity: complex (261 lines, 16.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: vocab-quest-bravegecko37-mwksm4t6" to link back to the original. Then publish at arcadelab.ai/publish.