示例成品 · 平台演示,按左边这组点选真跑出来的
这是为您孩子放学后准备的一款“打地鼠对战小游戏”HTML代码,孩子用手指点地鼠,和AI比谁反应快,还自带休息提醒。
```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>🐹 打地鼠对战 - AI陪玩</title>
<style>
/* ===== 全局样式 ===== */
:root {
--sky-top: #87CEEB;
--sky-bottom: #B5E8C8;
--grass: #6BC76B;
--grass-dark: #4CAF50;
--hole-dark: #5C4033;
--hole-light: #8B6914;
--player-color: #4285F4;
--player-light: #7BAAF7;
--ai-color: #FF9800;
--ai-light: #FFB74D;
--btn-bg: #FF6B6B;
--btn-hover: #FF5252;
--card-bg: #FFFEF7;
--text-dark: #3E3A39;
--text-light: #FFFFFF;
--shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
--shadow-sm: 0 3px 8px rgba(0, 0, 0, 0.1);
--radius: 20px;
--radius-sm: 12px;
}
* {
margin: 0;
padding: 0;
box-sizing: border-box;
-webkit-tap-highlight-color: transparent;
}
body {
font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Noto Sans SC', sans-serif;
background: linear-gradient(180deg, var(--sky-top) 0%, var(--sky-bottom) 55%, var(--grass) 55%, var(--grass-dark) 100%);
min-height: 100vh;
min-height: 100dvh;
display: flex;
justify-content: center;
align-items: center;
overscroll-behavior: none;
touch-action: manipulation;
user-select: none;
-webkit-user-select: none;
overflow: hidden;
}
/* 天空装饰 */
.sky-decor {
position: fixed;
pointer-events: none;
z-index: 0;
}
.sun {
top: 18px;
left: 18px;
font-size: 42px;
animation: sunGlow 3s ease-in-out infinite;
}
.cloud1 {
top: 35px;
right: 40px;
font-size: 45px;
opacity: 0.85;
animation: cloudMove 8s ease-in-out infinite;
}
.cloud2 {
top: 10px;
right: 120px;
font-size: 30px;
opacity: 0.6;
animation: cloudMove 6s ease-in-out infinite reverse;
}
.flower1 {
bottom: 8px;
left: 15px;
font-size: 28px;
animation: sway 4s ease-in-out infinite;
}
.flower2 {
bottom: 5px;
right: 20px;
font-size: 24px;
animation: sway 3.5s ease-in-out infinite reverse;
}
@keyframes sunGlow {
0%,
100% {
transform: scale(1);
}
50% {
transform: scale(1.12);
}
}
@keyframes cloudMove {
0%,
100% {
transform: translateX(0);
}
50% {
transform: translateX(25px);
}
}
@keyframes sway {
0%,
100% {
transform: rotate(-5deg);
}
50% {
transform: rotate(5deg);
}
}
/* ===== 游戏容器 ===== */
.game-container {
position: relativ
点左边「开工 · 直接出成品」,出一份你自己的版本(文字免费)