// Learn cc.Class:
//  - https://docs.cocos.com/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: require("BaseGameStates"),

    properties: {
        timelabel: cc.Label,
    },

    // LIFE-CYCLE CALLBACKS:
    onLoad() {

        this._super();
        this.init();
        this.UiController.actions();
        this._game_time = this.game_time;

        this.timelabel.string = "01:00";
        if (this._game_time >= 0) {
            this.schedule(function() {
                if (this.GameMode._gamestart) { this.DoSomething(); }
            }, 1);
        }




    },

    start() {

    },
    // update (dt) {},
    DoSomething() { // 倒计时算法
        if (this._game_time >= 1) {
            this._game_time--;

            this.minu = Math.floor(this._game_time / 60) //分钟

            this.seco = Math.floor(this._game_time % 60) //分钟
            if (this.minu < 10) {
                this._minu = "0" + this.minu;
            } else {
                this._minu = this.minu;
            }
            if (this.seco < 10) {
                this._seco = "0" + this.seco;
            } else {
                this._seco = this.seco;
            }
            this.timelabel.string = this._minu + ":" + this._seco; //场景中文本框显示 
        }
    },
    init() {
        this.GameMode = cc.find("GameMode").getComponent("GameMode");
        this.UiController = cc.find("Canvas/UiController").getComponent('UiController');

    },

});