Timeout-per-turn Logic For A Game
I'm creating a game in telegram bot and now i already reached the 'PLAYING' state. The most difficult part is the timeout-per-turn algorithm (for me). Here's the breakdown: Game
Solution 1:
Sounds like what you want is a clearTimeout. Basically, you would clear the timeout if the player answers within the next five seconds, otherwise, you carry on with kicking the player out of the game as normal. You can get the timeout ID as a return value from setTimeout
.
I'm making an assumption on your code, but this would basically be how it would go:
var playerTimeout = setTimeout(function () {
removePlayer(player);
startNextPlayersTurn();
}, 5000);
player.on('answer', function() {
clearTimeout(playerTimeout);
startNextPlayersTurn();
});
Post a Comment for "Timeout-per-turn Logic For A Game"