webrtc实现双人语音对战贪吃蛇游戏代码
代码语言:html
所属分类:游戏
代码描述:webrtc实现双人语音对战贪吃蛇游戏代码
代码标签: webrtc 双人 语音 对战 贪吃蛇 游戏 代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!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>WebRTC 双人语音贪吃蛇</title>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/pushclient.js"></script>
<script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/qrcode.min.js"></script>
<style>
:root {
--primary: #007bff;
--success: #28a745;
--warning: #ffc107;
--danger: #dc3545;
--dark: #343a40;
--board-bg: #1a1a2e;
--p1-color: #00d2ff;
--p2-color: #ff4757;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
background: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
color: #eee;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
padding: 10px;
}
.container {
width: 100%;
max-width: 600px;
background: rgba(20, 20, 40, 0.95);
border-radius: 16px;
box-shadow: 0 10px 40px rgba(0,0,0,0.5), 0 0 80px rgba(0,210,255,0.05);
overflow: hidden;
display: flex;
flex-direction: column;
border: 1px solid rgba(255,255,255,0.08);
}
header {
background: linear-gradient(135deg, #0f0c29, #1a1a2e);
color: white;
padding: 15px;
text-align: center;
position: relative;
border-bottom: 1px solid rgba(255,255,255,0.06);
}
header h3 { font-weight: 700; letter-spacing: 1px; }
.status-bar {
background: rgba(255,255,255,0.03);
padding: 10px 15px;
border-bottom: 1px solid rgba(255,255,255,0.06);
display: flex;
justify-content: space-between;
align-items: center;
font-size: 0.9rem;
flex-wrap: wrap;
gap: 10px;
}
.status-dot {
height: 10px; width: 10px;
background-color: #555;
border-radius: 50%;
display: inline-block;
margin-right: 5px;
transition: all 0.3s;
}
.status-connected .status-dot { background-color: var(--success); box-shadow: 0 0 8px var(--success); }
.score-board {
width: 100%;
display: flex;
justify-content: space-between;
font-weight: bold;
background: rgba(255,255,255,0.04);
padding: 8px 12px;
border-radius: 8px;
text-align: center;
border: 1px solid rgba(255,255,255,0.06);
}
.p1-score { color: var(--p1-color); }
.p2-score { color: var(--p2-color); }
.timer-display { color: var(--warning); font-size: 1.1em; }
.game-area {
padding: 10px;
display: flex;
justify-content: center;
align-items: center;
background: rgba(0,0,0,0.2);
}
canvas {
background-color: var(--board-bg);
box-shadow: 0 0 20px rgba(0,0,0,0.5), inset 0 0 30px rgba(0,0,0,0.3);
border-radius: 6px;
touch-action: none;
border: 2px solid rgba(255,255,255,0.08);
}
.d-pad {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 5px;
width: 180px;
margin: 10px auto;
}
.d-pad button {
padding: 15px;
background: rgba(255,255,255,0.08);
border: 1px solid rgba(255,255,255,0.12);
border-radius: 10px;
font-size: 1.5rem;
color: #ccc;
cursor: pointer;
transition: all 0.15s;
}
.d-pad button:active { background: rgba(255,255,255,0.2); transform: scale(0.95); }
.d-btn-up { grid-column: 2; grid-row: 1; }
.........完整代码请登录后点击上方下载按钮下载查看
















网友评论0