用DeepSeek,花10分钟就能快速制作单词记忆小游戏,娃很快学会主动记单词了!
然后,我用DeepSeek输入了一行指令,让DeepSeek直接做出来一个给孩子玩,同时还能提升学习效率的小游戏。而且最近不是DS又出来了一个V3-0324版本嘛,代码的能力也增长了不少,这就刚好能够快速完成我一个想法。因为我们在其中还添加了积分机制,家长可以根据每次积分的结果来给孩子奖励,以此来增加孩子学习的兴趣。在最近,我发现了一些现象,目前有很多的家长陪孩子背单词,日常就是:翻书、抽查、吼娃
在最近,我发现了一些现象,目前有很多的家长陪孩子背单词,日常就是:翻书、抽查、吼娃、心累
而且最近不是DS又出来了一个V3-0324版本嘛,代码的能力也增长了不少,这就刚好能够快速完成我一个想法
然后,我用DeepSeek输入了一行指令,让DeepSeek直接做出来一个给孩子玩,同时还能提升学习效率的小游戏
不到1分钟,就能收到完整方案——从页面设计到框架构建,考虑的十分周到
孩子拿到电脑玩到停不下来: 原来不是孩子不爱学,是家长需要先学会“用科技偷懒”
那么,我们就开始教大家去做一款这样的游戏吧
首先,我们打开DeepSeek官网,不要开启深度思考模式和联网搜索功能,直接输入下面这段提示词:
帮我生成一个适合小学生玩的单词的字母拼接游戏,孩子通过中文提示拼接单词,并且伴有2个多余的随机字母做干扰,使用Html+CSS+Javascript,页面分为游戏界面和设置界面
很快,DeepSeek就帮我们生成了完整的代码
然后,我们点击代码框右上角的复制按钮
在桌面新建一个文本文档,粘贴代码
保存后,返回修改文件后缀名,.txt—>.html
然后直接双击就可以使用了,我们来看看效果
怎么样,是不是非常的有趣呢!
因为我们在其中还添加了积分机制,家长可以根据每次积分的结果来给孩子奖励,以此来增加孩子学习的兴趣
你们也可以复制上面的提示词去做一款类似的小游戏,可玩性非常的高
如果想要源码的直接拿,按照上面的教程也可以自己动手去做一个
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>小学生单词拼接游戏</title>
<style>
body {
font-family: 'Arial Rounded MT Bold', 'Arial', sans-serif;
background-color: #f0f8ff;
margin: 0;
padding: 20px;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
}
h1 {
color: #ff6b6b;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
}
.container {
background-color: white;
border-radius: 15px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
padding: 25px;
width: 90%;
max-width: 800px;
text-align: center;
}
.game-area, .settings-area, .wordlist-area {
display: none;
}
.active {
display: block;
}
.prompt {
font-size: 24px;
margin: 20px 0;
color: #333;
background-color: #e6f7ff;
padding: 15px;
border-radius: 10px;
border-left: 5px solid #1890ff;
}
.letters-container {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 10px;
margin: 20px 0;
}
.letter {
width: 50px;
height: 50px;
background-color: #ffd166;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
font-weight: bold;
cursor: pointer;
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
transition: all 0.2s;
user-select: none;
}
.letter:hover {
transform: translateY(-3px);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
}
.letter.selected {
background-color: #06d6a0;
color: white;
}
.answer-container {
min-height: 60px;
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 10px;
margin: 20px 0;
background-color: #f8f9fa;
padding: 15px;
border-radius: 10px;
}
.answer-slot {
width: 50px;
height: 50px;
background-color: #e9ecef;
border-radius: 10px;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
border: 2px dashed #adb5bd;
user-select: none;
}
.answer-slot.filled {
background-color: #a5d8ff;
border: 2px solid #4dabf7;
}
.controls {
margin-top: 20px;
display: flex;
justify-content: center;
gap: 15px;
flex-wrap: wrap;
}
button {
padding: 10px 20px;
border: none;
border-radius: 50px;
font-size: 16px;
font-weight: bold;
cursor: pointer;
transition: all 0.2s;
}
.check-btn {
background-color: #51cf66;
color: white;
}
.reset-btn {
background-color: #fcc419;
color: white;
}
.next-btn {
background-color: #339af0;
color: white;
}
.prev-btn {
background-color: #9775fa;
color: white;
}
button:hover {
transform: translateY(-2px);
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
}
.feedback {
margin-top: 20px;
font-size: 20px;
font-weight: bold;
min-height: 30px;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
}
.correct {
color: #51cf66;
}
.incorrect {
color: #ff6b6b;
}
.score {
font-size: 18px;
margin-top: 15px;
color: #495057;
display: flex;
align-items: center;
justify-content: center;
gap: 5px;
}
.flower {
color: #ff6b6b;
font-size: 20px;
}
.settings-form {
display: flex;
flex-direction: column;
gap: 15px;
text-align: left;
}
.form-group {
display: flex;
flex-direction: column;
}
label {
margin-bottom: 5px;
font-weight: bold;
color: #495057;
}
select, input, textarea {
padding: 10px;
border-radius: 8px;
border: 1px solid #ced4da;
font-size: 16px;
}
textarea {
min-height: 150px;
resize: vertical;
font-family: monospace;
}
.start-btn {
background-color: #7950f2;
color: white;
margin-top: 20px;
}
.switch-btn {
background-color: transparent;
color: #339af0;
border: 2px solid #339af0;
margin-top: 20px;
}
.edit-wordlist-btn {
background-color: #20c997;
color: white;
}
.tabs {
display: flex;
margin-bottom: 20px;
flex-wrap: wrap;
}
.tab {
padding: 10px 20px;
cursor: pointer;
background-color: #e9ecef;
border-radius: 10px 10px 0 0;
margin-right: 5px;
margin-bottom: 5px;
}
.tab.active {
background-color: white;
font-weight: bold;
color: #339af0;
}
.question-cards {
display: flex;
flex-wrap: wrap;
gap: 10px;
justify-content: center;
margin-bottom: 20px;
}
.question-card {
width: 40px;
height: 40px;
background-color: #e9ecef;
border-radius: 8px;
display: flex;
justify-content: center;
align-items: center;
cursor: pointer;
transition: all 0.2s;
}
.question-card:hover {
background-color: #dee2e6;
}
.question-card.current {
background-color: #4dabf7;
color: white;
font-weight: bold;
}
.question-card.correct {
background-color: #51cf66;
color: white;
}
.wordlist-editor {
margin-top: 20px;
}
.wordlist-actions {
display: flex;
gap: 10px;
margin-top: 10px;
}
.save-btn {
background-color: #20c997;
color: white;
}
.cancel-btn {
background-color: #fa5252;
color: white;
}
.import-export {
display: flex;
gap: 10px;
margin-top: 15px;
}
</style>
</head>
<body>
<h1>小学生单词拼接游戏</h1>
<div class="tabs">
<div class="tab active" id="game-tab">游戏</div>
<div class="tab" id="settings-tab">设置</div>
<div class="tab" id="wordlist-tab">单词表</div>
</div>
<div class="container">
<div id="game" class="game-area active">
<div class="question-cards" id="question-cards">
<!-- 答题卡将在这里动态生成 -->
</div>
<div class="prompt" id="prompt">请根据提示拼接单词</div>
<div class="letters-container" id="letters-container">
<!-- 字母将在这里动态生成 -->
</div>
<div class="answer-container" id="answer-container">
<!-- 答案槽将在这里动态生成 -->
</div>
<div class="controls">
<button class="prev-btn" id="prev-btn">上一个</button>
<button class="check-btn" id="check-btn">检查答案</button>
<button class="reset-btn" id="reset-btn">重置</button>
<button class="next-btn" id="next-btn">下一个</button>
</div>
<div class="feedback" id="feedback"></div>
<div class="score" id="score">
<span>得分: 0</span>
<span class="flowers" id="flowers"></span>
</div>
</div>
<div id="settings" class="settings-area">
<div class="settings-form">
<div class="form-group">
<label for="difficulty">难度级别:</label>
<select id="difficulty">
<option value="easy">简单 (3-4字母单词)</option>
<option value="medium">中等 (5-6字母单词)</option>
<option value="hard">困难 (7+字母单词)</option>
</select>
</div>
<div class="form-group">
<label for="category">单词类别:</label>
<select id="category">
<option value="animals">动物</option>
<option value="fruits">水果</option>
<option value="colors">颜色</option>
<option value="school">学校相关</option>
<option value="family">家庭成员</option>
</select>
</div>
<div class="form-group">
<label for="show-hint">显示提示:</label>
<select id="show-hint">
<option value="yes">是</option>
<option value="no">否</option>
</select>
</div>
<div class="form-group">
<label for="auto-check">自动检查:</label>
<select id="auto-check">
<option value="yes">是 (选满字母自动检查)</option>
<option value="no">否 (手动点击检查)</option>
</select>
</div>
<button class="start-btn" id="start-btn">开始游戏</button>
<button class="edit-wordlist-btn" id="edit-wordlist-btn">编辑单词表</button>
<button class="switch-btn" id="back-to-game-btn">返回游戏</button>
</div>
</div>
<div id="wordlist" class="wordlist-area">
<h2>编辑单词表</h2>
<div class="form-group">
<label for="wordlist-category">选择类别:</label>
<select id="wordlist-category">
<option value="animals">动物</option>
<option value="fruits">水果</option>
<option value="colors">颜色</option>
<option value="school">学校相关</option>
<option value="family">家庭成员</option>
<option value="custom">自定义</option>
</select>
</div>
<div class="wordlist-editor">
<textarea id="wordlist-editor" placeholder="每行一个单词,格式为: 单词,中文提示 例如: apple,苹果"></textarea>
<div class="wordlist-actions">
<button class="save-btn" id="save-wordlist-btn">保存</button>
<button class="cancel-btn" id="cancel-wordlist-btn">取消</button>
</div>
</div>
<div class="import-export">
<button class="import-btn" id="import-wordlist-btn">导入单词表</button>
<button class="export-btn" id="export-wordlist-btn">导出单词表</button>
<input type="file" id="wordlist-file" accept=".json,.txt" style="display: none;">
</div>
<button class="switch-btn" id="back-to-settings-btn">返回设置</button>
</div>
</div>
<script>
// 游戏数据
let wordData = {
animals: [
{ word: "cat", hint: "猫" },
{ word: "dog", hint: "狗" },
{ word: "pig", hint: "猪" },
{ word: "bird", hint: "鸟" },
{ word: "fish", hint: "鱼" },
{ word: "lion", hint: "狮子" },
{ word: "bear", hint: "熊" },
{ word: "frog", hint: "青蛙" },
{ word: "duck", hint: "鸭子" },
{ word: "wolf", hint: "狼" }
],
fruits: [
{ word: "apple", hint: "苹果" },
{ word: "pear", hint: "梨" },
{ word: "banana", hint: "香蕉" },
{ word: "grape", hint: "葡萄" },
{ word: "peach", hint: "桃子" },
{ word: "melon", hint: "瓜" },
{ word: "lemon", hint: "柠檬" },
{ word: "mango", hint: "芒果" },
{ word: "berry", hint: "浆果" },
{ word: "cherry", hint: "樱桃" }
],
colors: [
{ word: "red", hint: "红色" },
{ word: "blue", hint: "蓝色" },
{ word: "green", hint: "绿色" },
{ word: "pink", hint: "粉色" },
{ word: "black", hint: "黑色" },
{ word: "white", hint: "白色" },
{ word: "brown", hint: "棕色" },
{ word: "gray", hint: "灰色" },
{ word: "gold", hint: "金色" },
{ word: "purple", hint: "紫色" }
],
school: [
{ word: "book", hint: "书" },
{ word: "pen", hint: "钢笔" },
{ word: "desk", hint: "课桌" },
{ word: "class", hint: "班级" },
{ word: "teacher", hint: "老师" },
{ word: "student", hint: "学生" },
{ word: "school", hint: "学校" },
{ word: "pencil", hint: "铅笔" },
{ word: "ruler", hint: "尺子" },
{ word: "eraser", hint: "橡皮" }
],
family: [
{ word: "dad", hint: "爸爸" },
{ word: "mom", hint: "妈妈" },
{ word: "son", hint: "儿子" },
{ word: "daughter", hint: "女儿" },
{ word: "brother", hint: "兄弟" },
{ word: "sister", hint: "姐妹" },
{ word: "grandpa", hint: "爷爷/外公" },
{ word: "grandma", hint: "奶奶/外婆" },
{ word: "uncle", hint: "叔叔/舅舅" },
{ word: "aunt", hint: "阿姨/姑姑" }
],
custom: []
};
// 游戏状态
let currentWord = "";
let currentHint = "";
let selectedLetters = [];
let score = 0;
let flowers = 0;
let usedWords = [];
let currentIndex = 0;
let questionStates = [];
let difficulty = "easy";
let category = "animals";
let showHint = "yes";
let autoCheck = "yes";
// DOM元素
const lettersContainer = document.getElementById("letters-container");
const answerContainer = document.getElementById("answer-container");
const promptElement = document.getElementById("prompt");
const feedbackElement = document.getElementById("feedback");
const scoreElement = document.getElementById("score");
const flowersElement = document.getElementById("flowers");
const questionCardsContainer = document.getElementById("question-cards");
const difficultySelect = document.getElementById("difficulty");
const categorySelect = document.getElementById("category");
const showHintSelect = document.getElementById("show-hint");
const autoCheckSelect = document.getElementById("auto-check");
const checkBtn = document.getElementById("check-btn");
const resetBtn = document.getElementById("reset-btn");
const nextBtn = document.getElementById("next-btn");
const prevBtn = document.getElementById("prev-btn");
const startBtn = document.getElementById("start-btn");
const editWordlistBtn = document.getElementById("edit-wordlist-btn");
const backToGameBtn = document.getElementById("back-to-game-btn");
const backToSettingsBtn = document.getElementById("back-to-settings-btn");
const gameTab = document.getElementById("game-tab");
const settingsTab = document.getElementById("settings-tab");
const wordlistTab = document.getElementById("wordlist-tab");
const wordlistCategorySelect = document.getElementById("wordlist-category");
const wordlistEditor = document.getElementById("wordlist-editor");
const saveWordlistBtn = document.getElementById("save-wordlist-btn");
const cancelWordlistBtn = document.getElementById("cancel-wordlist-btn");
const importWordlistBtn = document.getElementById("import-wordlist-btn");
const exportWordlistBtn = document.getElementById("export-wordlist-btn");
const wordlistFileInput = document.getElementById("wordlist-file");
// 初始化游戏
function initGame() {
difficulty = difficultySelect.value;
category = categorySelect.value;
showHint = showHintSelect.value;
autoCheck = autoCheckSelect.value;
score = 0;
flowers = 0;
usedWords = [];
currentIndex = 0;
questionStates = [];
updateScore();
updateFlowers();
selectRandomWord();
// 添加事件监听器
checkBtn.addEventListener("click", checkAnswer);
resetBtn.addEventListener("click", resetSelection);
nextBtn.addEventListener("click", nextWord);
prevBtn.addEventListener("click", prevWord);
startBtn.addEventListener("click", startGame);
editWordlistBtn.addEventListener("click", () => showTab("wordlist"));
backToGameBtn.addEventListener("click", () => showTab("game"));
backToSettingsBtn.addEventListener("click", () => showTab("settings"));
gameTab.addEventListener("click", () => showTab("game"));
settingsTab.addEventListener("click", () => showTab("settings"));
wordlistTab.addEventListener("click", () => showTab("wordlist"));
wordlistCategorySelect.addEventListener("change", loadWordlistForEditing);
saveWordlistBtn.addEventListener("click", saveWordlist);
cancelWordlistBtn.addEventListener("click", () => showTab("settings"));
importWordlistBtn.addEventListener("click", () => wordlistFileInput.click());
exportWordlistBtn.addEventListener("click", exportWordlist);
wordlistFileInput.addEventListener("change", importWordlist);
}
// 开始游戏
function startGame() {
initGame();
showTab("game");
}
// 选择随机单词
function selectRandomWord() {
const availableWords = wordData[category].filter(wordObj =>
!usedWords.includes(wordObj.word.toLowerCase()) &&
((difficulty === "easy" && wordObj.word.length <= 4) ||
(difficulty === "medium" && wordObj.word.length >= 5 && wordObj.word.length <= 6) ||
(difficulty === "hard" && wordObj.word.length >= 7)));
if (availableWords.length === 0) {
// 如果没有可用的单词了,重置已用单词列表
usedWords = [];
selectRandomWord();
return;
}
const randomIndex = Math.floor(Math.random() * availableWords.length);
currentWord = availableWords[randomIndex].word.toUpperCase();
currentHint = availableWords[randomIndex].hint;
usedWords.push(currentWord.toLowerCase());
// 初始化问题状态
if (questionStates.length <= currentIndex) {
questionStates.push({
word: currentWord,
hint: currentHint,
completed: false,
correct: false
});
}
setupGame();
}
// 设置游戏界面
function setupGame() {
// 清空容器
lettersContainer.innerHTML = "";
answerContainer.innerHTML = "";
feedbackElement.textContent = "";
feedbackElement.className = "feedback";
selectedLetters = [];
// 设置提示
promptElement.textContent = showHint === "yes" ?
`请拼出这个单词: ${currentHint}` :
`请拼出这个${currentWord.length}字母单词`;
// 创建答案槽
for (let i = 0; i < currentWord.length; i++) {
const slot = document.createElement("div");
slot.className = "answer-slot";
slot.dataset.index = i;
answerContainer.appendChild(slot);
}
// 创建字母选项(包含2个干扰字母)
const letters = currentWord.split("");
// 添加2个随机干扰字母
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
for (let i = 0; i < 2; i++) {
let randomLetter;
do {
randomLetter = alphabet[Math.floor(Math.random() * alphabet.length)];
} while (letters.includes(randomLetter));
letters.push(randomLetter);
}
// 打乱字母顺序
shuffleArray(letters);
// 创建字母元素
letters.forEach((letter, index) => {
const letterElement = document.createElement("div");
letterElement.className = "letter";
letterElement.textContent = letter;
letterElement.dataset.letter = letter;
letterElement.dataset.index = index;
letterElement.addEventListener("click", () => selectLetter(letterElement));
lettersContainer.appendChild(letterElement);
});
// 更新答题卡
updateQuestionCards();
}
// 更新答题卡
function updateQuestionCards() {
questionCardsContainer.innerHTML = "";
for (let i = 0; i < questionStates.length; i++) {
const card = document.createElement("div");
card.className = "question-card";
if (i === currentIndex) {
card.classList.add("current");
}
if (questionStates[i].completed) {
card.classList.add(questionStates[i].correct ? "correct" : "incorrect");
}
card.textContent = i + 1;
card.addEventListener("click", () => jumpToQuestion(i));
questionCardsContainer.appendChild(card);
}
}
// 跳转到指定问题
function jumpToQuestion(index) {
if (index >= 0 && index < questionStates.length) {
currentIndex = index;
currentWord = questionStates[index].word;
currentHint = questionStates[index].hint;
setupGame();
}
}
// 选择字母
function selectLetter(letterElement) {
// 如果字母已经被选中,则取消选择
if (letterElement.classList.contains("selected")) {
letterElement.classList.remove("selected");
const index = selectedLetters.findIndex(item => item.element === letterElement);
if (index !== -1) {
selectedLetters.splice(index, 1);
}
updateAnswerSlots();
return;
}
// 如果已经选择了足够的字母,不能再选择更多
if (selectedLetters.length >= currentWord.length) {
return;
}
// 选择字母
letterElement.classList.add("selected");
selectedLetters.push({
letter: letterElement.dataset.letter,
element: letterElement
});
updateAnswerSlots();
// 如果开启了自动检查且已选足够字母,自动检查
if (autoCheck === "yes" && selectedLetters.length === currentWord.length) {
setTimeout(() => {
checkAnswer();
}, 300);
}
}
// 更新答案槽
function updateAnswerSlots() {
const slots = document.querySelectorAll(".answer-slot");
// 清空所有槽
slots.forEach(slot => {
slot.textContent = "";
slot.className = "answer-slot";
});
// 填充已选字母
selectedLetters.forEach((item, index) => {
if (slots[index]) {
slots[index].textContent = item.letter;
slots[index].className = "answer-slot filled";
}
});
}
// 检查答案
function checkAnswer() {
if (selectedLetters.length !== currentWord.length) {
feedbackElement.textContent = "请选择正确数量的字母!";
feedbackElement.className = "feedback incorrect";
return;
}
const userAnswer = selectedLetters.map(item => item.letter).join("");
if (userAnswer === currentWord) {
feedbackElement.innerHTML = "<span>正确!太棒了!</span><span class='flower'>🌸</span>";
feedbackElement.className = "feedback correct";
score += 10;
flowers += 1;
updateScore();
updateFlowers();
// 标记问题为已完成且正确
questionStates[currentIndex].completed = true;
questionStates[currentIndex].correct = true;
updateQuestionCards();
// 自动跳转到下一个问题
setTimeout(() => {
nextWord();
}, 1000);
} else {
feedbackElement.textContent = `不对哦,再试试看!`;
feedbackElement.className = "feedback incorrect";
// 标记问题为已完成但错误
questionStates[currentIndex].completed = true;
questionStates[currentIndex].correct = false;
updateQuestionCards();
// 自动重置
setTimeout(() => {
resetSelection();
}, 1000);
}
}
// 重置选择
function resetSelection() {
selectedLetters.forEach(item => {
item.element.classList.remove("selected");
});
selectedLetters = [];
updateAnswerSlots();
feedbackElement.textContent = "";
feedbackElement.className = "feedback";
}
// 下一个单词
function nextWord() {
currentIndex++;
if (currentIndex < questionStates.length) {
// 跳转到已存在的问题
currentWord = questionStates[currentIndex].word;
currentHint = questionStates[currentIndex].hint;
setupGame();
} else {
// 选择新单词
selectRandomWord();
}
}
// 上一个单词
function prevWord() {
if (currentIndex > 0) {
currentIndex--;
currentWord = questionStates[currentIndex].word;
currentHint = questionStates[currentIndex].hint;
setupGame();
}
}
// 更新分数
function updateScore() {
scoreElement.querySelector("span").textContent = `得分: ${score}`;
}
// 更新小红花
function updateFlowers() {
flowersElement.innerHTML = "";
for (let i = 0; i < flowers; i++) {
flowersElement.innerHTML += "<span class='flower'>🌸</span>";
}
}
// 切换标签页
function showTab(tabName) {
document.getElementById("game").classList.remove("active");
document.getElementById("settings").classList.remove("active");
document.getElementById("wordlist").classList.remove("active");
document.getElementById(tabName).classList.add("active");
// 更新标签样式
gameTab.classList.remove("active");
settingsTab.classList.remove("active");
wordlistTab.classList.remove("active");
if (tabName === "game") {
gameTab.classList.add("active");
} else if (tabName === "settings") {
settingsTab.classList.add("active");
} else {
wordlistTab.classList.add("active");
loadWordlistForEditing();
}
}
// 加载单词表用于编辑
function loadWordlistForEditing() {
const category = wordlistCategorySelect.value;
const words = wordData[category] || [];
// 将单词数组转换为文本
wordlistEditor.value = words.map(item => `${item.word},${item.hint}`).join("\n");
}
// 保存单词表
function saveWordlist() {
const category = wordlistCategorySelect.value;
const text = wordlistEditor.value.trim();
// 解析文本为单词数组
const lines = text.split("\n").filter(line => line.trim() !== "");
const newWords = [];
for (const line of lines) {
const parts = line.split(",");
if (parts.length >= 2) {
newWords.push({
word: parts[0].trim(),
hint: parts[1].trim()
});
} else if (parts[0].trim() !== "") {
newWords.push({
word: parts[0].trim(),
hint: ""
});
}
}
wordData[category] = newWords;
alert("单词表保存成功!");
showTab("settings");
}
// 导出单词表
function exportWordlist() {
const dataStr = JSON.stringify(wordData, null, 2);
const dataUri = 'data:application/json;charset=utf-8,'+ encodeURIComponent(dataStr);
const exportFileDefaultName = '单词表.json';
const linkElement = document.createElement('a');
linkElement.setAttribute('href', dataUri);
linkElement.setAttribute('download', exportFileDefaultName);
linkElement.click();
}
// 导入单词表
function importWordlist(event) {
const file = event.target.files[0];
if (!file) return;
const reader = new FileReader();
reader.onload = function(e) {
try {
const importedData = JSON.parse(e.target.result);
if (typeof importedData === 'object' && importedData !== null) {
wordData = importedData;
alert("单词表导入成功!");
loadWordlistForEditing();
} else {
alert("导入的文件格式不正确!");
}
} catch (error) {
alert("导入失败:" + error.message);
}
};
reader.readAsText(file);
// 清空文件输入,以便可以重复导入同一文件
event.target.value = '';
}
// 辅助函数:打乱数组
function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
}
// 初始化
document.addEventListener("DOMContentLoaded", () => {
initGame();
});
</script>
</body>
</html>
更多推荐
所有评论(0)