Files
RGKT/rg-09112127/html/play/认识数字3.html

836 lines
28 KiB
HTML
Raw Normal View History

2025-10-10 19:44:14 +08:00
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>数学小精灵 - 培智学校生活数学游戏</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<!-- 引入后端集成脚本 -->
<script src="../../js/apiService.js"></script>
<script src="../../js/dataManager.js"></script>
<script src="../../js/userManager.js"></script>
<script src="../../js/accessTracker.js"></script>
<script src="../../js/gameTracker.js"></script>
<script src="../../js/gameDataLogger.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Comic Sans MS', '华文圆体', cursive;
}
body {
background: linear-gradient(135deg, #6ecbf5, #a17fe0);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
padding: 20px;
}
.game-container {
width: 95%;
max-width: 900px;
background: rgba(255, 255, 255, 0.92);
border-radius: 30px;
box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
overflow: hidden;
position: relative;
min-height: 85vh;
}
.game-header {
background: linear-gradient(to right, #ff9a9e, #fad0c4);
padding: 20px 30px;
display: flex;
justify-content: space-between;
align-items: center;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.logo {
display: flex;
align-items: center;
}
.logo img {
width: 60px;
height: 60px;
margin-right: 15px;
}
.logo-text {
font-size: 28px;
font-weight: bold;
color: #d43f8d;
text-shadow: 2px 2px 0 #ffd7e9;
}
.level-info {
background: rgba(255, 255, 255, 0.8);
padding: 10px 25px;
border-radius: 20px;
font-size: 20px;
font-weight: bold;
color: #ff6b6b;
box-shadow: 0 3px 8px rgba(0, 0, 0, 0.1);
}
/* 主内容区 */
.game-content {
padding: 30px;
display: flex;
flex-direction: column;
align-items: center;
position: relative;
min-height: 60vh;
}
/* 欢迎屏幕 */
.welcome-screen {
text-align: center;
padding: 40px 0;
animation: bounceIn 1s;
}
.welcome-title {
font-size: 48px;
color: #ff7b54;
margin-bottom: 30px;
text-shadow: 2px 2px 0 #ffe1c6;
}
.welcome-subtitle {
font-size: 28px;
color: #5c7cfa;
margin-bottom: 40px;
}
.character {
width: 200px;
height: 200px;
background: #ffb6c1;
border-radius: 50%;
margin: 20px auto 40px;
position: relative;
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
display: flex;
justify-content: center;
align-items: center;
overflow: hidden;
}
.character::before {
content: "😊";
font-size: 100px;
}
.start-button {
background: linear-gradient(to right, #ff9a9e, #fad0c4);
color: white;
font-size: 28px;
padding: 15px 50px;
border: none;
border-radius: 50px;
cursor: pointer;
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
transition: all 0.3s;
font-weight: bold;
}
.start-button:hover {
transform: scale(1.05);
box-shadow: 0 12px 20px rgba(0, 0, 0, 0.15);
}
/* 关卡选择 */
.level-selection {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 25px;
margin: 30px 0 50px;
width: 100%;
max-width: 800px;
}
.level-card {
background: white;
border-radius: 20px;
padding: 25px;
display: flex;
flex-direction: column;
align-items: center;
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
cursor: pointer;
transition: all 0.3s;
border: 4px solid transparent;
position: relative;
overflow: hidden;
}
.level-card:hover {
transform: translateY(-10px);
border-color: #ff9a9e;
}
.level-icon {
width: 100px;
height: 100px;
background: #ffecb5;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
font-size: 50px;
color: #ff9a9e;
}
.level-name {
font-size: 22px;
color: #5c7cfa;
font-weight: bold;
margin-bottom: 10px;
}
.level-desc {
font-size: 18px;
color: #666;
text-align: center;
}
/* 游戏区 */
.game-area {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}
.game-question {
font-size: 32px;
color: #2d6cdf;
margin-bottom: 30px;
text-align: center;
background: #e6f4ff;
padding: 15px 30px;
border-radius: 15px;
border: 3px dashed #a0c4ff;
width: 100%;
max-width: 600px;
}
.game-options {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 25px;
margin: 30px 0;
width: 100%;
max-width: 800px;
}
.game-option {
width: 120px;
height: 120px;
background: #ffde7d;
border-radius: 20px;
display: flex;
justify-content: center;
align-items: center;
font-size: 60px;
cursor: pointer;
transition: all 0.3s;
box-shadow: 0 8px 15px rgba(0, 0, 0, 0.1);
position: relative;
}
.game-option:hover {
transform: scale(1.1);
}
/* 视觉提示区 */
.visual-prompt {
display: flex;
justify-content: center;
flex-wrap: wrap;
gap: 15px;
margin: 30px 0;
padding: 20px;
background: #f6f7f9;
border-radius: 20px;
border: 3px solid #e0e0e0;
width: 100%;
max-width: 600px;
}
.visual-item {
width: 70px;
height: 70px;
background: #a0c4ff;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
font-size: 30px;
}
/* 反馈与导航 */
.feedback-area {
position: absolute;
bottom: 30px;
left: 0;
right: 0;
display: flex;
justify-content: center;
}
.feedback-text {
font-size: 36px;
font-weight: bold;
padding: 20px 40px;
border-radius: 20px;
animation: pop 0.5s;
}
.correct {
background: #d4edda;
color: #155724;
border: 3px solid #c3e6cb;
}
.incorrect {
background: #f8d7da;
color: #721c24;
border: 3px solid #f5c6cb;
}
.nav-buttons {
display: flex;
gap: 20px;
margin-top: 30px;
}
.nav-button {
background: #78c4d4;
color: white;
border: none;
border-radius: 20px;
padding: 15px 30px;
font-size: 22px;
cursor: pointer;
display: flex;
align-items: center;
gap: 10px;
transition: all 0.3s;
}
.nav-button:hover {
background: #5db8cb;
transform: scale(1.05);
}
/* 动画 */
@keyframes bounceIn {
from {
opacity: 0;
transform: scale(0.5);
}
to {
opacity: 1;
transform: scale(1);
}
}
@keyframes pop {
0% { transform: scale(0.8); }
50% { transform: scale(1.1); }
100% { transform: scale(1); }
}
@keyframes float {
0% { transform: translateY(0px); }
50% { transform: translateY(-15px); }
100% { transform: translateY(0px); }
}
/* 进度条 */
.progress-bar {
height: 20px;
background: #e0e0e0;
border-radius: 10px;
overflow: hidden;
width: 90%;
max-width: 700px;
margin: 20px 0;
}
.progress {
height: 100%;
background: linear-gradient(to right, #ff9a9e, #fad0c4);
border-radius: 10px;
width: 0%;
transition: width 0.5s ease-in-out;
}
/* 响应式设计 */
@media (max-width: 768px) {
.level-selection {
grid-template-columns: 1fr;
}
.game-options {
flex-wrap: wrap;
}
.game-option {
width: 100px;
height: 100px;
}
.welcome-title {
font-size: 36px;
}
}
.floating-element {
position: absolute;
animation: float 4s infinite ease-in-out;
}
.element-1 {
top: 50px;
left: 50px;
font-size: 50px;
color: #ff9a9e;
}
.element-2 {
bottom: 50px;
right: 50px;
font-size: 50px;
color: #5c7cfa;
}
</style>
</head>
<body>
<div class="game-container">
<div class="game-header">
<div class="logo">
<img src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyMDAgMjAwIj48Y2lyY2xlIGN4PSIxMDAiIGN5PSIxMDAiIHI9Ijk1IiBmaWxsPSIjRkZCQzREIi8+PHBhdGggZD0iTTcwLDEyMCBRMTAwLDE0MCAxMzAsMTIwIiBzdHJva2U9IiNGRjY4QjAiIHN0cm9rZS13aWR0aD0iOCIvPjxjaXJjbGUgY3g9IjgwIiBjeT0iODAiIHI9IjEwIiBmaWxsPSIjMzMzIi8+PGNpcmNsZSBjeD0iMTIwIiBjeT0iODAiIHI9IjEwIiBmaWxsPSIjMzMzIi8+PC9zdmc+" alt="数学小精灵">
<div class="logo-text">数学小精灵</div>
</div>
<div class="level-info"><span id="currentLevel">1</span></div>
</div>
<div class="game-content">
<!-- 欢迎界面 -->
<div class="welcome-screen" id="welcomeScreen">
<h1 class="welcome-title">生活数学小游戏</h1>
<h2 class="welcome-subtitle">一起来探索数字的奥秘吧!</h2>
<div class="character"></div>
<button class="start-button" id="startButton">
<i class="fas fa-play"></i> 开始游戏
</button>
</div>
<!-- 关卡选择 -->
<div id="levelSelection" class="level-selection" style="display:none;">
<div class="level-card" data-level="1">
<div class="level-icon">🔢</div>
<div class="level-name">认识数字</div>
<div class="level-desc">匹配数字和对应数量的物品</div>
</div>
<div class="level-card" data-level="2">
<div class="level-icon"></div>
<div class="level-name">数一数</div>
<div class="level-desc">点数物品并选择数字</div>
</div>
<div class="level-card" data-level="3">
<div class="level-icon"></div>
<div class="level-name">简单加减</div>
<div class="level-desc">5以内的加法</div>
</div>
</div>
<!-- 游戏区域 -->
<div id="gameArea" class="game-area" style="display:none;">
<div class="progress-bar">
<div class="progress" id="progressBar"></div>
</div>
<div class="game-question" id="question"></div>
<div class="visual-prompt" id="visualPrompt"></div>
<div class="game-options" id="optionsContainer"></div>
<div class="feedback-area">
<div id="feedback" class="feedback-text" style="display:none;"></div>
</div>
<div class="nav-buttons">
<button class="nav-button" id="replayButton" style="display:none;">
<i class="fas fa-redo"></i> 再听一次
</button>
<button class="nav-button" id="nextButton" style="display:none;">
下一题 <i class="fas fa-arrow-right"></i>
</button>
</div>
</div>
</div>
<!-- 浮动元素增加趣味性 -->
<div class="floating-element element-1">🌼</div>
<div class="floating-element element-2">🌈</div>
</div>
<script>
// 游戏状态管理
const gameState = {
currentLevel: 1,
currentQuestion: 0,
totalQuestions: 5,
questionsCorrect: 0
};
// 关卡数据
const levels = {
1: {
title: "认识数字",
questions: [
{
prompt: "找出数字3",
visual: [],
options: [1, 3, 5, 2],
correctIndex: 1
},
{
prompt: "找出数字5",
visual: [],
options: [2, 4, 5, 1],
correctIndex: 2
},
{
prompt: "找出数字2",
visual: [],
options: [3, 4, 2, 5],
correctIndex: 2
},
{
prompt: "找出数字4",
visual: [],
options: [1, 3, 4, 2],
correctIndex: 2
},
{
prompt: "找出数字1",
visual: [],
options: [4, 1, 5, 3],
correctIndex: 1
}
]
},
2: {
title: "数一数",
questions: [
{
prompt: "数一数有多少个苹果",
visual: ["🍎", "🍎", "🍎"],
options: [2, 3, 4, 5],
correctIndex: 1
},
{
prompt: "数一数有多少辆汽车",
visual: ["🚗", "🚗"],
options: [1, 2, 3, 4],
correctIndex: 1
},
{
prompt: "数一数有多少个气球",
visual: ["🎈", "🎈", "🎈", "🎈", "🎈"],
options: [3, 4, 5, 6],
correctIndex: 2
},
{
prompt: "数一数有多少只小狗",
visual: ["🐶", "🐶", "🐶"],
options: [1, 2, 3, 4],
correctIndex: 2
},
{
prompt: "数一数有多少朵花",
visual: ["🌼", "🌼", "🌼", "🌼"],
options: [3, 4, 5, 6],
correctIndex: 1
}
]
},
3: {
title: "简单加减",
questions: [
{
prompt: "1 加 2 等于多少?",
visual: ["1", "+", "2", "="],
options: [2, 3, 4, 5],
correctIndex: 1
},
{
prompt: "3 加 1 等于多少?",
visual: ["3", "+", "1", "="],
options: [2, 3, 4, 5],
correctIndex: 2
},
{
prompt: "2 加 2 等于多少?",
visual: ["2", "+", "2", "="],
options: [1, 2, 3, 4],
correctIndex: 3
},
{
prompt: "4 加 1 等于多少?",
visual: ["4", "+", "1", "="],
options: [3, 4, 5, 6],
correctIndex: 2
},
{
prompt: "0 加 3 等于多少?",
visual: ["0", "+", "3", "="],
options: [0, 1, 2, 3],
correctIndex: 3
}
]
}
};
// DOM元素
const dom = {
welcomeScreen: document.getElementById('welcomeScreen'),
levelSelection: document.getElementById('levelSelection'),
gameArea: document.getElementById('gameArea'),
question: document.getElementById('question'),
visualPrompt: document.getElementById('visualPrompt'),
optionsContainer: document.getElementById('optionsContainer'),
feedback: document.getElementById('feedback'),
nextButton: document.getElementById('nextButton'),
replayButton: document.getElementById('replayButton'),
progressBar: document.getElementById('progressBar'),
currentLevelElement: document.getElementById('currentLevel')
};
// 初始化游戏
function initGame() {
// 事件监听
document.getElementById('startButton').addEventListener('click', showLevelSelection);
document.querySelectorAll('.level-card').forEach(card => {
card.addEventListener('click', () => {
gameState.currentLevel = parseInt(card.dataset.level);
startGame();
});
});
dom.nextButton.addEventListener('click', nextQuestion);
dom.replayButton.addEventListener('click', playQuestion);
}
// 显示关卡选择界面
function showLevelSelection() {
dom.welcomeScreen.style.display = 'none';
dom.levelSelection.style.display = 'grid';
// 添加动画效果
const cards = document.querySelectorAll('.level-card');
cards.forEach((card, index) => {
setTimeout(() => {
card.style.opacity = 0;
card.style.transform = 'translateY(30px)';
setTimeout(() => {
card.style.transition = 'all 0.5s ease-out';
card.style.opacity = 1;
card.style.transform = 'translateY(0)';
}, 50);
}, index * 200);
});
}
// 开始游戏
function startGame() {
dom.levelSelection.style.display = 'none';
dom.gameArea.style.display = 'flex';
dom.currentLevelElement.textContent = gameState.currentLevel;
gameState.currentQuestion = 0;
gameState.questionsCorrect = 0;
updateProgressBar();
showQuestion();
}
// 显示问题
function showQuestion() {
const level = levels[gameState.currentLevel];
const question = level.questions[gameState.currentQuestion];
// 更新问题文本
dom.question.textContent = question.prompt;
// 更新视觉提示
dom.visualPrompt.innerHTML = '';
if(question.visual.length > 0) {
question.visual.forEach(item => {
const itemElement = document.createElement('div');
itemElement.className = 'visual-item';
itemElement.textContent = item;
dom.visualPrompt.appendChild(itemElement);
});
}
// 创建选项
dom.optionsContainer.innerHTML = '';
question.options.forEach((option, index) => {
const optionElement = document.createElement('div');
optionElement.className = 'game-option';
optionElement.textContent = option;
optionElement.dataset.index = index;
optionElement.addEventListener('click', () => {
checkAnswer(index);
});
dom.optionsContainer.appendChild(optionElement);
});
// 播放问题语音
playQuestion();
// 隐藏按钮
dom.feedback.style.display = 'none';
dom.nextButton.style.display = 'none';
dom.replayButton.style.display = 'none';
}
// 播放问题提示
function playQuestion() {
const level = levels[gameState.currentLevel];
const question = level.questions[gameState.currentQuestion];
// 在实际应用中,这里会播放语音
console.log("播放语音提示:", question.prompt);
// 添加视觉反馈 - 边框闪烁
dom.question.style.animation = 'none';
setTimeout(() => {
dom.question.style.animation = 'pop 0.5s';
}, 10);
}
// 检查答案
function checkAnswer(selectedIndex) {
const level = levels[gameState.currentLevel];
const question = level.questions[gameState.currentQuestion];
const isCorrect = selectedIndex === question.correctIndex;
// 播放音效
playSoundEffect(isCorrect);
if (isCorrect) {
gameState.questionsCorrect++;
// 显示正确反馈
dom.feedback.textContent = "✓ 太棒了!答对了!";
dom.feedback.className = 'feedback-text correct';
// 为正确选项添加效果
const options = document.querySelectorAll('.game-option');
options[selectedIndex].style.background = '#a8e6cf';
options[selectedIndex].style.transform = 'scale(1.2)';
} else {
// 显示错误反馈
dom.feedback.textContent = "✗ 再试一次!";
dom.feedback.className = 'feedback-text incorrect';
// 为错误选项添加效果
const option = document.querySelector(`.game-option[data-index="${selectedIndex}"]`);
option.style.background = '#ff8b94';
// 显示正确选项
const correctOption = document.querySelector(`.game-option[data-index="${question.correctIndex}"]`);
correctOption.style.background = '#a8e6cf';
correctOption.style.border = '3px solid #64c4a4';
}
// 显示反馈和按钮
dom.feedback.style.display = 'block';
dom.nextButton.style.display = 'flex';
dom.replayButton.style.display = 'flex';
// 更新进度条
updateProgressBar();
}
// 下一题
function nextQuestion() {
gameState.currentQuestion++;
if (gameState.currentQuestion < gameState.totalQuestions) {
showQuestion();
} else {
showResults();
}
}
// 更新进度条
function updateProgressBar() {
const progress = (gameState.currentQuestion / gameState.totalQuestions) * 100;
dom.progressBar.style.width = `${progress}%`;
}
// 显示结果
function showResults() {
const accuracy = Math.round((gameState.questionsCorrect / gameState.totalQuestions) * 100);
dom.question.innerHTML = `
<div style="text-align: center;">
<div style="font-size: 42px; color: #ff7b54; margin-bottom: 20px;">游戏完成!</div>
<div style="font-size: 36px; margin-bottom: 30px;">正确率: ${accuracy}%</div>
<div style="font-size: 80px; color: ${accuracy > 70 ? '#4caf50' : '#ff6b6b'};">
${accuracy > 70 ? '🥇' : accuracy > 50 ? '🥈' : '🥉'}
</div>
</div>
`;
dom.visualPrompt.style.display = 'none';
dom.optionsContainer.innerHTML = '';
dom.feedback.style.display = 'none';
dom.nextButton.style.display = 'none';
dom.replayButton.style.display = 'none';
// 添加重新开始按钮
const restartButton = document.createElement('button');
restartButton.className = 'start-button';
restartButton.style.marginTop = '30px';
restartButton.innerHTML = '<i class="fas fa-redo"></i> 再玩一次';
restartButton.addEventListener('click', showLevelSelection);
dom.optionsContainer.appendChild(restartButton);
// 播放结果音效
playSoundEffect(accuracy > 70);
}
// 播放音效
function playSoundEffect(isPositive) {
// 实际项目中会使用真实的音效文件
// 这里使用控制台输出代替
console.log(`播放音效: ${isPositive ? '正确' : '错误'}`);
}
// 初始化游戏
window.onload = initGame;
</script>
</body>
</html>