Commit 7cddcdc0 authored by 李维's avatar 李维

添加倒计时逻辑

parent e9739239
......@@ -19,6 +19,8 @@ const MSG_SWITCHSIDE = "msg_switch_side";
const MSG_ROLLING = "msg_rolling";
const MSG_GO = "msg_go";
const MSG_BACK = "msg_back";
const MSG_TIMEOUT = "msg_timeout";
const MSG_FINISH = "msg_finish";
const MSG_PLAYER_TO_TREE = "msg_player_to_tree";
const MSG_PLAYER_TO_HOME = "msg_player_to_home";
const MSG_PROFIX_END = "__END__";
......@@ -181,6 +183,7 @@ export default class SceneComponent extends MyCocosSceneComponent {
this.loadingLayer.setMaxPlayerNumber(2);
this.loadingLayer.onLoadFinished(() => {
this.initSide();
this.initTimer();
});
}
......@@ -354,6 +357,27 @@ export default class SceneComponent extends MyCocosSceneComponent {
});
}
timerCount = 10;
timeLabel = null;
// 初始化倒计时
initTimer() {
const timerHandle = () => {
if(this.timerCount > 0) {
this.timerCount --;
this.timeLabel.string = this.timerCount + "";
} else {
// 时间到
if(this.isRoomOwner) {
// 房主发起时间到事件
this.runEvent(MSG_TIMEOUT, {});
}
this.unschedule(timerHandle);
}
}
this.timeLabel = cc.find("Canvas/timer/count").getComponent(cc.Label);
this.schedule(timerHandle,1);
}
// 用户自定义事件
eventsMap = {};
registerEvent(name, callback, endCallback?) {
......@@ -613,6 +637,22 @@ export default class SceneComponent extends MyCocosSceneComponent {
})
})
// 时间到
this.registerEvent(MSG_TIMEOUT, (param, next) => {
console.log("时间到")
this.turntable.disable();
this.turntable.stopBlink();
setTimeout(() => {
next()
}, 2000);
}, ()=>{
this.runEvent(MSG_FINISH, {})
})
// 结束
this.registerEvent(MSG_FINISH, (param, next) => {
console.log("游戏结束")
})
}
// 获取下一道题的索引
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment