清理代码
This commit is contained in:
parent
fd23ad7db0
commit
04b6dea183
79
server.js
79
server.js
@ -3,7 +3,7 @@ const app = express()
|
|||||||
app.use(express.static('public'))
|
app.use(express.static('public'))
|
||||||
const host = process.env.HOST || '0.0.0.0'
|
const host = process.env.HOST || '0.0.0.0'
|
||||||
const port = process.env.PORT || 3000
|
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 io = require('socket.io')(server)
|
||||||
|
|
||||||
const clients = []
|
const clients = []
|
||||||
@ -56,81 +56,4 @@ 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