js+css实现精简版魔兽世界策略2d人机对战游戏代码
代码语言:html
所属分类:游戏
代码描述:js+css实现精简版魔兽世界策略2d人机对战游戏代码,玩法:造农民采木 ,造兵营 ,造步兵推平对方
代码标签: js css 精简 魔兽 世界 策略 2d 人机 对战 游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>魔兽微战:决战时刻</title>
<style>
/* --- 页面基础样式 --- */
body {
margin: 0;
background-color: #1a1a1a;
color: #fff;
font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
user-select: none;
}
/* --- 游戏容器 --- */
#game-wrapper {
position: relative;
box-shadow: 0 0 50px rgba(0,0,0,0.8);
border: 4px solid #444;
border-radius: 8px;
overflow: hidden;
}
canvas {
display: block;
background-color: #333;
}
/* --- 顶部HUD (资源/血量) --- */
#hud-top {
position: absolute;
top: 0; left: 0; width: 100%;
height: 50px;
background: rgba(0,0,0,0.85);
border-bottom: 2px solid #555;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 20px;
box-sizing: border-box;
font-size: 18px;
font-weight: bold;
z-index: 10;
}
.team-blue { color: #4da6ff; display: flex; align-items: center; gap: 15px; }
.team-red { color: #ff4d4d; display: flex; align-items: center; gap: 15px; flex-direction: row-reverse; }
.res-icon { color: #ffd700; font-size: 1.2em; }
/* --- 底部控制栏 --- */
#hud-bottom {
position: absolute;
bottom: 0; left: 0; width: 100%;
height: 90px;
background: #222;
border-top: 2px solid #555;
display: flex;
justify-content: center;
align-items: center;
gap: 20px;
z-index: 10;
}
/* --- 按钮样式 --- */
.cmd-btn {
width: 140px;
height: 60px;
border: none;
border-radius: 6px;
cursor: pointer;
position: relative;
font-family: inherit;
transition: all 0.1s;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
box-shadow: 0 4px 0 rgba(0,0,0,0.3);
}
.cmd-btn:active { transform: translateY(4px); box-shadow: none; }
.cmd-btn:disabled {
background: #3a3a3a;
color: #777;
cursor: not-allowed;
transform: none;
box-shadow: none;
border: 1px solid #444;
}
/* 按钮具体颜色 */
#btn-worker { background: linear-gradient(#4a6fa5, #3b5985); color: white; }
#btn-worker:hover:not(:disabled) { background: #5a7fb5; }
#btn-barracks { background: linear-gradient(#e6b800, #c29b00); color: #222; }
#btn-barracks:hover:not(:disabled) { background: #ffcc00; }
#btn-soldier { background: linear-gradient(#d9534f, #c9302c); color: white; }
#btn-soldier:hover:not(:disabled) { background: #e66460; }
.btn-title { font-size: 16px; font-weight: bold; }
.btn-cost { font-size: 12px; opacity: 0.9; margin-top: 2px; }
/* --- 游戏结束遮罩 --- */
#overlay {
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0,0,0,0.9);
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 20;
}
#overlay h1 { font-size: 48px; margin-bottom: 10px; text-shadow: 0 0 15px currentColor; }
#overlay p { font-size: 18px; color: #aaa; margin-bottom: 30px; }
.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0