"use strict";
cc._RF.push(module, 'b26a49RCSFPT4C+F7xAd62t', 'GameManager');
// Script/GameManager.ts

"use strict";
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.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
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var GameData_1 = require("./GameData");
var GameTool_1 = require("./tool/GameTool");
var Notification_1 = require("./tool/Notification");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var GameManager = /** @class */ (function (_super) {
    __extends(GameManager, _super);
    function GameManager() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.Camera = null;
        _this.topUI = null;
        _this.Player = null;
        _this.Ground = null;
        _this.Xin = null;
        _this.time = null;
        _this.GameOver = null;
        _this.Tip = null;
        _this.blockPrefab = [];
        return _this;
    }
    GameManager_1 = GameManager;
    // LIFE-CYCLE CALLBACKS:
    GameManager.prototype.onLoad = function () {
        cc.game.setFrameRate(61);
        // 示例使用
        var manager = cc.director.getCollisionManager();
        manager.enabled = true;
        // manager.enabledDebugDraw = true;
        GameManager_1._instance = this;
        // GameData._instance.GM_INFO.probation = false;
        this.Air = [];
        this.Air2 = [];
    };
    GameManager.prototype.onEnable = function () {
        Notification_1.Notification.on("createBlock", this.createBlock, this);
        Notification_1.Notification.on("addScore", this.addScore, this);
        Notification_1.Notification.on("createCrackBlock", this.createCrackBlock, this);
        Notification_1.Notification.on("showGround", this.showGround, this);
        Notification_1.Notification.on("death", this.getDeath, this);
        Notification_1.Notification.on("jump", this.jump, this);
        Notification_1.Notification.on("setData", this.setData, this);
    };
    GameManager.prototype.onDestroy = function () {
        Notification_1.Notification.off("createBlock", this.createBlock);
        Notification_1.Notification.off("addScore", this.addScore);
        Notification_1.Notification.off("createCrackBlock", this.createCrackBlock);
        Notification_1.Notification.off("death", this.getDeath);
        Notification_1.Notification.off("jump", this.jump);
        Notification_1.Notification.off("showGround", this.showGround);
        Notification_1.Notification.off("setData", this.setData);
    };
    //根据是否全面屏，做独立适配方面
    GameManager.prototype.fit = function () {
        this.node.getChildByName("bg2").y = -2167.675;
        var jg = this.setFit();
        if (!jg) {
            this.node.getChildByName("bg2").y = -2100;
            this.topUI.y = 660;
        }
    };
    //判断全面屏
    GameManager.prototype.getSetScreenResolutionFlag = function () {
        var size = cc.winSize;
        var width = size.width;
        var height = size.height;
        if ((height / width) > (16.2 / 9))
            return false;
        return true;
    };
    //判断全面屏适配
    GameManager.prototype.setFit = function () {
        var flag = this.getSetScreenResolutionFlag();
        if (flag) {
        }
        else {
        }
        return flag;
    };
    GameManager.prototype.init = function () {
        this.drop = this.topUI.y - this.Camera.node.y;
        this.score = 0;
        this.oldSpeed = 10;
        this.guide = -1;
        this.begin = true;
        this.over = false;
        this.interfere = false;
        this.round = 0;
        this.level = 0;
        GameData_1.default._instance.GM_INFO.levelMax = 1;
        GameData_1.default._instance.GM_INFO.difficultyMax = 1;
        GameData_1.default._instance.GM_INFO.life = 3;
        this.blockArray = [];
        this.difficultyArray = 0;
        this.cameraMove = false;
        this.countTime = 180;
        this.topUI.getChildByName("xin1").active = true;
        this.topUI.getChildByName("xin2").active = true;
        this.topUI.getChildByName("xin3").active = true;
        this.topUI.getChildByName("star1").active = false;
        this.topUI.getChildByName("star2").active = false;
        this.topUI.getChildByName("star3").active = false;
        GameData_1.default._instance.LEVEL_init();
        this.schedule(this.updateCountDownTime, 1);
    };
    GameManager.prototype.start = function () {
        var _this = this;
        // this.node.on(cc.Node.EventType.TOUCH_START, this.jump, this);
        this.fit();
        this.init();
        // GameData._instance.GM_INFO.probation = false;
        if (GameData_1.default._instance.GM_INFO.probation) {
            this.Player.getComponent("Player").jumpPause = true;
            var tip = this.Tip.getChildByName("tip");
            this.tipShow(tip, -1, true);
        }
        else {
            this.node.getChildByName("Begin").opacity = 0;
            this.node.getChildByName("Begin").scale = 2;
            if (this.node.getChildByName("Begin")) {
                cc.tween(this.node.getChildByName("Begin"))
                    .to(0.5, { opacity: 255, scale: 1 })
                    .delay(0.5)
                    .to(0.5, { opacity: 0, scale: 0 })
                    .call(function () {
                    _this.startGame();
                })
                    .start();
            }
            else {
                setTimeout(function () {
                    _this.startGame();
                }, 1000);
            }
        }
    };
    //开启引导
    GameManager.prototype.startGuide = function (type, revive) {
        var _this = this;
        this.guide = type;
        console.log("startGuide", type);
        if (type == 0) {
            this.careteGuideBlock(1);
        }
        else if (type == 2) {
            var block = this.node.getChildByName("Block").children[this.node.getChildByName("Block").children.length - 1];
            cc.tween(block)
                .to(0.7, { x: 0 })
                .start();
            this.tipHide("tip2", 3, false);
        }
        else if (type == 3) {
            if (revive == true) {
                this.round += 1;
                this.careteGuideBlock(3);
            }
            else {
                var tip = this.Tip.getChildByName("tip3");
                this.tipShow(tip, type, false);
                setTimeout(function () {
                    _this.tipHide("tip3", null, false);
                    _this.round += 1;
                    _this.careteGuideBlock(3);
                }, 3000);
            }
        }
        else if (type == 4) {
            this.round += 1;
            this.careteGuideBlock(4);
        }
        else if (type == 5) {
            this.round += 1;
            this.careteGuideBlock(5);
        }
        else if (type == 6) {
            var block = this.node.getChildByName("Block").children[this.node.getChildByName("Block").children.length - 1];
            cc.tween(block)
                .to(0.7, { x: 0 })
                .start();
            this.tipHide("tip4", 7, revive);
        }
        else if (type == 7) {
            if (revive == true) {
                this.round += 1;
                this.careteGuideBlock(7);
            }
            else {
                var tip = this.Tip.getChildByName("tip5");
                this.tipShow(tip, type, false);
                setTimeout(function () {
                    _this.tipHide("tip5", null, revive);
                    _this.round += 1;
                    _this.careteGuideBlock(7);
                }, 2000);
            }
        }
        else if (type == 8) {
            this.round += 1;
            this.careteGuideBlock(8);
        }
        else if (type == 9) {
            this.Player.getComponent("Player").jumpPause = true;
            var tip_1 = this.Tip.getChildByName("tip6");
            setTimeout(function () {
                _this.tipShow(tip_1, type, false);
            }, 1000);
        }
    };
    GameManager.prototype.tipShow = function (tipName, type, showNext) {
        var _this = this;
        var tip = tipName;
        var left = this.Tip.getChildByName("left");
        var right = this.Tip.getChildByName("right");
        left.width = 0;
        right.width = 0;
        tip.opacity = 0;
        cc.tween(left)
            .to(0.25, { width: 348 })
            .start();
        cc.tween(right)
            .to(0.25, { width: 348 })
            .start();
        cc.tween(tip)
            .delay(0.15)
            .to(0.15, { opacity: 255 })
            .call(function () {
            _this.guide = type;
            if (type == 5)
                _this.guide = 6;
            if (type == 5 || type == 1)
                _this.Player.getComponent("Player").jumpPause = false;
        })
            .start();
        if (showNext == true) {
            this.Tip.getChildByName("btn_next").active = true;
            this.Tip.getChildByName("btn_jump").active = true;
            cc.tween(this.Tip.getChildByName("btn_next"))
                .delay(0.5)
                .to(0.2, { opacity: 255 })
                .start();
            cc.tween(this.Tip.getChildByName("btn_jump"))
                .delay(0.5)
                .to(0.2, { opacity: 255 })
                .start();
        }
        if (tip.name == "tip6") {
            this.Tip.getChildByName("btn_start").active = true;
            cc.tween(this.Tip.getChildByName("btn_start"))
                .delay(1)
                .to(0.2, { opacity: 255 })
                .start();
        }
    };
    //隐藏
    GameManager.prototype.tipHide = function (tipName, num, revive) {
        var _this = this;
        var tip = this.Tip.getChildByName(tipName);
        var left = this.Tip.getChildByName("left");
        var right = this.Tip.getChildByName("right");
        cc.tween(left)
            .delay(0.1)
            .to(0.25, { width: 0 })
            .start();
        cc.tween(right)
            .delay(0.1)
            .to(0.25, { width: 0 })
            .start();
        cc.tween(tip)
            .to(0.12, { opacity: 0 })
            .delay(1.5)
            .call(function () {
            if (tip.name != "tip3" && tipName != "tip5") {
                _this.Player.getComponent("Player").jumpPause = true;
            }
            if (num != null) {
                _this.startGuide(num, revive);
            }
        })
            .start();
    };
    GameManager.prototype.careteGuideBlock = function (type) {
        var _this = this;
        this.Ground.active = false;
        var tip = this.Tip.getChildByName("tip2");
        if (type == 5) {
            tip = this.Tip.getChildByName("tip4");
        }
        this.Player.getComponent("Player").jumpPause = true;
        var block = cc.instantiate(this.blockPrefab[13]);
        var height = this.Player.getComponent("Player").basicHeight + GameData_1.default._instance.GM_INFO.blockMin;
        if (type > 4) {
            height += block.height + GameData_1.default._instance.GM_INFO.blockMax;
            GameData_1.default._instance.CLICK_DATA.height = true;
        }
        block.setPosition(cc.v2(this.round % 2 == 0 ? 480 : -480, height));
        block.parent = this.node.getChildByName("Block");
        var num = 150;
        var time = 3;
        if (type == 1 || type == 5) {
            num = this.round % 2 == 0 ? num : -num;
        }
        else if (type == 3 || type == 4 || type == 7 || type == 8 || type == 9) {
            this.Player.getComponent("Player").jumpPause = false;
            num = -block.x;
            time = 7;
        }
        cc.tween(block)
            .to(time, { x: num })
            .call(function () {
            if (type == 1 || type == 5) {
                if (type == 1)
                    _this.Player.getComponent("Player").jumpPause = true;
                _this.tipShow(tip, type, false);
            }
        })
            .start();
    };
    GameManager.prototype.showGround = function (tempY) {
        var _this = this;
        setTimeout(function () {
            _this.Ground.active = true;
            _this.Ground.y = tempY;
        }, 500);
    };
    GameManager.prototype.guideStart = function () {
        this.tipHide("tip6", null, false);
        this.Tip.getChildByName("btn_next").active = false;
        this.Tip.getChildByName("btn_jump").active = false;
        this.Tip.getChildByName("btn_start").active = false;
        GameData_1.default._instance.GM_INFO.probation = false;
        this.destroyBlock(false);
        this.onDestroy();
        cc.director.loadScene("GameScene");
    };
    //下一步
    GameManager.prototype.guideNext = function () {
        if (this.guide == -1) {
            this.tipHide("tip", 0, false);
            this.Tip.getChildByName("btn_next").active = false;
            this.Tip.getChildByName("btn_jump").active = false;
            this.Tip.getChildByName("btn_start").active = false;
        }
    };
    //跳过
    GameManager.prototype.guideJump = function () {
        this.Tip.getChildByName("btn_next").active = false;
        this.Tip.getChildByName("btn_jump").active = false;
        this.Tip.getChildByName("btn_start").active = false;
        GameData_1.default._instance.GM_INFO.probation = false;
        this.destroyBlock(false);
        this.onDestroy();
        cc.director.loadScene("GameScene");
    };
    GameManager.prototype.jump = function () {
        this.Player.getComponent("Player").jump();
    };
    GameManager.prototype.startGame = function () {
        this.createBlock();
        // this.createAir();
    };
    GameManager.prototype.addScore = function (score) {
        var _this = this;
        GameData_1.default._instance.CLICK_DATA.getScore = parseInt(score);
        GameManager_1._instance.score += parseInt(score);
        GameData_1.default._instance.CLICK_DATA.totalScore = GameManager_1._instance.score;
        this.topUI.getChildByName("nandu").getComponent(cc.Label).string = GameManager_1._instance.score + "";
        var scale = GameManager_1._instance.score / GameData_1.default._instance.LEVEL_INFO.scoreMax;
        cc.tween(this.topUI.getChildByName("progress").getComponent(cc.Sprite))
            .to(0.5, { fillRange: scale })
            .call(function () {
            if (scale >= GameData_1.default._instance.LEVEL_INFO.star1 && !_this.topUI.getChildByName("star1").active) {
                _this.topUI.getChildByName("star1").active = true;
            }
            if (scale >= GameData_1.default._instance.LEVEL_INFO.star2 && !_this.topUI.getChildByName("star2").active) {
                _this.topUI.getChildByName("star2").active = true;
            }
            if (scale >= GameData_1.default._instance.LEVEL_INFO.star3 && !_this.topUI.getChildByName("star3").active) {
                _this.topUI.getChildByName("star3").active = true;
                // GameData._instance.scoreMax = 150000;
            }
        })
            .start();
    };
    GameManager.prototype.createBlock = function () {
        if (this.over == false && this.begin == true) {
            this.Ground.active = false;
            this.Player.getComponent("Player").jumpPause = false;
            var num = Math.floor(Math.random() * 12);
            if (this.round <= 10 && num == 5) {
                num = Math.floor(Math.random() * 6 + 6);
            }
            var block = cc.instantiate(this.blockPrefab[num]);
            var height = this.Player.getComponent("Player").basicHeight + GameData_1.default._instance.GM_INFO.blockMin;
            if (num > GameData_1.default._instance.GM_INFO.blockScale) {
                height += block.height + GameData_1.default._instance.GM_INFO.blockMax;
                GameData_1.default._instance.CLICK_DATA.height = true;
            }
            if (height >= 0 && this.cameraMove == false) {
                this.countHeight = this.Player.getComponent("Player").basicHeight - this.Camera.node.y;
                this.cameraMove = true;
            }
            block.setPosition(cc.v2(this.round % 2 == 0 ? 480 : -480, height));
            block.parent = this.node.getChildByName("Block");
            block.zIndex = 10;
            this.block = null;
            this.block = block;
            this.round += 1;
            this.level += 1;
            if (this.round > GameData_1.default._instance.GM_INFO.levelMax)
                GameData_1.default._instance.GM_INFO.levelMax = this.round;
            GameData_1.default._instance.CLICK_DATA.level = this.round;
            GameData_1.default._instance.CLICK_DATA.round = this.level;
            GameData_1.default._instance.LEVEL_INFO.layer += GameData_1.default._instance.LEVEL_INFO.layerAdd;
            if (GameData_1.default._instance.LEVEL_INFO.speed < 2)
                GameData_1.default._instance.LEVEL_INFO.speed += GameData_1.default._instance.LEVEL_INFO.addSpeed;
            if (GameData_1.default._instance.LEVEL_INFO.reduceSpeed <= 100)
                GameData_1.default._instance.LEVEL_INFO.reduceSpeed += GameData_1.default._instance.LEVEL_INFO.jiansu;
            if (this.round == GameData_1.default._instance.LEVEL_INFO.round1)
                GameData_1.default._instance.LEVEL_INFO.jiansu = 2;
            else if (this.round == GameData_1.default._instance.LEVEL_INFO.round2)
                GameData_1.default._instance.LEVEL_INFO.jiansu = 1;
            else if (this.round == GameData_1.default._instance.LEVEL_INFO.round3)
                GameData_1.default._instance.LEVEL_INFO.jiansu = 0.5;
        }
    };
    //产生空气
    GameManager.prototype.createAir = function () {
        for (var i = 0; i < 100; i++) {
            this.Ground.active = false;
            var num = Math.floor(Math.random() * 12);
            if (this.round <= 10 && num == 5) {
                num = Math.floor(Math.random() * 6 + 6);
            }
            var block = cc.instantiate(this.blockPrefab[num]);
            var height = this.Player.getComponent("Player").basicHeight + GameData_1.default._instance.GM_INFO.blockMin;
            if (num > GameData_1.default._instance.GM_INFO.blockScale) {
                height += block.height + GameData_1.default._instance.GM_INFO.blockMax;
                GameData_1.default._instance.CLICK_DATA.height = true;
            }
            block.setPosition(cc.v2(this.round % 2 == 0 ? 480 : -480, height));
            block.parent = this.node.getChildByName("Block");
            block.zIndex = 10;
            this.round += 1;
            this.level += 1;
            if (this.round > GameData_1.default._instance.GM_INFO.levelMax)
                GameData_1.default._instance.GM_INFO.levelMax = this.round;
            GameData_1.default._instance.CLICK_DATA.level = this.round;
            GameData_1.default._instance.CLICK_DATA.round = this.level;
            GameData_1.default._instance.LEVEL_INFO.layer += GameData_1.default._instance.LEVEL_INFO.layerAdd;
            GameData_1.default._instance.LEVEL_INFO.speed += GameData_1.default._instance.LEVEL_INFO.addSpeed;
            if (GameData_1.default._instance.LEVEL_INFO.reduceSpeed <= 80)
                GameData_1.default._instance.LEVEL_INFO.reduceSpeed += GameData_1.default._instance.LEVEL_INFO.jiansu;
            if (this.round == GameData_1.default._instance.LEVEL_INFO.round1)
                GameData_1.default._instance.LEVEL_INFO.jiansu = 2;
            else if (this.round == GameData_1.default._instance.LEVEL_INFO.round2)
                GameData_1.default._instance.LEVEL_INFO.jiansu = 1;
            else if (this.round == GameData_1.default._instance.LEVEL_INFO.round3)
                GameData_1.default._instance.LEVEL_INFO.jiansu = 0.5;
        }
    };
    GameManager.prototype.clearAir = function () {
        cc.director.loadScene("GameScene");
    };
    //虚假碎裂块
    GameManager.prototype.createCrackBlock = function () {
        this.interfere = true;
        GameData_1.default._instance.CLICK_DATA.fake = this.interfere;
        if (this.round > 1)
            this.destroyBlock(true);
        if (this.over == false && this.begin == true) {
            var block = cc.instantiate(this.blockPrefab[12]);
            var height = this.Player.getComponent("Player").basicHeight;
            if (GameData_1.default._instance.CLICK_DATA.height == true) {
                height += block.height / 2;
            }
            block.setPosition(cc.v2(this.round % 2 == 0 ? 480 : -480, height));
            block.parent = this.node.getChildByName("CrackBlock");
            block.zIndex = 1;
        }
    };
    GameManager.prototype.destroyBlock = function (type) {
        if (type == true) {
            if (this.node) {
                if (this.node.getChildByName("CrackBlock")) {
                    if (this.node.getChildByName("CrackBlock").children) {
                        var block2 = this.node.getChildByName("CrackBlock").children;
                        for (var i = 0; i < block2.length; i++) {
                            if (block2[i]) {
                                block2[i].getComponent("Block").hide();
                            }
                        }
                    }
                }
            }
        }
        else {
            var block = this.node.getChildByName("Block").children;
            for (var i = 0; i < block.length; i++) {
                if (block[i]) {
                    block[i].active = false;
                }
            }
        }
    };
    GameManager.prototype.xinAction = function () {
        var xin = this.topUI.getChildByName("xin1");
        if (GameData_1.default._instance.GM_INFO.life == 2)
            xin = this.topUI.getChildByName("xin3");
        else if (GameData_1.default._instance.GM_INFO.life == 1)
            xin = this.topUI.getChildByName("xin2");
        cc.tween(xin)
            .to(0.6, { scale: 1.6, opacity: 0 })
            .call(function () {
            xin.active = false;
        })
            .start();
    };
    //死亡
    GameManager.prototype.getDeath = function (data) {
        var _this = this;
        if (data == true) {
            this.destroyBlock(false);
            cc.tween(this.Player)
                .to(1, { y: -500 }, { easing: 'cubicIn' })
                .call(function () {
                _this.Player.getComponent("Player").init();
                // this.Player.getComponent("Player").jumpPause = true;
                if (_this.guide > 5) {
                    if (_this.guide == 6) {
                        _this.guide = 5;
                        _this.round = 2;
                        _this.startGuide(5, true);
                    }
                    else {
                        _this.round = 1;
                        _this.startGuide(6, true);
                    }
                }
                else {
                    _this.round = 0;
                    _this.startGuide(3, true);
                }
            })
                .delay(0.5)
                .call(function () {
            })
                .start();
        }
        else {
            if (GameData_1.default._instance.GM_INFO.life > 0) {
                GameData_1.default._instance.GM_INFO.life -= 1;
                this.getDevive(1);
            }
            else {
                GameData_1.default._instance.GM_INFO.life = -1;
                this.getDevive(3);
            }
        }
    };
    //复活
    GameManager.prototype.getDevive = function (time) {
        var _this = this;
        this.round = 0;
        GameData_1.default._instance.LEVEL_init();
        if (this.topUI.getChildByName("star3").active == true) {
            // GameData._instance.LEVEL_INFO.scoreMax = 150000;
        }
        this.interfere = false;
        GameData_1.default._instance.CLICK_DATA.fake = this.interfere;
        this.destroyBlock(false);
        var block2 = this.node.getChildByName("CrackBlock").children;
        for (var i = 0; i < block2.length; i++) {
            if (block2[i]) {
                block2[i].active = false;
            }
        }
        // this.blockArray = [];
        var actionTime = 1;
        if (this.Player.y > 500) {
            actionTime = (this.Player.y + 500) / 1000 * actionTime;
        }
        cc.tween(this.Player)
            .to(actionTime, { y: -500 }, { easing: 'cubicIn' })
            .call(function () {
            _this.Player.getComponent("Player").xinAction();
        })
            .delay(0.5)
            .call(function () {
            _this.xinAction();
            _this.Player.getComponent("Player").init();
            if (time > 1) {
                _this.Xin.parent.active = true;
                _this.Xin.getComponent(cc.Sprite).fillRange = 0;
                cc.tween(_this.Xin.getComponent(cc.Sprite))
                    .to(time, { fillRange: 1 })
                    .delay(0.3)
                    .call(function () {
                    _this.Xin.parent.active = false;
                })
                    .delay(0)
                    .call(function () {
                    _this.createBlock();
                })
                    .start();
            }
            else {
                setTimeout(function () {
                    _this.createBlock();
                }, (time + 0.5) * 1000);
            }
        })
            .start();
    };
    GameManager.prototype.setData = function () {
        GameData_1.default._instance.CLICK_DATA.totalScore = GameManager_1._instance.score;
        GameData_1.default._instance.CLICK_DATA.timer = this.countTime;
        GameData_1.default._instance.CLICK_DATA.level = this.round;
        GameData_1.default._instance.CLICK_DATA.round = this.level;
        //CLICK_DATA 数据处理完毕后调用上传接口  上传接口内CLICK_DATA不做改变
        GameTool_1.GameTool.setGameData();
    };
    //获取matchId  用于上传每次点击数据里面记录id方便查询
    GameManager.prototype.getMatchId = function () {
        var matchId = cc.sys.localStorage.getItem("matchId");
        if (matchId == "undifend" || matchId == null) {
            matchId = this.setMatchId();
        }
        else {
            if (this.containsNanana(matchId) == true) {
                matchId = this.setMatchId();
            }
            else {
                var char = parseInt(matchId[10]);
                if (this.level == 1) {
                    char += 1;
                }
                matchId = matchId.slice(0, 10) + char + "";
                GameData_1.default._instance.GM_INFO.matchId = matchId;
                cc.sys.localStorage.setItem("matchId", matchId);
            }
        }
        return matchId;
    };
    //检测matchId 如果有缓存以前的nanana数据清除
    GameManager.prototype.containsNanana = function (str) {
        return /na/i.test(str);
    };
    //重新设置MatchId
    GameManager.prototype.setMatchId = function () {
        // 定义包含可用字符的字符集
        var characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        // 创建一个数组以保存随机字符
        var uuidArray = [];
        // 循环10次 生成10位的UUID
        for (var i = 0; i < 10; i++) {
            // 生成随机索引，范围是字符集的长度
            var randomIndex = Math.floor(Math.random() * characters.length);
            // 从字符集中获取随机字符
            var randomChar = characters.charAt(randomIndex);
            // 将字符添加到数组中
            uuidArray.push(randomChar);
        }
        var data = uuidArray.join('') + 1 + "";
        cc.sys.localStorage.setItem("matchNumber", 1);
        cc.sys.localStorage.setItem("matchId", data);
        GameData_1.default._instance.GM_INFO.matchId = data;
        return data;
    };
    GameManager.prototype.updateCountDownTime = function () {
        var _this = this;
        if (this.countTime > 0 && !GameData_1.default._instance.GM_INFO.probation) {
            this.countTime -= 1;
            this.time.string = this.getTimeMargin(this.countTime);
            if (this.countTime < 5) {
                cc.tween(this.time.node)
                    .to(0.25, { scale: 1.5, color: cc.color(255, 0, 0) })
                    .to(0.25, { scale: 1, color: cc.color(255, 255, 255) })
                    .start();
            }
            if (this.countTime <= 0) {
                this.unschedule(this.updateCountDownTime);
                this.begin = false;
                this.over = true;
                this.overStop();
                this.setRank();
                setTimeout(function () {
                    _this.overOpen();
                }, 2000);
            }
        }
    };
    //停止所有动画
    GameManager.prototype.overStop = function () {
        if (this.Player.getComponent("Player").jumpAction)
            this.Player.getComponent("Player").jumpAction.stop();
        var block = this.node.getChildByName("Block").children;
        for (var i = 0; i < block.length; i++) {
            if (block[i]) {
                if (block[i].getComponent("Block").tween)
                    block[i].getComponent("Block").tween.stop();
            }
        }
        var block2 = this.node.getChildByName("CrackBlock").children;
        for (var i = 0; i < block2.length; i++) {
            if (block2[i]) {
                if (block2[i].getComponent("Block").tween)
                    block2[i].getComponent("Block").tween.stop();
            }
        }
    };
    GameManager.prototype.setRank = function () {
        GameData_1.default._instance.GM_INFO.score = this.score;
        GameTool_1.GameTool.setRank();
    };
    GameManager.prototype.overOpen = function () {
        this.Player.active = false;
        this.destroyBlock(false);
        this.destroyBlock(true);
        this.GameOver.active = true;
        this.GameOver.getChildByName("score").getComponent(cc.Label).string = this.score + "";
        this.GameOver.getChildByName("level").getComponent(cc.Label).string =
            GameData_1.default._instance.GM_INFO.levelMax + "";
        // this.GameOver.getChildByName("difficulty").getComponent(cc.Label).string = 
        // GameData._instance.GM_INFO.difficultyMax + "";
        var difficulty = parseInt(this.difficultyArray / this.level * 10 + "");
        // console.log("难度总数",this.difficultyArray,"次数",this.level,"最终",difficulty);
        this.GameOver.getChildByName("difficulty").getComponent(cc.Label).string =
            difficulty / 10 + "";
    };
    GameManager.prototype.backLoad = function () {
        this.destroyBlock(false);
        this.destroyBlock(true);
        this.onDestroy();
        cc.director.loadScene("LoadScene");
    };
    GameManager.prototype.again = function () {
        this.destroyBlock(false);
        this.destroyBlock(true);
        this.onDestroy();
        cc.director.loadScene("GameScene");
    };
    GameManager.prototype.openRank = function () {
        cc.director.loadScene("RankScene");
    };
    //时间格式转换
    GameManager.prototype.getTimeMargin = function (second) {
        var total = 0;
        total = second;
        var hour = 0;
        hour = parseInt((total / 3600) + ""); //计算整数小时数
        var afterHour = total - hour * 60 * 60; //取得算出小时数后剩余的秒数
        var min = parseInt((afterHour / 60) + ""); //计算整数分
        var m = "" + min;
        if (min < 10)
            m = "0" + min;
        var afterMin = total - hour * 60 * 60 - min * 60; //取得算出分后剩余的秒数
        var miao = afterMin + "";
        if (afterMin < 10)
            miao = "0" + afterMin;
        return m + ':' + miao;
    };
    GameManager.prototype.update = function (dt) {
        if (this.cameraMove == true && this.over == false) {
            this.Camera.node.y = this.Player.y - this.countHeight;
            if (this.Camera.node.y <= 0)
                this.Camera.node.y = 0;
            this.topUI.y = this.Camera.node.y + this.drop;
        }
    };
    var GameManager_1;
    __decorate([
        property(cc.Camera)
    ], GameManager.prototype, "Camera", void 0);
    __decorate([
        property(cc.Node)
    ], GameManager.prototype, "topUI", void 0);
    __decorate([
        property(cc.Node)
    ], GameManager.prototype, "Player", void 0);
    __decorate([
        property(cc.Node)
    ], GameManager.prototype, "Ground", void 0);
    __decorate([
        property(cc.Node)
    ], GameManager.prototype, "Xin", void 0);
    __decorate([
        property(cc.Label)
    ], GameManager.prototype, "time", void 0);
    __decorate([
        property(cc.Node)
    ], GameManager.prototype, "GameOver", void 0);
    __decorate([
        property(cc.Node)
    ], GameManager.prototype, "Tip", void 0);
    __decorate([
        property([cc.Prefab])
    ], GameManager.prototype, "blockPrefab", void 0);
    GameManager = GameManager_1 = __decorate([
        ccclass
    ], GameManager);
    return GameManager;
}(cc.Component));
exports.default = GameManager;

cc._RF.pop();