Word Pixel: CET-4 Quest
by BoldBunny94736 lines23.3 KB
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<title>Word Pixel: CET-4 Quest</title>
<style>
/* ============ 全局 ============ */
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: 'Courier New', monospace;
background: #1a1a2e;
color: #eee;
overflow: hidden;
touch-action: none;
user-select: none;
}
.screen {
display: none;
width: 100vw;
height: 100vh;
position: fixed;
top: 0; left: 0;
}
.screen.active { display: flex; flex-direction: column; }
/* ============ 像素字体标题 ============ */
.pixel-title {
font-size: 24px;
text-align: center;
color: #ffd700;
text-shadow: 3px 3px 0 #ff6b35;
letter-spacing: 2px;
margin: 20px 0;
}
/* ============ 主菜单 ============ */
#menu-screen {
background: linear-gradient(180deg, #16213e 0%, #0f3460 100%);
align-items: center;
justify-content: center;
}
.menu-btn {
width: 220px;
height: 50px;
margin: 10px;
background: #e94560;
border: 3px solid #fff;
color: #fff;
font-size: 18px;
font-family: inherit;
cursor: pointer;
box-shadow: 4px 4px 0 #900;
}
.menu-btn:active { transform: translate(2px,2px); box-shadow: 2px 2px 0 #900; }
/* ============ 地图 ============ */
#map-screen {
background: #2d6a4f;
position: relative;
}
#map-canvas {
width: 100%; height: calc(100% - 60px);
position: relative;
overflow: hidden;
}
.tile-ground { background: #40916c; }
.tile-grass { background: #52b788; }
/* 玩家 */
#player {
width: 32px; height: 32px;
position: absolute;
transition: none;
font-size: 28px;
line-height: 32px;
text-align: center;
z-index: 10;
}
/* 怪物 */
.monster {
width: 32px; height: 32px;
position: absolute;
font-size: 26px;
line-height: 32px;
text-align: center;
z-index: 5;
animation: monsterBounce 1s infinite alternate;
}
@keyframes monsterBounce {
from { transform: translateY(0); }
to { transform: translateY(-4px); }
}
/* HUD */
#hud {
height: 60px;
background: #1b4332;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0 10px;
font-size: 13px;
border-top: 2px solid #52b788;
}
.hp-bar-bg {
width: 100px; height: 14px;
background: #333;
border: 1px solid #fff;
}
.hp-bar-fill {
height: 100%; background: #e94560;
transition: width 0.3s;
}
.timer-text { color: #ffd700; font-size: 18px; font-weight: bold; }
/* 虚拟方向键 */
#dpad {
position: fixed;
bottom: 20px; left: 20px;
display: grid;
grid-template-columns: 40px 40px 40px;
grid-template-rows: 40px 40px 40px;
gap: 4px;
z-index: 100;
}
#dpad button {
width: 40px; height: 40px;
background: rgba(255,255,255,0.3);
border: 2px solid #fff;
color: #fff;
font-size: 18px;
cursor: pointer;
}
#dpad .up { grid-column: 2; grid-row: 1; }
#dpad .left { grid-column: 1; grid-row: 2; }
#dpad .right { grid-column: 3; grid-row: 2; }
#dpad .down { grid-column: 2; grid-row: 3; }
/* ============ 战斗 ============ */
#battle-screen {
background: #0d1b2a;
align-items: center;
}
.battle-area {
flex: 1;
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
position: relative;
}
.monster-display {
font-size: 64px;
margin-bottom: 10px;
animation: monsterIdle 2s infinite;
}
@keyframes monsterIdle {
0%,100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
.word-display {
font-size: 28px;
color: #ffd700;
margin: 10px 0;
letter-spacing: 3px;
}
.speak-btn {
background: #0f3460;
border: 2px solid #4fc3f7;
color: #4fc3f7;
padding: 6px 14px;
font-size: 14px;
cursor: pointer;
margin-bottom: 10px;
}
.options-area {
width: 90%;
max-width: 360px;
}
.option-btn {
width: 100%;
height: 48px;
margin: 6px 0;
background: #16213e;
border: 2px solid #e94560;
color: #eee;
font-size: 16px;
font-family: inherit;
cursor: pointer;
}
.option-btn:hover { background: #e94560; }
.option-btn.correct { background: #2d6a4f !important; border-color: #52b788; }
.option-btn.wrong { background: #900 !important; }
/* 拼写区 */
.spell-area {
width: 90%; max-width: 360px;
text-align: center;
}
.spell-hint {
font-size: 18px; color: #aaa; margin-bottom: 8px;
}
.spell-blanks {
font-size: 24px; letter-spacing: 6px; margin-bottom: 10px;
color: #ffd700;
}
.spell-letters {
display: flex; flex-wrap: wrap; justify-content: center; gap: 6px;
}
.letter-btn {
width: 36px; height: 36px;
background: #0f3460; border: 2px solid #4fc3f7;
color: #fff; font-size: 16px; cursor: pointer;
}
.letter-btn:active { background: #4fc3f7; color: #000; }
/* 战斗消息 */
.battle-msg {
position: absolute;
top: 40%;
font-size: 22px;
font-weight: bold;
text-shadow: 2px 2px 0 #000;
animation: msgFloat 1s forwards;
pointer-events: none;
}
@keyframes msgFloat {
0% { opacity: 1; transform: translateY(0); }
100% { opacity: 0; transform: translateY(-40px); }
}
/* 血条 */
.battle-hud {
width: 100%; padding: 10px;
display: flex; justify-content: space-between;
font-size: 12px;
}
.battle-hp {
width: 45%; height: 16px; background: #333; border: 1px solid #fff;
}
.battle-hp-fill { height: 100%; transition: width 0.3s; }
/* ============ 结算 ============ */
#result-screen {
background: #1a1a2e;
align-items: center;
padding: 20px;
overflow-y: auto;
}
.result-card {
background: #16213e;
border: 2px solid #ffd700;
padding: 20px; width: 90%; max-width: 400px;
text-align: center;
}
.result-card h2 { color: #ffd700; margin-bottom: 15px; }
.result-stat { font-size: 16px; margin: 8px 0; }
.word-review { margin-top: 15px; text-align: left; max-height: 200px; overflow-y: auto; }
.word-review div { padding: 4px 0; border-bottom: 1px solid #333; font-size: 14px; }
.result-btns { margin-top: 15px; display: flex; gap: 10px; justify-content: center; }
/* ============ 单词书 ============ */
#wordbook-screen {
background: #1a1a2e;
padding: 20px;
overflow-y: auto;
}
.wordbook-list { width: 100%; max-width: 500px; margin: 0 auto; }
.wordbook-item {
background: #16213e; padding: 10px; margin: 6px 0;
border-left: 3px solid #e94560; font-size: 14px;
}
.wordbook-item .en { color: #ffd700; font-weight: bold; }
.wordbook-item .zh { color: #aaa; }
.wordbook-item button {
float: right; background: #0f3460; border: 1px solid #4fc3f7;
color: #4fc3f7; padding: 2px 8px; cursor: pointer; font-size: 12px;
}
/* ============ 通用按钮 ============ */
.btn {
padding: 10px 20px;
background: #e94560;
border: 2px solid #fff;
color: #fff;
font-size: 16px;
font-family: inherit;
cursor: pointer;
}
.btn:active { transform: translate(1px,1px); }
</style>
</head>
<body>
<!-- ===== 主菜单 ===== -->
<div id="menu-screen" class="screen active">
<div class="pixel-title">Word Pixel<br>CET-4 Quest</div>
<button class="menu-btn" onclick="startGame()">⚔️ 开始冒险</button>
<button class="menu-btn" onclick="showScreen('wordbook-screen')">📖 单词书</button>
<button class="menu-btn" onclick="toggleMute()">🔊 设置</button>
<p style="margin-top:20px;font-size:12px;color:#aaa;">四级基础词汇 · RPG记忆小游戏</p>
</div>
<!-- ===== 地图 ===== -->
<div id="map-screen" class="screen">
<div id="map-canvas"></div>
<div id="hud">
<div>❤️ <span id="hud-hp">100</span><br><div class="hp-bar-bg"><div class="hp-bar-fill" id="hp-fill" style="width:100%"></div></div></div>
<div class="timer-text" id="timer">04:00</div>
<div>Lv.<span id="hud-lv">1</span> XP:<span id="hud-xp">0</span></div>
</div>
<!-- 虚拟方向键 -->
<div id="dpad">
<button class="up" onclick="movePlayer(0,-1)">▲</button>
<button class="left" onclick="movePlayer(-1,0)">◀</button>
<button class="right" onclick="movePlayer(1,0)">▶</button>
<button class="down" onclick="movePlayer(0,1)">▼</button>
</div>
</div>
<!-- ===== 战斗 ===== -->
<div id="battle-screen" class="screen">
<div class="battle-hud">
<div>👹 怪物 HP<br><div class="battle-hp"><div class="battle-hp-fill" id="monster-hp" style="width:100%;background:#e94560"></div></div></div>
<div>🧙 玩家 HP<br><div class="battle-hp"><div class="battle-hp-fill" id="player-hp" style="width:100%;background:#52b788"></div></div></div>
</div>
<div class="battle-area" id="battle-area">
<div class="monster-display" id="battle-monster">👹</div>
<div class="word-display" id="battle-word"></div>
<button class="speak-btn" onclick="speakWord()">🔊 发音</button>
<div class="options-area" id="options-area"></div>
<div class="spell-area" id="spell-area" style="display:none">
<div class="spell-hint" id="spell-hint"></div>
<div class="spell-blanks" id="spell-blanks"></div>
<div class="spell-letters" id="spell-letters"></div>
</div>
</div>
</div>
<!-- ===== 结算 ===== -->
<div id="result-screen" class="screen">
<div class="result-card">
<h2>🎉 本局结算</h2>
<div class="result-stat">⏱️ 存活时间:<span id="res-time"></span></div>
<div class="result-stat">⚔️ 击败怪物:<span id="res-kills"></span></div>
<div class="result-stat">📖 掌握单词:<span id="res-words"></span></div>
<div class="result-stat">🎯 正确率:<span id="res-acc"></span></div>
<div class="word-review" id="res-review"></div>
<div class="result-btns">
<button class="btn" onclick="startGame()">再来一局</button>
<button class="btn" onclick="showScreen('menu-screen')">返回菜单</button>
</div>
</div>
</div>
<!-- ===== 单词书 ===== -->
<div id="wordbook-screen" class="screen">
<div class="pixel-title">📖 单词书</div>
<div class="wordbook-list" id="wordbook-list"></div>
<div style="text-align:center;margin-top:15px;">
<button class="btn" onclick="showScreen('menu-screen')">返回</button>
</div>
</div>
<script>
// ============ 词库 ============
const WORDS = [
{id:1,en:"abandon",zh:"放弃",example:"He abandoned his car."},
{id:2,en:"ability",zh:"能力",example:"She has the ability to win."},
{id:3,en:"abroad",zh:"在国外",example:"He studied abroad."},
{id:4,en:"absence",zh:"缺席",example:"His absence was noticed."},
{id:5,en:"absolute",zh:"绝对的",example:"absolute power"},
{id:6,en:"absorb",zh:"吸收",example:"Plants absorb water."},
{id:7,en:"abstract",zh:"抽象的",example:"abstract art"},
{id:8,en:"abundant",zh:"丰富的",example:"abundant food"},
{id:9,en:"academic",zh:"学术的",example:"academic year"},
{id:10,en:"accelerate",zh:"加速",example:"accelerate the car"},
{id:11,en:"access",zh:"进入",example:"access the building"},
{id:12,en:"accommodate",zh:"容纳",example:"The hotel accommodates 200 guests."},
{id:13,en:"accompany",zh:"陪伴",example:"She accompanied me."},
{id:14,en:"accomplish",zh:"完成",example:"accomplish a task"},
{id:15,en:"account",zh:"账户",example:"bank account"},
{id:16,en:"accurate",zh:"准确的",example:"accurate information"},
{id:17,en:"accuse",zh:"指责",example:"He accused her of lying."},
{id:18,en:"accustom",zh:"使习惯",example:"accustom to the cold"},
{id:19,en:"achieve",zh:"达到",example:"achieve a goal"},
{id:20,en:"acknowledge",zh:"承认",example:"He acknowledged his mistake."}
];
// ============ 全局状态 ============
let state = {
screen: 'menu-screen',
playerX: 180, playerY: 200,
hp: 100, maxHp: 100,
lv: 1, xp: 0,
timeLeft: 240, timerInterval: null,
monsters: [], currentMonster: null,
battleState: 'choose', // choose | spell
consecutiveCorrect: 0,
spellAnswer: '', spellInput: '',
killed: 0, totalQuestions: 0, correctAnswers: 0,
masteredWords: [], sessionWords: [],
mute: false
};
// ============ 屏幕切换 ============
function showScreen(id) {
document.querySelectorAll('.screen').forEach(s => s.classList.remove('active'));
document.getElementById(id).classList.add('active');
state.screen = id;
if (id === 'wordbook-screen') renderWordbook();
}
// ============ 开始游戏 ============
function startGame() {
state.hp = 100; state.lv = 1; state.xp = 0;
state.timeLeft = 240; state.killed = 0;
state.totalQuestions = 0; state.correctAnswers = 0;
state.sessionWords = [];
state.playerX = 180; state.playerY = 200;
spawnMonsters();
renderMap();
showScreen('map-screen');
updateHUD();
startTimer();
}
// ============ 倒计时 ============
function startTimer() {
clearInterval(state.timerInterval);
state.timerInterval = setInterval(() => {
state.timeLeft--;
updateTimerDisplay();
if (state.timeLeft <= 0) {
clearInterval(state.timerInterval);
endGame();
}
}, 1000);
}
function updateTimerDisplay() {
let m = Math.floor(state.timeLeft / 60);
let s = state.timeLeft % 60;
document.getElementById('timer').textContent =
(m<10?'0'+m:m) + ':' + (s<10?'0'+s:s);
}
// ============ 地图怪物生成 ============
function spawnMonsters() {
state.monsters = [];
const mapW = window.innerWidth, mapH = window.innerHeight - 60;
for (let i = 0; i < 7; i++) {
let w = WORDS[Math.floor(Math.random() * WORDS.length)];
state.monsters.push({
word: w, x: 40 + Math.random() * (mapW - 80),
y: 40 + Math.random() * (mapH - 80),
dead: false, emoji: ['👹','👺','🧟','💀','👻','🤡','👽'][i%7]
});
}
}
// ============ 渲染地图 ============
function renderMap() {
const canvas = document.getElementById('map-canvas');
canvas.innerHTML = `<div id="player">🧙♂️</div>`;
document.getElementById('player').style.left = state.playerX + 'px';
document.getElementById('player').style.top = state.playerY + 'px';
state.monsters.forEach((m, i) => {
if (m.dead) return;
let el = document.createElement('div');
el.className = 'monster';
el.textContent = m.emoji;
el.style.left = m.x + 'px';
el.style.top = m.y + 'px';
el.id = 'monster-' + i;
canvas.appendChild(el);
});
}
// ============ 玩家移动 ============
function movePlayer(dx, dy) {
if (state.screen !== 'map-screen') return;
state.playerX += dx * 20; state.playerY += dy * 20;
const maxW = window.innerWidth - 32, maxH = window.innerHeight - 60 - 32;
state.playerX = Math.max(0, Math.min(maxW, state.playerX));
state.playerY = Math.max(0, Math.min(maxH, state.playerY));
renderMap();
checkCollisions();
}
document.addEventListener('keydown', e => {
if (state.screen !== 'map-screen') return;
if (e.key === 'ArrowUp' || e.key === 'w') movePlayer(0,-1);
if (e.key === 'ArrowDown' || e.key === 's') movePlayer(0,1);
if (e.key === 'ArrowLeft' || e.key === 'a') movePlayer(-1,0);
if (e.key === 'ArrowRight' || e.key === 'd') movePlayer(1,0);
});
// ============ 碰撞检测 ============
function checkCollisions() {
state.monsters.forEach((m, i) => {
if (m.dead) return;
let dx = Math.abs(state.playerX - m.x), dy = Math.abs(state.playerY - m.y);
if (dx < 35 && dy < 35) {
m.dead = true;
startBattle(m);
}
});
}
// ============ 战斗 ============
function startBattle(monster) {
clearInterval(state.timerInterval);
state.currentMonster = monster;
state.battleState = 'choose';
state.consecutiveCorrect = 0;
showScreen('battle-screen');
document.getElementById('battle-monster').textContent = monster.emoji;
document.getElementById('battle-word').textContent = monster.word.en;
document.getElementById('monster-hp').style.width = '100%';
document.getElementById('player-hp').style.width = (state.hp/state.maxHp*100)+'%';
document.getElementById('spell-area').style.display = 'none';
document.getElementById('options-area').style.display = 'block';
generateOptions();
}
function generateOptions() {
const w = state.currentMonster.word;
let opts = [w.zh];
while (opts.length < 3) {
let r = WORDS[Math.floor(Math.random()*WORDS.length)].zh;
if (!opts.includes(r)) opts.push(r);
}
opts.sort(() => Math.random() - 0.5);
const area = document.getElementById('options-area');
area.innerHTML = '';
opts.forEach(o => {
let btn = document.createElement('button');
btn.className = 'option-btn';
btn.textContent = o;
btn.onclick = () => selectOption(o, btn);
area.appendChild(btn);
});
}
function selectOption(choice, btn) {
const correct = choice === state.currentMonster.word.zh;
state.totalQuestions++;
if (correct) {
state.correctAnswers++;
state.consecutiveCorrect++;
btn.classList.add('correct');
showBattleMsg('Correct! ⚔️', '#52b788');
// 怪物掉血
let mhp = document.getElementById('monster-hp');
let curW = parseInt(mhp.style.width) || 100;
mhp.style.width = Math.max(0, curW - 35) + '%';
if (curW - 35 <= 0) {
setTimeout(battleWin, 600);
} else if (state.consecutiveCorrect >= 2) {
setTimeout(startSpell, 600);
}
} else {
state.consecutiveCorrect = 0;
btn.classList.add('wrong');
showBattleMsg('再想想~ 💥', '#e94560');
// 玩家掉血
state.hp -= 20;
document.getElementById('player-hp').style.width = Math.max(0, state.hp/state.maxHp*100)+'%';
if (state.hp <= 0) setTimeout(battleLose, 600);
}
}
function startSpell() {
state.battleState = 'spell';
state.spellInput = '';
const w = state.currentMonster.word;
// 生成残缺
let en = w.en;
let blanks = en.split('').map((c,i) => (i%2===0 && i>0 && i<en.length-1) ? '_' : c).join('');
state.spellAnswer = en;
document.getElementById('options-area').style.display = 'none';
document.getElementById('spell-area').style.display = 'block';
document.getElementById('spell-hint').textContent = '拼写:' + w.zh;
document.getElementById('spell-blanks').textContent = blanks;
// 字母按钮
let letters = [...new Set(en.split(''))];
while (letters.length < 8) letters.push(String.fromCharCode(97+Math.floor(Math.random()*26)));
letters.sort(() => Math.random()-0.5);
const larea = document.getElementById('spell-letters');
larea.innerHTML = '';
letters.forEach(l => {
let b = document.createElement('button');
b.className = 'letter-btn';
b.textContent = l;
b.onclick = () => inputLetter(l);
larea.appendChild(b);
});
}
function inputLetter(l) {
if (state.battleState !== 'spell') return;
state.spellInput += l;
let display = state.spellAnswer.split('').map((c,i) => {
if (i < state.spellInput.length) return state.spellInput[i];
if (i%2===0 && i>0 && i<state.spellAnswer.length-1) return '_';
return c;
}).join('');
document.getElementById('spell-blanks').textContent = display;
if (state.spellInput.length >= state.spellAnswer.length) {
checkSpell();
}
}
function checkSpell() {
if (state.spellInput === state.spellAnswer) {
showBattleMsg('必杀技! 💥', '#ffd700');
document.getElementById('monster-hp').style.width = '0%';
setTimeout(battleWin, 800);
} else {
showBattleMsg('拼写错误!', '#e94560');
state.battleState = 'choose';
state.consecutiveCorrect = 0;
document.getElementById('spell-area').style.display = 'none';
document.getElementById('options-area').style.display = 'block';
generateOptions();
}
}
function battleWin() {
state.killed++;
state.masteredWords.push(state.currentMonster.word);
state.sessionWords.push(state.currentMonster.word);
state.xp += 25;
if (state.xp >= 100) { state.lv++; state.xp -= 100; }
saveWord(state.currentMonster.word);
// 返回地图
showScreen('map-screen');
renderMap();
updateHUD();
startTimer();
// 检查是否所有怪都死了
if (state.monsters.every(m => m.dead)) {
setTimeout(() => { clearInterval(state.timerInterval); endGame(); }, 500);
}
}
function battleLose() {
clearInterval(state.timerInterval);
endGame();
}
function showBattleMsg(text, color) {
const el = document.createElement('div');
el.className = 'battle-msg';
el.textContent = text;
el.style.color = color;
el.style.left = '50%';
el.style.transform = 'translateX(-50%)';
document.getElementById('battle-area').appendChild(el);
setTimeout(() => el.remove(), 1000);
}
// ============ 发音 ============
function speakWord() {
if (state.mute) return;
const word = state.currentMonster ? state.currentMonster.word.en : '';
if (!word) return;
if ('speechSynthesis' in window) {
const u = new SpeechSynthesisUtterance(word);
u.lang = 'en-US'; u.rate = 0.8;
speechSynthesis.cancel();
speechSynthesis.speak(u);
}
}
// ============ HUD ============
function updateHUD() {
document.getElementById('hud-hp').textContent = state.hp;
document.getElementById('hp-fill').style.width = (state.hp/state.maxHp*100)+'%';
document.getElementById('hud-lv').textContent = state.lv;
document.getElementById('hud-xp').textContent = state.xp;
}
// ============ 结算 ============
function endGame() {
const acc = state.totalQuestions > 0 ? Math.round(state.correctAnswers/state.totalQuestions*100)+'%' : '0%';
const m = Math.floor(state.timeLeft/60), s = state.timeLeft%60;
const survived = (4 - (state.timeLeft/60)).toFixed(1) + ' 分钟';
document.getElementById('res-time').textContent = survived;
document.getElementById('res-kills').textContent = state.killed;
document.getElementById('res-words').textContent = state.sessionWords.length;
document.getElementById('res-acc').textContent = acc;
// 单词回顾
const review = document.getElementById('res-review');
review.innerHTML = '<p style="color:#ffd700">本局单词:</p>';
state.sessionWords.forEach(w => {
let d = document.createElement('div');
d.textContent = `${w.en} — ${w.zh}`;
review.appendChild(d);
});
showScreen('result-screen');
}
// ============ 单词书 ============
function saveWord(w) {
let saved = JSON.parse(localStorage.getItem('masteredWords') || '[]');
if (!saved.find(s => s.en === w.en)) { saved.push(w); localStorage.setItem('masteredWords', JSON.stringify(saved)); }
}
function renderWordbook() {
const list = document.getElementById('wordbook-list');
list.innerHTML = '';
let saved = JSON.parse(localStorage.getItem('masteredWords') || '[]');
if (saved.length === 0) { list.innerHTML = '<p style="text-align:center;color:#aaa;">暂无已掌握单词</p>'; return; }
saved.forEach(w => {
let d = document.createElement('div');
d.className = 'wordbook-item';
d.innerHTML = `<span class="en">${w.en}</span> <span class="zh">${w.zh}</span><br><small>${w.example}</small><button onclick="speakText('${w.en}')">🔊</button>`;
list.appendChild(d);
});
}
function speakText(t) {
if ('speechSynthesis' in window) { speechSynthesis.cancel(); const u=new SpeechSynthesisUtterance(t); u.lang='en-US'; speechSynthesis.speak(u); }
}
// ============ 设置 ============
function toggleMute() {
state.mute = !state.mute;
alert(state.mute ? '已静音' : '已取消静音');
}
// 初始化
renderMap();
</script>
</body>
</html>Game Source: Word Pixel: CET-4 Quest
Creator: BoldBunny94
Libraries: none
Complexity: complex (736 lines, 23.3 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: word-pixel-cet-4-quest-boldbunny94" to link back to the original. Then publish at arcadelab.ai/publish.