添加自动按钮

This commit is contained in:
赵鑫 2022-08-18 17:03:18 +08:00
parent af239b349e
commit c0d9e161bf
2 changed files with 13 additions and 0 deletions

View File

@ -1,5 +1,6 @@
const player = io()
let myNumber = 0
let autoPlayer = 0
player.on('alert', (message) => {
alert(message)
@ -34,3 +35,14 @@ function makeCards(n) {
if (n == 0) return ''
return '['.repeat(n) + ']'
}
buttonAuto.addEventListener('click', () => {
if (autoPlayer != 0) {
clearInterval(autoPlayer)
autoPlayer = 0
buttonAuto.style.color = 'black'
} else {
autoPlayer = setInterval(() => player.emit('go'), 1000)
buttonAuto.style.color = 'red'
}
})

View File

@ -20,6 +20,7 @@
<p>
<button id="buttonJoin" style="color:red;" onclick="player.emit('join')">加入</button>
<button id="buttonGo" onclick="player.emit('go')">出牌</button>
<button id="buttonAuto">自动</button>
</p>
<p id="cardsDisplay"></p>
<script src="/socket.io/socket.io.js"></script>