Compare commits
No commits in common. "5018eefddb92af063bc4f8d45790a4950ec1cef7" and "fd23ad7db0708b114a541588608b22fa0b668e19" have entirely different histories.
5018eefddb
...
fd23ad7db0
@ -5,61 +5,14 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@200;300;400;500;600;700;900&display=swap"
|
||||
rel="stylesheet">
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>陆战棋</title>
|
||||
<title>陆战棋游戏</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="game">
|
||||
<div id="gameboard"></div>
|
||||
<div id="sidebar">
|
||||
<div id="display">
|
||||
<h1>陆 战 棋</h1>
|
||||
<h2 class="player1">黑方: 10.10.10.20</h2>
|
||||
<h2 class="player2">红方: </h2>
|
||||
<h2>当前时间: 12 : 25</h2>
|
||||
<h2>本局时间: 00 : 00</h2>
|
||||
<div id="buttons-container">
|
||||
<button>参 战</button>
|
||||
<button>就 绪</button>
|
||||
<button>认 输</button>
|
||||
<button>离 开</button>
|
||||
</div>
|
||||
</div>
|
||||
<div id="pieces-container">
|
||||
<div class="title">棋 子 </div>
|
||||
<div class="piece player2">军 旗</div>
|
||||
<div class="piece player2">司 令</div>
|
||||
<div class="piece player2">军 长</div>
|
||||
<div class="piece player2">师 长</div>
|
||||
<div class="piece player2">师 长</div>
|
||||
<div class="piece player2">旅 长</div>
|
||||
<div class="piece player2">旅 长</div>
|
||||
<div class="piece player2">团 长</div>
|
||||
<div class="piece player2">团 长</div>
|
||||
<div class="piece player2">营 长</div>
|
||||
<div class="piece player2">营 长</div>
|
||||
<div class="piece player2">连 长</div>
|
||||
<div class="piece player2">连 长</div>
|
||||
<div class="piece player2">连 长</div>
|
||||
<div class="piece player2">排 长</div>
|
||||
<div class="piece player2">排 长</div>
|
||||
<div class="piece player2">排 长</div>
|
||||
<div class="piece player2">工 兵</div>
|
||||
<div class="piece player2">工 兵</div>
|
||||
<div class="piece player2">工 兵</div>
|
||||
<div class="piece player2">地 雷</div>
|
||||
<div class="piece player2">地 雷</div>
|
||||
<div class="piece player2">地 雷</div>
|
||||
<div class="piece player2">炸 弹</div>
|
||||
<div class="piece player2">炸 弹</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h1>陆战棋游戏</h1>
|
||||
<h2 id="role"></h2>
|
||||
<button id="gameButton">玩家1</button>
|
||||
<script src="/socket.io/socket.io.min.js"></script>
|
||||
<script src="game.js"></script>
|
||||
</body>
|
||||
|
@ -1,84 +1,13 @@
|
||||
* {
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
box-sizing: border-box;
|
||||
font-family: 'Noto Serif SC', serif;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 1280px;
|
||||
padding: 1rem;
|
||||
margin: 0 auto;
|
||||
background-color: #6a6;
|
||||
}
|
||||
|
||||
#game {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
#gameboard {
|
||||
width: 982px;
|
||||
height: 1248px;
|
||||
background-image: url(board.png);
|
||||
}
|
||||
|
||||
#sidebar {
|
||||
}
|
||||
|
||||
#display {
|
||||
width: 240px;
|
||||
height: 440px;
|
||||
color: #030;
|
||||
display: flex;
|
||||
flex-flow: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
#buttons-container,
|
||||
#pieces-container {
|
||||
width: 240px;
|
||||
padding: 20px;
|
||||
gap: 20px;
|
||||
display: flex;
|
||||
flex-flow: row wrap;
|
||||
justify-content: space-between;
|
||||
border: 4px #363 dashed;
|
||||
button {
|
||||
padding: 0.5rem;
|
||||
color: lightgray;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.player1 {
|
||||
color: #333;
|
||||
color: black;
|
||||
}
|
||||
|
||||
.player2 {
|
||||
color: #833;
|
||||
}
|
||||
|
||||
button,
|
||||
.piece {
|
||||
width: 80px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
font-size: 24px;
|
||||
font-weight: 900;
|
||||
border-radius: 4px;
|
||||
border: double 3px black;
|
||||
text-shadow: 0 1px 0px white;
|
||||
box-shadow: 1px 1px 2px black;
|
||||
background: linear-gradient(to bottom, #fff, #ccc, #ddd);
|
||||
}
|
||||
|
||||
.title {
|
||||
width: 80px;
|
||||
height: 40px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 24px;
|
||||
font-weight: 900;
|
||||
color: red;
|
||||
}
|
||||
|
79
server.js
79
server.js
@ -3,7 +3,7 @@ const app = express()
|
||||
app.use(express.static('public'))
|
||||
const host = process.env.HOST || '0.0.0.0'
|
||||
const port = process.env.PORT || 3000
|
||||
const server = app.listen(port, host, () => console.log(`陆战棋游戏服务运行在 http://${host}:${port}/`))
|
||||
const server = app.listen(port, host, () => console.log(`陆战棋游戏运行在:http://${host}:${port}/`))
|
||||
const io = require('socket.io')(server)
|
||||
|
||||
const clients = []
|
||||
@ -56,4 +56,81 @@ io.on('connection', (client) => {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// console.log(`${client.handshake.address} 来了`)
|
||||
// client.emit('client', '旁观者')
|
||||
|
||||
// if (players.length < 2) {
|
||||
// players.push(client)
|
||||
// if (players.length == 2) {
|
||||
// // 游戏开始
|
||||
// console.log('玩家就位,游戏开始')
|
||||
// currentPlayer = players[0]
|
||||
// io.emit('currentPlayer', currentPlayer === players[0] ? 'player1' : 'player2')
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (players.length > 0 && client.id == players[0].id) client.emit('client', '玩家1')
|
||||
// else if (players.length == 2 && client.id == players[1].id) client.emit('client', '玩家2')
|
||||
// else client.emit('client', '旁观者')
|
||||
|
||||
// client.on('click', () => {
|
||||
// if (client == currentPlayer) {
|
||||
// // 切换玩家
|
||||
// if (currentPlayer === players[0]) {
|
||||
// currentPlayer = players[1]
|
||||
// io.emit('currentPlayer', 'player2')
|
||||
// } else {
|
||||
// currentPlayer = players[0]
|
||||
// io.emit('currentPlayer', 'player1')
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
|
||||
// client.on('disconnect', () => {
|
||||
// io.emit('client', '旁观者')
|
||||
// if (players.includes(client)) {
|
||||
// const playerNumber = players.indexOf(client)
|
||||
// players.splice(playerNumber, 1)
|
||||
// }
|
||||
// if (players.length == 2) {
|
||||
// // 游戏开始
|
||||
// console.log('玩家就位,游戏开始')
|
||||
// currentPlayer = players[0]
|
||||
// io.emit('currentPlayer', currentPlayer === players[0] ? 'player1' : 'player2')
|
||||
// }
|
||||
// if (players.length > 0 && client.id == players[0].id) client.emit('client', '玩家1')
|
||||
// else if (players.length == 2 && client.id == players[1].id) client.emit('client', '玩家2')
|
||||
// else client.emit('client', '旁观者')
|
||||
// })
|
||||
|
||||
// if (players.length < 2) {
|
||||
// players.push(client)
|
||||
// console.log(`玩家${players.length}加入了[${client.handshake.address}]`)
|
||||
// if (players.length == 2) {
|
||||
// // 广播当前是player1(玩家1, 黑色)
|
||||
// currentPlayer = players[0]
|
||||
// io.emit('currentPlayer', 'player1')
|
||||
// // 向玩家1发出点击许可
|
||||
// currentPlayer.emit('yourTurn')
|
||||
// }
|
||||
// } else {
|
||||
// console.log(`旁观者${client.handshake.address}来了`)
|
||||
// if (currentPlayer === players[0]) {
|
||||
// io.emit('currentPlayer', 'player1')
|
||||
// } else {
|
||||
// io.emit('currentPlayer', 'player2')
|
||||
// }
|
||||
// }
|
||||
// client.on('click', () => {
|
||||
// console.log(client.handshake.address, '点了按钮')
|
||||
// if (currentPlayer === players[0]) {
|
||||
// io.emit('currentPlayer', 'player2')
|
||||
// currentPlayer = players[1]
|
||||
// } else {
|
||||
// io.emit('currentPlayer', 'player1')
|
||||
// currentPlayer = players[0]
|
||||
// }
|
||||
// currentPlayer.emit('yourTurn')
|
||||
// })
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user