分离js代码
This commit is contained in:
parent
52ad894774
commit
42cc5655da
14
public/game.js
Normal file
14
public/game.js
Normal 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')
|
||||
}
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user