我正在节点和套接字中创建绘图/猜测游戏。简单地说:我有一个类Room、Game(扩展了 Room)和一个类Round(每场 10 个)。每轮一个用户被指定为抽屉,猜测者有45 秒的时间来猜测这个词。
在第一次猜测计时器是否高于 20 秒时,计时器将减少到 20 秒。
我不确定,但这就是我开始的方式:
班级回合:
function Round(id, game){
var ROUNDTIME = 45,
timer = new Date();
this.id = id;
this.game = game;
this.endTime = timer.setSeconds(timer.getSeconds() + ROUNDTIME);
...
}
类游戏:
function Game(){
this.MAX_ROUNDS = 10;
this.rounds = [];
this.currentRound = null;
...
}
Game.prototype.start = function(){
this.nextRound;
}
Game.prototype.nextRound = function(){
if(this.rounds.length <= this.MAX_ROUNDS){
this.currentRound = new Round(this.rounds.length + 1, this);
...
} else {
this.endGame();
}
}
Game.prototype.endGame = function(){
...
}
之后,我有一个 Round 函数,每次提交答案/消息时都会检查答案。在第一次回答时,我将 endTime 减少到剩下 20 秒。
所以有2个问题:
- 这是一种正确/良好的实用方法吗?
- 我应该如何将它进一步实施到应用程序本身?(setInterval of 1 seconds with emit?还是在达到 endDate 时简单地发出?还是其他方式?)