初始化
This commit is contained in:
422
rg-09112127/html/play/美味餐桌02(4以内加法).html
Normal file
422
rg-09112127/html/play/美味餐桌02(4以内加法).html
Normal file
@@ -0,0 +1,422 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>美味餐桌(4以内加法)</title>
|
||||
|
||||
<!-- 引入后端集成脚本 -->
|
||||
<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>
|
||||
:root {
|
||||
--primary: #FF9AA2;
|
||||
--secondary: #FFB7B2;
|
||||
--accent: #FFDAC1;
|
||||
--food: #E2F0CB;
|
||||
--text: #5E5346;
|
||||
--correct: #B5EAD7;
|
||||
--wrong: #FF9AA2;
|
||||
--button: #70A1FF;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: 'Comic Sans MS', 'Marker Felt', '微软雅黑', sans-serif;
|
||||
background-color: var(--accent);
|
||||
color: var(--text);
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
color: var(--primary);
|
||||
margin-bottom: 20px;
|
||||
text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.1);
|
||||
font-size: 2.2rem;
|
||||
}
|
||||
|
||||
.container {
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
background-color: white;
|
||||
border-radius: 20px;
|
||||
padding: 20px;
|
||||
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
/* 餐桌区域 */
|
||||
.table-area {
|
||||
background-color: #F0E6DD;
|
||||
border: 12px solid #D4A76A;
|
||||
border-radius: 50%;
|
||||
width: 100%;
|
||||
height: 250px;
|
||||
margin-bottom: 30px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.table-area::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: radial-gradient(circle at center, transparent 60%, rgba(0, 0, 0, 0.1) 100%);
|
||||
}
|
||||
|
||||
.table-items {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 15px;
|
||||
padding: 20px;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* 食物图片样式 */
|
||||
.food-item {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
background-color: var(--food);
|
||||
border-radius: 50%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
border: 3px solid white;
|
||||
}
|
||||
|
||||
.food-item img {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
/* 按钮区域 */
|
||||
.button-area {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 20px;
|
||||
padding: 15px;
|
||||
background-color: var(--secondary);
|
||||
border-radius: 15px;
|
||||
}
|
||||
|
||||
.number-btn {
|
||||
width: 70px;
|
||||
height: 70px;
|
||||
border-radius: 50%;
|
||||
background-color: var(--button);
|
||||
color: white;
|
||||
font-size: 2rem;
|
||||
font-weight: bold;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.3s ease;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
|
||||
.number-btn:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.number-btn:active {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
/* 提示信息 */
|
||||
.message {
|
||||
margin-top: 15px;
|
||||
padding: 10px 15px;
|
||||
border-radius: 10px;
|
||||
font-size: 1.2rem;
|
||||
text-align: center;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
|
||||
.message.show {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.correct {
|
||||
background-color: var(--correct);
|
||||
}
|
||||
|
||||
.wrong {
|
||||
background-color: var(--wrong);
|
||||
}
|
||||
|
||||
/* 动画效果 */
|
||||
@keyframes shake {
|
||||
|
||||
0%,
|
||||
100% {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
25% {
|
||||
transform: translateX(-5px);
|
||||
}
|
||||
|
||||
75% {
|
||||
transform: translateX(5px);
|
||||
}
|
||||
}
|
||||
|
||||
.shake {
|
||||
animation: shake 0.3s ease infinite;
|
||||
}
|
||||
|
||||
@keyframes float {
|
||||
|
||||
0%,
|
||||
100% {
|
||||
transform: translateY(0);
|
||||
}
|
||||
|
||||
50% {
|
||||
transform: translateY(-10px);
|
||||
}
|
||||
}
|
||||
|
||||
.float {
|
||||
animation: float 2s ease-in-out infinite;
|
||||
}
|
||||
|
||||
/* 庆祝效果 */
|
||||
.celebration {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
z-index: 100;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
opacity: 0;
|
||||
transition: opacity 0.5s ease;
|
||||
}
|
||||
|
||||
.celebration.show {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.confetti {
|
||||
position: absolute;
|
||||
width: 15px;
|
||||
height: 15px;
|
||||
background-color: var(--primary);
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
@keyframes confetti-fall {
|
||||
0% {
|
||||
transform: translateY(-100vh) rotate(0deg);
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
100% {
|
||||
transform: translateY(100vh) rotate(360deg);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
h1 {
|
||||
font-size: 1.8rem;
|
||||
}
|
||||
|
||||
.table-area {
|
||||
height: 200px;
|
||||
}
|
||||
|
||||
.food-item {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
}
|
||||
|
||||
.food-item img {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.number-btn {
|
||||
width: 50px;
|
||||
height: 50px;
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>美味餐桌</h1>
|
||||
<div class="container">
|
||||
<div class="table-area">
|
||||
<div class="table-items" id="tableItems"></div>
|
||||
</div>
|
||||
|
||||
<div class="button-area">
|
||||
<button class="number-btn" id="btn1">1</button>
|
||||
<button class="number-btn" id="btn2">2</button>
|
||||
<button class="number-btn" id="btn3">3</button>
|
||||
<button class="number-btn" id="btn4">4</button>
|
||||
</div>
|
||||
|
||||
<div class="message" id="message"></div>
|
||||
</div>
|
||||
|
||||
<div class="celebration" id="celebration"></div>
|
||||
|
||||
<script>
|
||||
// 食物图片数组
|
||||
const foodImages = [
|
||||
'🍎', '🍐', '🍊', '🍋', '🍌', '🍉', '🍇', '🍓', '🍈', '🍒', '🍑', '🥭', '🍍', '🥥', '🥝', '🍅', '🥑', '🥦', '🥕'
|
||||
];
|
||||
|
||||
// DOM元素
|
||||
const tableItems = document.getElementById('tableItems');
|
||||
const btn1 = document.getElementById('btn1');
|
||||
const btn2 = document.getElementById('btn2');
|
||||
const btn3 = document.getElementById('btn3');
|
||||
const btn4 = document.getElementById('btn4');
|
||||
const message = document.getElementById('message');
|
||||
const celebration = document.getElementById('celebration');
|
||||
|
||||
// 游戏状态
|
||||
let currentFoodCount = 0;
|
||||
|
||||
// 初始化游戏
|
||||
function initGame() {
|
||||
// 清空餐桌
|
||||
tableItems.innerHTML = '';
|
||||
message.classList.remove('show');
|
||||
|
||||
// 随机生成1-4个食物
|
||||
currentFoodCount = Math.floor(Math.random() * 4) + 1;
|
||||
|
||||
// 在餐桌上放置食物
|
||||
for (let i = 0; i < currentFoodCount; i++) {
|
||||
const randomFood = getRandomFood();
|
||||
const foodItem = createFoodItem(randomFood);
|
||||
tableItems.appendChild(foodItem);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取随机食物
|
||||
function getRandomFood() {
|
||||
const randomIndex = Math.floor(Math.random() * foodImages.length);
|
||||
return foodImages[randomIndex];
|
||||
}
|
||||
|
||||
// 创建食物元素
|
||||
function createFoodItem(food) {
|
||||
const foodItem = document.createElement('div');
|
||||
foodItem.className = 'food-item float';
|
||||
foodItem.innerHTML = `<span style="font-size: 2.5rem">${food}</span>`;
|
||||
return foodItem;
|
||||
}
|
||||
|
||||
// 检查答案
|
||||
function checkAnswer(selectedNumber) {
|
||||
// 清除之前的提示
|
||||
message.classList.remove('show');
|
||||
|
||||
if (selectedNumber === currentFoodCount) {
|
||||
// 答案正确
|
||||
message.textContent = '太棒了!答对了!';
|
||||
message.className = 'message correct show';
|
||||
celebrate();
|
||||
|
||||
// 1秒后生成新题目
|
||||
setTimeout(initGame, 1000);
|
||||
} else {
|
||||
// 答案错误
|
||||
message.textContent = `不对哦!正确答案是 ${currentFoodCount} 个食物~`;
|
||||
message.className = 'message wrong show';
|
||||
|
||||
// 让餐桌上的食物抖动
|
||||
const foodItems = tableItems.querySelectorAll('.food-item');
|
||||
foodItems.forEach(item => {
|
||||
item.classList.add('shake');
|
||||
});
|
||||
|
||||
// 3秒后停止抖动
|
||||
setTimeout(() => {
|
||||
foodItems.forEach(item => {
|
||||
item.classList.remove('shake');
|
||||
});
|
||||
}, 3000);
|
||||
}
|
||||
}
|
||||
|
||||
// 按钮点击事件
|
||||
btn1.addEventListener('click', () => checkAnswer(1));
|
||||
btn2.addEventListener('click', () => checkAnswer(2));
|
||||
btn3.addEventListener('click', () => checkAnswer(3));
|
||||
btn4.addEventListener('click', () => checkAnswer(4));
|
||||
|
||||
// 庆祝效果
|
||||
function celebrate() {
|
||||
celebration.innerHTML = '';
|
||||
celebration.classList.add('show');
|
||||
|
||||
// 创建彩色纸屑
|
||||
for (let i = 0; i < 50; i++) {
|
||||
const confetti = document.createElement('div');
|
||||
confetti.className = 'confetti';
|
||||
confetti.style.left = `${Math.random() * 100}vw`;
|
||||
confetti.style.backgroundColor = getRandomColor();
|
||||
confetti.style.animation = `confetti-fall ${Math.random() * 2 + 2}s linear forwards`;
|
||||
confetti.style.animationDelay = `${Math.random() * 0.5}s`;
|
||||
celebration.appendChild(confetti);
|
||||
}
|
||||
|
||||
// 3秒后隐藏庆祝效果
|
||||
setTimeout(() => {
|
||||
celebration.classList.remove('show');
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
// 获取随机颜色
|
||||
function getRandomColor() {
|
||||
const colors = ['#FF9AA2', '#FFB7B2', '#FFDAC1', '#E2F0CB', '#B5EAD7', '#C7CEEA'];
|
||||
return colors[Math.floor(Math.random() * colors.length)];
|
||||
}
|
||||
|
||||
// 初始化游戏
|
||||
initGame();
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user