分离js代码

This commit is contained in:
赵鑫 2022-08-04 22:22:05 +08:00
parent 52ad894774
commit 42cc5655da
2 changed files with 15 additions and 17 deletions

14
public/game.js Normal file
View File

@ -0,0 +1,14 @@
const client = io()
client.on('role', (name) => {
role.innerText = name
})
client.on('player', (player) => {
gameButton.classList = player
gameButton.innerText = player == 'player1' ? '玩家1' : '玩家2'
})
gameButton.onclick = () => {
client.emit('click')
}

View File

@ -5,7 +5,6 @@
<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="shortcut icon" href="data:" type="image/x-icon">
<title>陆战棋游戏</title>
<style>
button {
@ -30,22 +29,7 @@
<h2 id="role"></h2>
<button id="gameButton">玩家1</button>
<script src="/socket.io/socket.io.min.js"></script>
<script>
const client = io()
client.on('role', (name) => {
role.innerText = name
})
client.on('player', (player) => {
gameButton.classList = player
gameButton.innerText = player == 'player1' ? '玩家1' : '玩家2'
})
gameButton.onclick = () => {
client.emit('click')
}
</script>
<script src="game.js"></script>
</body>
</html>