添加自动按钮
This commit is contained in:
parent
af239b349e
commit
c0d9e161bf
@ -1,5 +1,6 @@
|
|||||||
const player = io()
|
const player = io()
|
||||||
let myNumber = 0
|
let myNumber = 0
|
||||||
|
let autoPlayer = 0
|
||||||
|
|
||||||
player.on('alert', (message) => {
|
player.on('alert', (message) => {
|
||||||
alert(message)
|
alert(message)
|
||||||
@ -34,3 +35,14 @@ function makeCards(n) {
|
|||||||
if (n == 0) return ''
|
if (n == 0) return ''
|
||||||
return '['.repeat(n) + ']'
|
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'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
<p>
|
<p>
|
||||||
<button id="buttonJoin" style="color:red;" onclick="player.emit('join')">加入</button>
|
<button id="buttonJoin" style="color:red;" onclick="player.emit('join')">加入</button>
|
||||||
<button id="buttonGo" onclick="player.emit('go')">出牌</button>
|
<button id="buttonGo" onclick="player.emit('go')">出牌</button>
|
||||||
|
<button id="buttonAuto">自动</button>
|
||||||
</p>
|
</p>
|
||||||
<p id="cardsDisplay"></p>
|
<p id="cardsDisplay"></p>
|
||||||
<script src="/socket.io/socket.io.js"></script>
|
<script src="/socket.io/socket.io.js"></script>
|
||||||
|
Loading…
Reference in New Issue
Block a user