canvas实现酸雨生存挑战小游戏代码
代码语言:html
所属分类:游戏
代码描述:canvas实现酸雨生存挑战小游戏代码,选用不同材料来绘制房子,不能让酸雨腐蚀到人类,预算有限,一定要精打细算, 玩法 1. 选择材料 - 5种不同材料(木板、砖块、石头、玻璃、钢铁) 2. 绘制房屋 - 在画布上拖拽鼠标绘制建筑保护下方的3个小人 3. 开始酸雨 - 点击按钮后酸雨开始降落 4. 坚持20秒 - 如果建筑被腐蚀穿透,酸雨滴到人就失败 材料特性 | 材料 | 价格 | 耐久 | 抗酸性 | | 木板 | 5
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>酸雨建房 - 保护人类</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
background: #1a1a2e;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
font-family: 'Microsoft YaHei', sans-serif;
overflow: hidden;
}
#gameContainer {
position: relative;
}
canvas {
border: 2px solid #444;
cursor: crosshair;
display: block;
}
#ui {
position: absolute;
top: 10px;
left: 10px;
right: 10px;
display: flex;
justify-content: space-between;
align-items: flex-start;
pointer-events: none;
z-index: 10;
}
#materials {
display: flex;
gap: 8px;
pointer-events: all;
}
.mat-btn {
padding: 8px 14px;
border: 3px solid #555;
border-radius: 8px;
cursor: pointer;
font-size: 13px;
font-weight: bold;
color: #fff;
text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
transition: all 0.2s;
position: relative;
}
.mat-btn:hover { transform: scale(1.05); }
.mat-btn.selected { border-color: #fff; box-shadow: 0 0 15px rgba(255,255,255,0.5); }
.mat-btn .cost { font-size: 10px; display: block; opacity: 0.8; }
.mat-btn .durability { font-size: 10px; display: block; color: #aff; }
#info {
text-align: right;
pointer-events: all;
}
#info div {
color: #fff;
font-size: 14px;
margin-bottom: 4px;
text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
}
#timer { font-size: 24px !important; color: #ff0 !important; font-weight: bold; }
#budget { color: #0f0 !important; }
#startBtn {
padding: 12px 30px;
font-size: 18px;
background: linear-gradient(135deg, #e74c3c, #c0392b);
color: #fff;
border: none;
border-radius: 10px;
cursor: pointer;
pointer-events: all;
font-weight: bold;
transition: all 0.3s;
}
#startBtn:hover { transform: scale(1.1); background: linear-gradient(135deg, #ff6b6b, #e74c3c); }
#clearBtn {
padding: 8px 16px;
font-size: 13px;
background: #555;
color: #fff;
border: none;
border-radius: 6px;
cursor: pointer;
pointer-events: all;
margin-top: 4px;
}
#overlay {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
display: flex;
justify-content: center;
align-items: center;
background: rgba(0,0,0,0.7);
z-index: 20;
}
#overlay.hidden { display: none; }
#overlayContent {
text-align: center;
color: #fff;
}
#overlayContent h1 { font-size: 48px; margin-bottom: 20px; }
#overlayContent p { font-size: 18px; margin-bottom: 10px; line-height: 1.6; }
#overlayContent button {
padding: 15px 40px;
font-size: 20px;
margin-top: 20px;
background: linear-gradient(135deg, #2ecc71, #27ae60);
color: #fff;
border: none;
border-radius: 10px;
cursor: pointer;
font-weight: bold;
}
#overlayContent button:hover { transform: scale(1.05); }
.win h1 { color: #2ecc71; }
.lose h1 { color: #e74c3c; }
#eraseBtn {
padding: 8px 14px;
border: 3px solid #555;
border-radius: 8p.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0