Here's a basic HTML structure for the interactive chemistry learning game you described:
html Copy code
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>初中化学学习游戏</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f0f8ff;
color: #333;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
header {
background-color: #4682b4;
color: white;
padding: 20px 0;
text-align: center;
}
nav {
background-color: #b0c4de;
padding: 10px 0;
}
nav ul {
list-style-type: none;
padding: 0;
margin: 0;
display: flex;
justify-content: center;
}
nav ul li {
margin: 0 15px;
}
nav ul li a {
color: #333;
text-decoration: none;
font-weight: bold;
}
.content {
background-color: white;
padding: 20px;
margin-top: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0,0,0,0.1);
}
.periodic-table {
display: grid;
grid-template-columns: repeat(18, 1fr);
gap: 2px;
}
.element {
background-color: #e6e6fa;
padding: 5px;
text-align: center;
cursor: pointer;
transition: background-color 0.3s;
}
.element:hover {
background-color: #d8bfd8;
}
.element-card {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0,0,0,0.2);
z-index: 1000;
max-width: 80%;
max-height: 80%;
overflow-y: auto;
}
.close-btn {
position: absolute;
top: 10px;
right: 10px;
cursor: pointer;
font-size: 24px;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.game-container {
margin-top: 20px;
}
.question {
font-size: 18px;
margin-bottom: 10px;
}
.options {
display: grid;
grid-template-columns: repeat(2, 1fr);
gap: 10px;
}
.option {
background-color: #e6e6fa;
padding: 10px;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
.option:hover {
background-color: #d8bfd8;
}
.progress-bar {
width: 100%;
height: 20px;
background-color: #f0f0f0;
border-radius: 10px;
margin-top: 20px;
}
.progress {
width: 0;
height: 100%;
background-color: #4caf50;
border-radius: 10px;
transition: width 0.3s;
}
</style>
</head>
<body>
<header>
<h1>初中化学学习游戏</h1>
</header>
<nav>
<ul>
<li><a href="#home">首页</a></li>
<li><a href="#periodic-table">元素周期表</a></li>
<li><a href="#valence-table">化合价表</a></li>
<li><a href="#formula-table">化学式表</a></li>
<li><a href="#equation-table">方程式表</a></li>
<li><a href="#knowledge-base">基础知识库</a></li>
<li><a href="#element-game">元素记忆游戏</a></li>
<li><a href="#formula-game">化学式记忆游戏</a></li>
<li><a href="#equation-game">方程式记忆游戏</a></li>
<li><a href="#comprehensive-quiz">综合题库</a></li>
<li><a href="#score-statistics">得分统计</a></li>
</ul>
</nav>
<div class="container">
<div id="home" class="content">
<h2>欢迎来到初中化学学习游戏</h2>
<p>这是一个互动式的化学学习平台,帮助你掌握初中化学的基础知识。</p>
</div>
<div id="periodic-table" class="content">
<h2>元素周期表</h2>
<div class="periodic-table">
<!-- 元素周期表内容将通过JavaScript动态生成 -->
</div>
</div>
<div id="valence-table" class="content">
<h2>化合价表</h2>
<table>
<tr>
<th>元素/原子团</th>
<th>化合价</th>
</tr>
<!-- 化合价表内容将通过JavaScript动态生成 -->
</table>
</div>
<div id="formula-table" class="content">
<h2>化学式表</h2>
<!-- 化学式表内容将通过JavaScript动态生成 -->
</div>
<div id="equation-table" class="content">
<h2>方程式表</h2>
<!-- 方程式表内容将通过JavaScript动态生成 -->
</div>
<div id="knowledge-base" class="content">
<h2>基础知识库</h2>
<!-- 基础知识库内容将通过JavaScript动态生成 -->
</div>
<div id="element-game" class="content">
<h2>元素记忆游戏</h2>
<div class="game-container">
<!-- 游戏内容将通过JavaScript动态生成 -->
</div>
</div>
<div id="formula-game" class="content">
<h2>化学式记忆游戏</h2>
<div class="game-container">
<!-- 游戏内容将通过JavaScript动态生成 -->
</div>
</div>
<div id="equation-game" class="content">
<h2>方程式记忆游戏</h2>
<div class="game-container">
<!-- 游戏内容将通过JavaScript动态生成 -->
</div>
</div>
<div id="comprehensive-quiz" class="content">
<h2>综合题库</h2>
<div class="game-container">
<!-- 综合题库内容将通过JavaScript动态生成 -->
</div>
</div>
<div id="score-statistics" class="content">
<h2>得分统计</h2>
<!-- 得分统计内容将通过JavaScript动态生成 -->
</div>
</div>
<script>
// 元素数据
const elements = [
{symbol: 'H', name: '氢', number: 1, mass: 1.008},
{symbol: 'He', name: '氦', number: 2, mass: 4.003},
// ... 其他元素数据
];
// 化合价数据
const valences = [
{element: 'H', valence: '+1'},
{element: 'O', valence: '-2'},
// ... 其他化合价数据
];
// 化学式数据
const formulas = [
{formula: 'H2O', name: '水'},
{formula: 'NaCl', name: '氯化钠'},
// ... 其他化学式数据
];
// 方程式数据
const equations = [
{equation: '2H2 + O2 = 2H2O', condition: '点燃'},
// ... 其他方程式数据
];
// 基础知识数据
const knowledgeBase = [
{title: '高锰酸钾制备氧气', content: '...'},
// ... 其他知识点
];
// 游戏题目数据
const gameQuestions = [
{
question: '氢的化学符号是什么?',
options: ['H', 'He', 'O', 'N'],
answer: 'H'
},
// ... 其他游戏题目
];
// 生成元素周期表
function generatePeriodicTable() {
const periodicTable = document.querySelector('.periodic-table');
elements.forEach(element => {
const elementDiv = document.createElement('div');
elementDiv.className = 'element';
elementDiv.innerHTML = `
<strong>${element.symbol}</strong><br>
${element.number}
`;
elementDiv.addEventListener('click', () => showElementCard(element));
periodicTable.appendChild(elementDiv);
});
}
// 显示元素卡片
function showElementCard(element) {
const card = document.createElement('div');
card.className = 'element-card';
card.innerHTML = `
<span class="close-btn">×</span>
<h3>${element.name} (${element.symbol})</h3>
<p>原子序数: ${element.number}</p>
<p>相对原子质量: ${element.mass}</p>
<!-- 这里可以添加更多元素信息 -->
<div class="atom-structure">
<!-- 这里可以用Canvas或SVG绘制原子结构图 -->
</div>
`;
document.body.appendChild(card);
card.querySelector('.close-btn').addEventListener('click', () => card.remove());
}
// 生成化合价表
function generateValenceTable() {
const table = document.querySelector('#valence-table table');
valences.forEach(valence => {
const row = table.insertRow();
row.insertCell().textContent = valence.element;
row.insertCell().textContent = valence.valence;
});
}
// 生成化学式表
function generateFormulaTable() {
const formulaTable = document.querySelector('#formula-table');
formulas.forEach(formula => {
const p = document.createElement('p');
p.textContent = `${formula.formula}: ${formula.name}`;
formulaTable.appendChild(p);
});
}
// 生成方程式表
function generateEquationTable() {
const equationTable = document.querySelector('#equation-table');
equations.forEach(equation => {
const p = document.createElement('p');
p.textContent = `${equation.equation} (${equation.condition})`;
equationTable.appendChild(p);
});
}
// 生成基础知识库
function generateKnowledgeBase() {
const knowledgeBaseDiv = document.querySelector('#knowledge-base');
knowledgeBase.forEach(item => {
const section = document.createElement('section');
section.innerHTML = `
<h3>${item.title}</h3>
<p>${item.content}</p>
`;
knowledgeBaseDiv.appendChild(section);
});
}
// 生成游戏问题
function generateGameQuestion(gameContainer) {
const question = gameQuestions[Math.floor(Math.random() * gameQuestions.length)];
gameContainer.innerHTML = `
<div class="question">${question.question}</div>
<div class="options">
${question.options.map(option => `
<div class="option">${option}</div>
`).join('')}
</div>
<div class="progress-bar">
<div class="progress"></div>
</div>
`;
gameContainer.querySelectorAll('.option').forEach(option => {
option.addEventListener('click', () => checkAnswer(option, question.answer, gameContainer));
});
}
// 检查答案
function checkAnswer(selectedOption, correctAnswer, gameContainer) {
const options = gameContainer.querySelectorAll('.option');
options.forEach(option => {
option.style.pointerEvents = 'none';
if (option.textContent === correctAnswer) {
option.style.backgroundColor = '#90ee90';
} else if (option === selectedOption) {
option.style.backgroundColor = '#ffcccb';
}
});
setTimeout(() => generateGameQuestion(gameContainer), 1500);
}
// 初始化游戏
function initializeGames() {
const gameContainers = document.querySelectorAll('.game-container');
gameContainers.forEach(container => generateGameQuestion(container));
}
// 页面加载完成后初始化
window.addEventListener('load', () => {
generatePeriodicTable();
generateValenceTable();
generateFormulaTable();
generateEquationTable();
generateKnowledgeBase();
initializeGames();
});
</script>
</body>
</html>
This HTML file provides a basic structure for the interactive chemistry learning game you described. It includes:
The JavaScript code generates the content dynamically based on predefined data structures. You'll need to expand these data structures with more comprehensive information about elements, formulas, equations, and quiz questions.