js+css实现保护蚂蚁搬家划线游戏代码
代码语言:html
所属分类:游戏
代码描述:js+css实现保护蚂蚁搬家划线游戏代码,按住鼠标画线造墙。保护蓝色蚂蚁避开红色敌人,到达绿色区域。
代码标签: js css 保护 蚂蚁 搬家 划线 游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SVG 蚂蚁护送游戏</title>
<style>
body {
margin: 0;
overflow: hidden;
background-color: #1a1a1a;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
user-select: none; /* 防止选中文字 */
}
/* 游戏容器 */
#game-container {
position: relative;
width: 100vw;
height: 100vh;
}
/* SVG 画布 */
svg {
width: 100%;
height: 100%;
display: block;
cursor: crosshair;
}
/* UI 浮层 */
#ui-layer {
position: absolute;
top: 0;
left: 0;
width: 100%;
pointer-events: none; /* 让鼠标事件穿透到 SVG */
padding: 20px;
box-sizing: border-box;
}
h1 {
color: white;
margin: 0;
font-size: 24px;
text-shadow: 0 0 5px black;
}
p {
color: #aaa;
margin: 5px 0;
}
#controls {
margin-top: 10px;
pointer-events: auto; /* 按钮需要响应点击 */
}
button {
padding: 10px 20px;
background: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
margin-right: 10px;
transition: background 0.2s;
}
button.clear { background: #ff9800; }
button:hover { opacity: 0.9; }
/* 游戏结束/获胜 弹窗 */
#overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0,0,0,0.8);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
color: white;
z-index: 100;
display: none; /* 默认隐藏 */
}
#overlay h2 { font-size: 48px; margin-bottom: 20px; }
/* SVG 元素样式 */
.wall-line {
stroke: white;
stroke-width: 4;
fill: none;
stroke-linecap: round;
stroke-linejoin: round;
}
.preview-line {
stroke: rgba(255, 255, 255, 0.5);
stroke-width: 2;
fill: none;
stroke-dasharray: 5,5;
}
</style>
</head>
<body>
<div id="game-container">
<svg id="game-svg">
<!-- 动态内容将通过 JS 插入 -->
</svg>
<div id="ui-layer">
<h1>蚂蚁护送计划</h1>
<p>按住鼠标画线造墙。保护蓝色蚂蚁避开红色敌人,到达绿色区域。</p>
<div id="controls">
<button onclick=&qu.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0