完善关卡逻辑
This commit is contained in:
@@ -4,6 +4,8 @@ import { Block } from "./Block";
|
||||
import { Candy } from "./Candy";
|
||||
import { DOStage } from "../models/DOStage";
|
||||
import { config } from "../constants/config";
|
||||
import { StorageManager } from "../models/StorageManager";
|
||||
import { Utility_ConvertSecondToString } from "../utils/utility";
|
||||
|
||||
|
||||
const { regClass, property } = Laya;
|
||||
@@ -56,8 +58,8 @@ export class Stage extends Laya.Script {
|
||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||
onAwake(): void {
|
||||
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
|
||||
UIManager.getInstance().loadHome();
|
||||
UIManager.getInstance().closeStage();
|
||||
UIManager.getInstance().loadHomeUI();
|
||||
UIManager.getInstance().closeStageUI();
|
||||
})
|
||||
for (var i=0; i<this.obj_blocks.numChildren; i++) {
|
||||
var hbox = this.obj_blocks.getChildAt(i);
|
||||
@@ -101,6 +103,7 @@ export class Stage extends Laya.Script {
|
||||
this.data = doStage
|
||||
|
||||
this.onUpdateScore()
|
||||
this.label_diff.text = this.data.get_difficulty()
|
||||
this.onUpdateMistake()
|
||||
var begin = Date.now()
|
||||
Laya.timer.loop(1000, this, ()=>{
|
||||
@@ -108,12 +111,7 @@ export class Stage extends Laya.Script {
|
||||
this.data.set_duration(this.data.get_duration() + Math.floor((now-begin)/1000))
|
||||
begin = now
|
||||
var last = this.data.get_duration()
|
||||
var hour = Math.floor(last/3600)
|
||||
last = last - hour * 3600
|
||||
var minite = Math.floor(last/60)
|
||||
last = last - minite * 60
|
||||
var second = Math.floor(last)
|
||||
this.label_time.text = `${hour>=10?hour:("0"+hour)}:${minite>=10?minite:("0"+minite)}:${second>10?second:("0"+second)}`
|
||||
this.label_time.text = Utility_ConvertSecondToString(last)
|
||||
})
|
||||
|
||||
var blocks = doStage.get_blocks()
|
||||
@@ -335,7 +333,16 @@ export class Stage extends Laya.Script {
|
||||
if (b) {
|
||||
if (this.getIsComplete()) {
|
||||
console.log("完成关卡")
|
||||
UIManager.getInstance().loadGameDone()
|
||||
StorageManager.getInstance().cleanStage(this.data.get_stageID())//完成关卡清除关卡数据
|
||||
var user = StorageManager.getInstance().getUser()
|
||||
if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) {
|
||||
user.set_isCompletedMain(true)
|
||||
user.update_progress(this.data.get_difficulty(), this.data.get_stageIndex()+1)
|
||||
}
|
||||
else if (this.data.get_stageType() == config.STAGE_TYPE.DC) {
|
||||
user.add_done(this.data.get_stageID())
|
||||
}
|
||||
UIManager.getInstance().loadGameDoneUI()
|
||||
}
|
||||
}
|
||||
else {//失败
|
||||
@@ -343,7 +350,7 @@ export class Stage extends Laya.Script {
|
||||
this.onUpdateMistake()
|
||||
if (this.data.get_mistake() >= config.MISTAKE_MAX) {
|
||||
console.log("关卡失败")
|
||||
// UIManager.getInstance().loadGameOver()
|
||||
UIManager.getInstance().loadGameOverUI()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user