
cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        block_pre: {
            default: null,
            type: cc.Prefab,
        },
        add_num_pre: {
            default: null,
            type: cc.Prefab,
        },
        bomb_pre:{
            default: null,
            type: cc.Prefab,
        },
        bomb_main:{
            default: null,
            type: cc.Node,
        },
        unclick: {
            default: null,
            type: cc.Node,
        },
        add_main: {
            default: null,
            type: cc.Node,
        },
        five: {
            default: null,
            type: cc.Node,
        },
        score: {
            default: null,
            type: cc.Node,
        },
        jinbi_san: {
            default: null,
            type: cc.Node,
        },
        block_san: {
            default: null,
            type: cc.Node,
        },
        this_time_score: {
            default: null,
            type: cc.Node,
        },
        game_over: {
            default: null,
            type: cc.Node,
        },
        result_page: {
            default: null,
            type: cc.Node,
        },
        set_main: {
            default: null,
            type: cc.Node,
        },
        top_score:{
            default: null,
            type: cc.Node,
        },
        bgm: {
            type: cc.AudioSource,
            default: null
        },
        xiaochu_bgm: {
            type: cc.AudioSource,
            default: null
        },
        bgm_control:{
            default: null,
            type: cc.Node,
        },
        beyond_main:{
            default: null,
            type: cc.Node,
        },
        help:{
            default: null,
            type: cc.Node,
        },
        help_mask:{
            default: null,
            type: cc.Node,
        },
        combo:{
            default: null,
            type: cc.Node,
        },
        bonus:{
            default: null,
            type: cc.Node,
        },
        fengxiang_fuhuo:{
            default: null,
            type: cc.Node,
        },
        shipin_fuhuo:{
            default: null,
            type: cc.Node,
        },
        fuhuobi_fuhuo:{
            default: null,
            type: cc.Node,
        },
        cun_dang:{
            default: null,
            type: cc.Node,
        },
        bomb_node:cc.Node,
        double_node:cc.Node,
        wanneng_node:cc.Node,
        first_main:cc.Node,
        combo_texiao:cc.Node,
        chengjiu:cc.Node,
        daoju:cc.Node,
        wanneng_no:cc.Node,
        double_texiao:cc.Node,
        wannng_main:cc.Node,
        daojishi10:cc.Node,
        dander_main:cc.Node,
        baoxiang_main:cc.Node,
        get_daoju:cc.Node,
        //相等的邻居
        neighbor: [],
        neighbor_name: [],
        block_pos_arr: [],
        block_sprite: [],
        saizi_sprite: [],
        Opportunity:5,
        last_timer:null,//最后一次机会的计时器
        voice:false,
        combo_label:1,
        last_touch:0,//上一次点击时间戳
        double:0,
        fuhuobi_sprite:null,
        click:true,
        share_video:null,
        houtai_button_name:null,
        // callback:null,
        //   block_pos:[(-240.00, -240.00),(-120.00, -240.00),(0.00, -240.00),(120.00, -240.00),(240.00, -240.00),(-240.00, -120.00),(-120.00, -120.00),(0.00, -120.00),(120.00, -120.00),(240.00, -120.00),(-240.00, 0.00),(-120.00, 0.00),(0.00, 0.00),(120.00, 0.00),(240.00, 0.00),(-240.00, 120.00),(-120.00, 120.00),(0.00, 120.00),(120.00, 120.00),(240.00, 120.00),(-240.00, 240.00),(-120.00, 240.00),(0.00, 240.00),(120.00, 240.00),(240.00, 240.00)],
        //   block_pos:[{x: 60, y: 60},{x: 180, y: 60},{x: 300, y: 60},{x: 420, y: 60},{x: 540, y: 60},{x: 60, y: 180},{x: 180, y: 180},{x: 300, y: 180},{x: 420, y: 180},{x: 540, y: 180},{x: 60, y: 300},{x: 180, y: 300},{x: 300, y: 300},{x: 420, y: 300},{x: 540, y: 300},{x: 60, y: 420},{x: 180, y: 420},{x: 300, y: 420},{x: 420, y: 420},{x: 540, y: 420},{x: 60, y: 540},{x: 180, y: 540},{x: 300, y: 540},{x: 420, y: 540},{x: 540, y: 540}],
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        var self = this;
        if(game_msg.voice == true){
            this.bgm.play();
            this.bgm_control.children[0].active = true;
        }else{
            this.bgm_control.children[0].active = false;
        }
        // this._tex = new cc.Texture2D();
        // window.sharedCanvas.width = 750;
        // window.sharedCanvas.height = 1334;
        // if (window.sharedCanvas) {
        //     window.sharedCanvas.width = cc.game.canvas.width * 2;
        //     window.sharedCanvas.height = cc.game.canvas.height * 2;
        // }
        
        // self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = 1;
        // console.log(sdk.userid,">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
        self.fuhuobi_sprite = self.fuhuobi_fuhuo.getComponent(cc.Sprite).spriteFrame;
        self.fuhuobi_fuhuo.getComponent(cc.Button).interactable = false;
        // console.log("interactable",self.fengxiang_fuhuo.getComponent(cc.Button).interactable);
        cc.loader.loadRes("images/fuhuobifuhuo_huise",cc.SpriteFrame,function (err, spriteFrame) {
            if (err) {
                cc.error(err.message || err);
                return;
            }
            self.fuhuobi_fuhuo.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        });

        // self.daoju_houtai_msg();
        
        // if(cc.sys.localStorage.getItem("node_msg_arr")){
        //     self.score.getComponent(cc.Label).string = cc.sys.localStorage.getItem("score") || 0;

        //     self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = (self.score.getComponent(cc.Label).string/400000).toFixed(2);
        // }

        // if(game_msg.node_msg_arr.length>1){
        //     self.score.getComponent(cc.Label).string = game_msg.score;
        //     // self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = (game_msg.score/400000).toFixed(2);
        //     self.chenghao_fn(game_msg.score);
        // }


        this.beyond_main.active = false;
        this.scheduleOnce(function(){
            if (cc.sys.platform === cc.sys.WECHAT_GAME) {
                // console.log(self.score.getComponent(cc.Label).string);
                self.onRankReq(3,self.score.getComponent(cc.Label).string);
                this.subContextView = this.beyond_main.getComponent(cc.WXSubContextView);
                this.subContextView.enabled = false;
                self.scheduleOnce(function(){self.subContextView.update();},0.5);
            }
            self.beyond_main.active = true;
        },2);
        
        
        

//         subContextView.enabled = false;
        
        cc.game.on(cc.game.EVENT_HIDE, function(){
            // console.log("wwwwwwwwwwwww");
            if(self.unclick.active == false){
                self.storage_fn();
            }
            
            cc.director.pause();
            // console.log("pause.....");
        },this);
        cc.game.on(cc.game.EVENT_SHOW, function(){
            cc.director.resume();
            // console.log("resume.....");
        },this);
    },

    daoju_houtai_msg:function(){
        var self = this;
        // var fuhuobi_sprite = self.fuhuobi_fuhuo.getComponent(cc.Sprite).spriteFrame;
        self.bomb_node.getChildByName("many").active = false;
        self.bomb_node.getChildByName("jia").active = true;
        self.double_node.getChildByName("many").active = false;
        self.double_node.getChildByName("jia").active = true;
        self.double_node.getChildByName("many").active = false;
        self.wanneng_node.getChildByName("jia").active = true;
        // sdk.Post(sdk.ip2+"/Reward/all",{"uid":sdk.userid,"token":cc.HQ.PlayerMgr.info.token},function(data){
        //     console.log(data.d,"?????????????????");
        //     for(let i = 0;i<data.d.length;i++){
        //         if(data.d[i].type == 1){
        //             // console.log(data.d[i].num,self.bomb_node.getChildByName("many").getComponent(cc.Label).string);
        //             if(data.d[i].num>0){
        //                 self.bomb_node.getChildByName("many").getComponent(cc.Label).string = "x"+data.d[i].num;
        //                 self.bomb_node.getChildByName("many").active = true;
        //                 self.bomb_node.getChildByName("jia").active = false;
        //             }
                    
        //         }
        //         if(data.d[i].type == 2){
        //             if(data.d[i].num>0){
        //                 self.double_node.getChildByName("many").getComponent(cc.Label).string = "x"+data.d[i].num;
        //                 self.double_node.getChildByName("many").active = true;
        //                 self.double_node.getChildByName("jia").active = false;
        //             }
                    
        //         }
        //         if(data.d[i].type == 4){
        //             if(data.d[i].num>0){
        //                 self.wanneng_node.getChildByName("many").getComponent(cc.Label).string = "x"+data.d[i].num;
        //                 self.double_node.getChildByName("many").active = true;
        //                 self.wanneng_node.getChildByName("jia").active = false;
        //             }
                    
        //         }
        //         if(data.d[i].type == 3){
        //             if(data.d[i].num>0){
        //                 self.fuhuobi_fuhuo.getComponent(cc.Button).interactable = true;
        //                 self.fuhuobi_fuhuo.getComponent(cc.Sprite).spriteFrame = self.fuhuobi_sprite;
        //             }
        //             // self.fuhuobi_fuhuo.getChildByName("many").getComponent(cc.Label).string = "x"+data.d[i].num;
        //         }
        //     }
        // })
    },
    

    start () {
        // console.log(this.jinbi_san.getComponent(sp.Skeleton));
        var self = this;
        var block_pos = [{x: 60, y: 60},{x: 180, y: 60},{x: 300, y: 60},{x: 420, y: 60},{x: 540, y: 60},{x: 60, y: 180},{x: 180, y: 180},{x: 300, y: 180},{x: 420, y: 180},{x: 540, y: 180},{x: 60, y: 300},{x: 180, y: 300},{x: 300, y: 300},{x: 420, y: 300},{x: 540, y: 300},{x: 60, y: 420},{x: 180, y: 420},{x: 300, y: 420},{x: 420, y: 420},{x: 540, y: 420},{x: 60, y: 540},{x: 180, y: 540},{x: 300, y: 540},{x: 420, y: 540},{x: 540, y: 540}];
        this.block_pos_arr = block_pos;
        // var block_matrix = [11,12,13,14,15,21,22,23,24,25,31,32,33,34,35,41,42,43,44,45,51,52,53,54,55];

        cc.loader.loadRes("images/saizi_huise",cc.SpriteFrame,function (err, spriteFrame) {
            if (err) {
                cc.error(err.message || err);
                return;
            }
            self.saizi_sprite.push(spriteFrame);
            self.saizi_sprite.push(self.five.children[0].getComponent(cc.Sprite).spriteFrame);
        });

        // 连消的分数
        for(let i = 0; i < 25; i++){
            var node = cc.instantiate(self.add_num_pre);
            node.parent = self.add_main;
            self.add_main.children[i].setPosition(cc.v2(block_pos[i]));

            var node2 = cc.instantiate(self.bomb_pre);
            node2.parent = self.bomb_main;
            self.bomb_main.children[i].setPosition(cc.v2(block_pos[i]));
        }

        // if(cc.sys.localStorage.getItem("bomb")){self.bomb_node.destroy()};
        // if(cc.sys.localStorage.getItem("double")){self.double_node.destroy()};
        // if(cc.sys.localStorage.getItem("wanneng")){self.wanneng_node.destroy()};

        if(game_msg.houtai_kaiguan == true){
            self.bomb_node.active = true;
            self.double_node.active = true;
            self.wanneng_node.active = true;
            self.daoju_many();
        }

        for(let j = 1; j <= 21;j++){ //加载所有数字图片
            cc.loader.loadRes("images/"+j,cc.SpriteFrame,function (err, spriteFrame) {
                if (err) {
                    cc.error(err.message || err);
                    return;
                }
                // console.log(self.block_sprite);
                self.block_sprite.push(spriteFrame);
                if(self.block_sprite.length == 21){
                    self.block_sprite = self.selectionSort(self.block_sprite);
                    // console.log(self.block_sprite);
                    for(let i = 0;i<25;i++){
                        self.createEnemy(self.node,i); //放入父元素
                    }
                    self.check(false);
                    var isplay = cc.sys.localStorage.getItem("isplay");
                    if(isplay != "1"){
                        self.check(true);
                    }
                    cc.sys.localStorage.setItem("isplay","1"); //设置loaclStorage
                    // console.log(cc.sys.localStorage.getItem("isplay"));
                    // var node_msg_name = cc.sys.localStorage.getItem("node_msg_name").split(",");
                    // var node_msg_num = cc.sys.localStorage.getItem("node_msg_num").split(",");
                    
                    // if(cc.sys.localStorage.getItem("node_msg_arr")){
                    
                }
            });
            
        }

        this.enemyPool = new cc.NodePool();
        
        for (let i = 0; i < 25; ++i) {
            let enemy = cc.instantiate(this.block_pre); // 创建节点
            this.enemyPool.put(enemy); // 通过 putInPool 接口放入对象池
        }
        self.on_event();
    },
    on_event:function(){
        var self = this;
        this.node.on('add_num', function (event) { //监听石块的发射事件
            var new_touch = Date.now();
            if(new_touch - self.last_touch < 100){return false;}
            self.last_touch = new_touch;
            event.stopPropagation();
            // console.log(event.target);
            // console.log(self.node.getChildByName("block_0").getComponent("block").matrix);
            self.combo_label = 1;
            if(self.help.active == true){self.help.active = false; self.help_mask.active = false;self.first_main.active = false;}
            self.Opportunity --;
            if(self.Opportunity<0){self.Opportunity = 0};
            
            self.five.children[self.Opportunity].runAction(cc.sequence(cc.spawn(cc.scaleTo(0.2, 1.4),cc.fadeOut(0.2, 0)),cc.delayTime(0.1),cc.callFunc(function(target) {
                // console.log(target);
                target.getComponent(cc.Sprite).spriteFrame = self.saizi_sprite[0];
                target.runAction(cc.fadeIn(0.1));
                target.scale = 0.9;
            },self.five.children[self.Opportunity])));

            // event.target.getComponent("block").num +=1;
            event.target.num +=1;
            // console.log(event.target.getChildByName("text").getComponent(cc.Label).string);
            if(event.target.num<20){
                event.target.getComponent(cc.Sprite).spriteFrame = self.block_sprite[event.target.num];
            }else{
                event.target.getComponent(cc.Sprite).spriteFrame = self.block_sprite[20];
                event.target.getChildByName("text").getComponent(cc.Label).string = Number(event.target.num)+1;
                event.target.getChildByName("text").active = true;
            }
            // event.target.getComponent(cc.Sprite).spriteFrame = self.block_sprite[event.target.getComponent("block").num];
            
            self.clear(event.target,true,true,true,true,false); //查找相邻 
            var len = self.neighbor.length;
            if(len>=2){
                self.result_fn(self.neighbor,event.target); //合并效果 下坠 添加新节点
                self.neighbor = [];
            }else{
                if(self.Opportunity == 1){
                    self.last_san();
                    if(game_msg.danger_tip == true && game_msg.houtai_kaiguan == true){
                        game_msg.danger_tip = false;
                        self.dander_main_show();
                    }
                }
                if(self.Opportunity == 0){
                    if(game_msg.daojishi == true && game_msg.houtai_kaiguan == true){
                        game_msg.daojishi = false;
                        self.daojishi10_fn();
                    }else{
                        self.game_over_fn();
                    }
                }
            }
        });
    },
    daoju_many(){
        if(game_msg.hammer_time>0){
            this.bomb_node.getChildByName("jia").active = false;
            this.bomb_node.getChildByName("many").active = true;
            this.bomb_node.getChildByName("many").getComponent(cc.Label).string = game_msg.hammer_time;
        }
        if(game_msg.Opportunity_add_time>0){
            this.double_node.getChildByName("jia").active = false;
            this.double_node.getChildByName("many").active = true;
            this.double_node.getChildByName("many").getComponent(cc.Label).string = game_msg.Opportunity_add_time;
        }
        if(game_msg.refresh_time>0){
            this.wanneng_node.getChildByName("jia").active = false;
            this.wanneng_node.getChildByName("many").active = true;
            this.wanneng_node.getChildByName("many").getComponent(cc.Label).string = game_msg.refresh_time;
        }
    },
    daojishi10_fn(){
        this.share_video = sdk.getButtonConfig("fuhuo_daojishi"); 
        this.houtai_button_name = "fuhuo_daojishi";

        this.daojishi10.getChildByName("video").active = false;
        this.daojishi10.getChildByName("share").active = false;

        if(this.share_video.type == "video"){
            this.daojishi10.getChildByName("video").active = true;
        }else{
            this.daojishi10.getChildByName("share").active = true;
        }

        this.daojishi10.active = true;
        var time = 10;
        this.daojishi10.getChildByName("time").getComponent(cc.Label).string = time;

        this.callback = function () {
            time --;
            this.daojishi10.getChildByName("time").getComponent(cc.Label).string = time;
            if (time == 0) {
                // 在第六次执行回调时取消这个计时器
                this.unschedule(this.callback);
                this.daojishi10.active = false;
                this.game_over_fn();
            } 
        }
        this.schedule(this.callback, 1);
    },
    fuhuo_five(){
        this.unschedule(this.callback);
        this.lingqu();
    },
    daojishi10_close(){
        this.daojishi10.active = false;
        this.unschedule(this.callback);
        this.game_over_fn();
    },
    
    game_over_fn(){
        var self = this;
        self.unclick.active = true;
        self.five.children[0].getComponent(cc.Sprite).spriteFrame = self.saizi_sprite[0];
        clearInterval(self.last_timer);
        self.last_timer = null;
        
        // Net.httpRequest()
        // Net.packAjaxSend("http://172.16.175.89:8200/api/top_record.api.php",data,'GET');
        for(let i = 0; i < 25; ++i){ //结束再加一次所有节点分数
            self.add_score_fn(self.node.getChildByName("b"+i));
        }

        // if(cc.sys.localStorage.getItem("node_msg_arr")){cc.sys.localStorage.removeItem("node_msg_arr");}
        // if(cc.sys.localStorage.getItem("fenxiang")){cc.sys.localStorage.removeItem("fenxiang");}
        // if(cc.sys.localStorage.getItem("shipin")){cc.sys.localStorage.removeItem("shipin");}
        // if(cc.sys.localStorage.getItem("fuhuobi")){cc.sys.localStorage.removeItem("fuhuobi");}
        // if(cc.sys.localStorage.getItem("bomb")){cc.sys.localStorage.removeItem("bomb");}
        // if(cc.sys.localStorage.getItem("double")){cc.sys.localStorage.removeItem("double");}
        // if(cc.sys.localStorage.getItem("wanneng")){cc.sys.localStorage.removeItem("wanneng");}
        game_msg.node_msg_arr = [];
        game_msg.score = 0,
        game_msg.last_score = 0,
        game_msg.fengxiang_fuhuo = true;
        game_msg.shipin_fuhuo = true;
        game_msg.danger_tip = true;
        game_msg.daojishi = true;

        // game_msg.fuhuobi = 0;
        // game_msg.hammer_time0,
        // game_msg.refresh_time:0,
        // game_msg.Opportunity_add_time:0,

        var score = Number(self.score.getComponent(cc.Label).string);
        
        // if(cc.sys.localStorage.getItem("top_score")){
        //     if(cc.sys.localStorage.getItem("top_score")<score){
        //         cc.sys.localStorage.setItem("top_score",score);
        //     }
        // }else{
        //     cc.sys.localStorage.setItem("top_score",score);
        // }

        if(game_msg.highest_score<score){
            game_msg.highest_score = score;
            self.setUserCloudStorage(score);
        }

        sdk.setToServer("GameMsg","Json",game_msg,-1); // 结束保存一次
        
        self.this_time_score.getComponent(cc.Label).string = score;
        self.top_score.getComponent(cc.Label).string = game_msg.highest_score;

        

        self.scheduleOnce(function() {
            self.game_over.active = true;
        }, 1);
        self.scheduleOnce(function(){
            self.node.parent.parent.active = false;
            self.game_over.active = false;
            self.result_page.active = true;
        },2);
    },
    dander_main_close(){
        this.dander_main.active = false;
    },
    dander_main_show(){
        var rand_num = this.rand(1,3);
        this.dander_main.getChildByName("Opportunity_add").active = false;
        this.dander_main.getChildByName("refresh").active = false;
        this.dander_main.getChildByName("hammer").active = false;
        if(rand_num ==1){
            this.dander_main.getChildByName("Opportunity_add").active = true;
            this.share_video = sdk.getButtonConfig("button_opportunity_add"); 
            this.houtai_button_name = "button_opportunity_add";
        }
        if(rand_num ==2){
            this.dander_main.getChildByName("hammer").active = true;
            this.share_video = sdk.getButtonConfig("button_hammer");
            this.houtai_button_name = "button_hammer";
        }
        if(rand_num ==3){
            this.dander_main.getChildByName("refresh").active = true;
            this.share_video = sdk.getButtonConfig("button_refresh");
            this.houtai_button_name = "button_refresh";
        }
        this.dander_main.getChildByName("video").active = false;
        this.dander_main.getChildByName("share").active = false;
        if(this.share_video.type == "video"){
            this.dander_main.getChildByName("video").active = true;
        }else{
            this.dander_main.getChildByName("share").active = true;
        }
        this.dander_main.active = true;
    },
    // dander_main_share(){

    // },
    // dander_main_video(){
    //     if(this.dander_main.getChildByName("Opportunity_add").active == true){
    //         this.lingqu("button_refresh");
    //     }
    // },

    baoxiang_main_close(){
        this.baoxiang_main.active = false;
    },
    baoxiang_main_show(){
        if(game_msg.houtai_kaiguan == true){
            var rand_num = this.rand(1,3);
            // this.dander_main.getChildByName("Opportunity_add").active = false;
            // this.dander_main.getChildByName("refresh").active = false;
            // this.dander_main.getChildByName("hammer").active = false;
            if(rand_num ==1){
                // this.dander_main.getChildByName("Opportunity_add").active = true;
                this.share_video = sdk.getButtonConfig("button_opportunity_add"); 
                this.houtai_button_name = "button_opportunity_add";
            }
            if(rand_num ==2){
                // this.dander_main.getChildByName("hammer").active = true;
                this.share_video = sdk.getButtonConfig("button_hammer");
                this.houtai_button_name = "button_hammer";
            }
            if(rand_num ==3){
                // this.dander_main.getChildByName("refresh").active = true;
                this.share_video = sdk.getButtonConfig("button_refresh");
                this.houtai_button_name = "button_refresh";
            }
            this.baoxiang_main.getChildByName("video").active = false;
            this.baoxiang_main.getChildByName("share").active = false;
            if(this.share_video.type == "video"){
                this.baoxiang_main.getChildByName("video").active = true;
            }else{
                this.baoxiang_main.getChildByName("share").active = true;
            }
            this.baoxiang_main.active = true;
        }  
    },
    baoxiang_main_get(){
        if(this.share_video.type == "video"){
            sdk.setSceneEvent("获得宝箱","点击","获得宝箱视频",{},null);
        }else{
            sdk.setSceneEvent("获得宝箱","点击","获得宝箱分享",{},null);
        }
        this.lingqu();
    },

    get_daoju_close(){
        this.get_daoju.getChildByName("Opportunity_add").runAction(cc.moveBy(0.3,-123,300));
        this.get_daoju.getChildByName("hammer").runAction(cc.moveBy(0.3,0,300));
        this.get_daoju.getChildByName("refresh").runAction(cc.moveBy(0.3,123,300));
        this.scheduleOnce(function(){
            this.get_daoju.active = false;
        },0.3);
    },
    get_daoju_open(button_name){
        this.get_daoju.getChildByName("Opportunity_add").active = false;
        this.get_daoju.getChildByName("refresh").active = false;
        this.get_daoju.getChildByName("hammer").active = false;
        this.get_daoju.getChildByName("Opportunity_add").setPosition(cc.v2(0,-43));
        this.get_daoju.getChildByName("refresh").setPosition(cc.v2(0,-46));
        this.get_daoju.getChildByName("hammer").setPosition(cc.v2(0,-39));
        if(button_name == "button_opportunity_add"){
            this.get_daoju.getChildByName("Opportunity_add").active = true;
        }
        if(button_name == "button_hammer"){
            this.get_daoju.getChildByName("hammer").active = true;
        }
        if(button_name == "button_refresh"){
            this.get_daoju.getChildByName("refresh").active = true;
        }
        // this.get_daoju.setPosition(cc.v2(0,0));
        this.get_daoju.active = true;
    },
     //上传要保存的数据
     setUserCloudStorage:function (score) {
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            var KVDataList = [{ key: "score", value: "" + score }];
            wx.setUserCloudStorage({
                KVDataList: KVDataList,
                success(res) {
                    console.log("保存数据成功");
                },
                fail(res) {

                }
            });
        }
    },

    createEnemy: function (parentNode,i) {
        var self = this;
        let enemy = null;
        if (this.enemyPool.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
            // console.log(this.enemyPool.size());
            enemy = this.enemyPool.get();
        } else { // 如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
            enemy = cc.instantiate(this.enemyPrefab);
        }
        enemy.parent = parentNode; // 将生成的敌人加入节点树
        // enemy.getComponent('Enemy').init(); //接下来就可以调用 enemy 身上的脚本进行初始化
        enemy.name = 'b'+i;
        enemy.setPosition(cc.v2(this.block_pos_arr[i]));
        // self.node.children[i].getComponent("block").matrix = block_matrix[i];
        // console.log(self.node.children[i].getPosition(),self.node.children[i].getComponent("block").matrix,self.node.children[i].name);
        var chance = self.rand(1,100);
        if(chance <= 30){var rand_num = 0;}
        if(chance > 30 && chance <= 60){var rand_num = 1;}
        if(chance > 60 && chance <= 90){var rand_num = 2;}
        if(chance > 90 && chance <= 95){var rand_num = 3;}
        if(chance > 95 && chance <= 100){var rand_num = 4;}
        // var rand_num = self.rand(0,3);
        // self.node.children[i].children[0].getComponent(cc.Label).string = rand_num + self.node.children[i].name;
        // enemy.getComponent("block").num = rand_num;
        enemy.num = rand_num;
        enemy.getComponent(cc.Sprite).spriteFrame = self.block_sprite[rand_num];

        if(i == 24){
            if(game_msg.node_msg_arr.length>1){
                // var node_msg_arr = JSON.parse(cc.sys.localStorage.getItem("node_msg_arr"));
                var node_msg_arr = game_msg.node_msg_arr;
                var node_msg_len = node_msg_arr.length;
                // self.score.getComponent(cc.Label).string = cc.sys.localStorage.getItem("score");
                // var Opportunity_save = Number(cc.sys.localStorage.getItem("Opportunity"));
                // console.log("fffff",game_msg.score);
                self.score.getComponent(cc.Label).string = game_msg.score;
                self.chenghao_fn(game_msg.score);
                var Opportunity_save = Number(game_msg.Opportunity);
                self.Opportunity = Opportunity_save;
                if(Opportunity_save == 1){self.last_san();}
                for(let i=Opportunity_save; i<5;i++){
                    self.five.children[i].getComponent(cc.Sprite).spriteFrame = self.saizi_sprite[0];
                 }
                for(let i = 0;i<node_msg_len;i++){
                    var save_num = Number(node_msg_arr[i]);
                    // self.node.getChildByName(node_msg_arr[i].name).getComponent("block").num = save_num;
                    // self.node.getChildByName("b"+i).num = save_num;
                    // self.node.getChildByName("b"+i).getComponent(cc.Sprite).spriteFrame = self.block_sprite[save_num];
                    self.node.children[i].num = save_num;
                    self.node.children[i].getComponent(cc.Sprite).spriteFrame = self.block_sprite[save_num];
                }
                // if(cc.sys.localStorage.getItem("fenxiang")){
                if(game_msg.fenxiang_fuhuo == false){
                    self.fengxiang_fuhuo.getComponent(cc.Button).interactable = false;
                    // console.log("interactable",self.fengxiang_fuhuo.getComponent(cc.Button).interactable);
                    cc.loader.loadRes("images/fenxiangfuhuo_huise",cc.SpriteFrame,function (err, spriteFrame) {
                        if (err) {
                            cc.error(err.message || err);
                            return;
                        }
                        self.fengxiang_fuhuo.getComponent(cc.Sprite).spriteFrame = spriteFrame;
                    });
                }
                // if(cc.sys.localStorage.getItem("shipin")){
                if(game_msg.shipin_fuhuo == false){
                    self.shipin_fuhuo.getComponent(cc.Button).interactable = false;
                    // console.log("interactable",self.fengxiang_fuhuo.getComponent(cc.Button).interactable);
                    cc.loader.loadRes("images/kanshipinfuhuo_huise",cc.SpriteFrame,function (err, spriteFrame) {
                        if (err) {
                            cc.error(err.message || err);
                            return;
                        }
                        self.shipin_fuhuo.getComponent(cc.Sprite).spriteFrame = spriteFrame;
                    });
                }

                // if(cc.sys.localStorage.getItem("fuhuobi")){
                if(game_msg.fuhuobi <= 0){
                    self.fuhuobi_fuhuo.getComponent(cc.Button).interactable = false;
                    // console.log("interactable",self.fengxiang_fuhuo.getComponent(cc.Button).interactable);
                    cc.loader.loadRes("images/fuhuobifuhuo_huise",cc.SpriteFrame,function (err, spriteFrame) {
                        if (err) {
                            cc.error(err.message || err);
                            return;
                        }
                        self.fuhuobi_fuhuo.getComponent(cc.Sprite).spriteFrame = spriteFrame;
                    });
                }  
            }
        }
    },
    createEnemy_later: function (parentNode,i) {
        var self = this;
        let enemy = null;
        if (this.enemyPool.size() > 0) { // 通过 size 接口判断对象池中是否有空闲的对象
            // console.log(this.enemyPool.size());
            enemy = this.enemyPool.get();
        } else { // 如果没有空闲对象，也就是对象池中备用对象不够时，我们就用 cc.instantiate 重新创建
            enemy = cc.instantiate(this.enemyPrefab);
        }
        enemy.parent = parentNode; // 将生成的敌人加入节点树
        // enemy.getComponent('Enemy').init(); //接下来就可以调用 enemy 身上的脚本进行初始化
        enemy.name = 'b'+i;
        enemy.setPosition(cc.v2(this.block_pos_arr[i]));
        // self.node.children[i].getComponent("block").matrix = block_matrix[i];
        // console.log(self.node.children[i].getPosition(),self.node.children[i].getComponent("block").matrix,self.node.children[i].name);
        var score_now = self.score.getComponent(cc.Label).string;
        if(score_now < 10000){
            var chance = self.rand(1,100);
            if(chance <= 30){var rand_num = 0;}
            if(chance > 30 && chance <= 60){var rand_num = 1;}
            if(chance > 60 && chance <= 90){var rand_num = 2;}
            if(chance > 90 && chance <= 95){var rand_num = 3;}
            if(chance > 95 && chance <= 100){var rand_num = 4;}
        }
        if(score_now >= 10000 && score_now <= 50000){
            var chance = self.rand(1,100);
            if(chance <= 20){var rand_num = 0;}
            if(chance > 20 && chance <= 50){var rand_num = 1;}
            if(chance > 50 && chance <= 80){var rand_num = 2;}
            if(chance > 80 && chance <= 90){var rand_num = 3;}
            if(chance > 90 && chance <= 100){var rand_num = 4;}
        }
        if(score_now > 50000 && score_now <= 80000){
            var chance = self.rand(1,100);
            if(chance <= 15){var rand_num = 0;}
            if(chance > 15 && chance <= 40){var rand_num = 1;}
            if(chance > 40 && chance <= 70){var rand_num = 2;}
            if(chance > 70 && chance <= 85){var rand_num = 3;}
            if(chance > 85 && chance <= 100){var rand_num = 4;}
        }
        if(score_now > 80000 && score_now <= 120000){
            var chance = self.rand(1,100);
            if(chance <= 25){var rand_num = 0;}
            if(chance > 25 && chance <= 35){var rand_num = 1;}
            if(chance > 35 && chance <= 45){var rand_num = 2;}
            if(chance > 45 && chance <= 70){var rand_num = 3;}
            if(chance > 70 && chance <= 100){var rand_num = 4;}
            // var rand_num = self.rand(0,4);
        }
        if(score_now > 120000){
            var chance = self.rand(1,100);
            if(chance <= 30){var rand_num = 0;}
            if(chance > 30 && chance <= 35){var rand_num = 1;}
            if(chance > 35 && chance <= 40){var rand_num = 2;}
            if(chance > 40 && chance <= 70){var rand_num = 3;}
            if(chance > 70 && chance <= 100){var rand_num = 4;}
            // var rand_num = self.rand(0,4);
        }
        // self.node.children[i].children[0].getComponent(cc.Label).string = rand_num + self.node.children[i].name;
        // enemy.getComponent("block").num = rand_num;
        enemy.num = rand_num;
        enemy.getChildByName("text").active = false;
        enemy.getComponent(cc.Sprite).spriteFrame = self.block_sprite[rand_num];

        // enemy.stopAllActions();
        // enemy.runAction(cc.hide());
        // enemy.scale = 0.8;
        // enemy.runAction(cc.sequence(cc.delayTime(0.3),cc.spawn(cc.show(),cc.scaleTo(0.05, 1))));
        // enemy.active = false;
        enemy.scale = 0.8;
        // self.scheduleOnce(function(){
            // enemy.active = true;
            enemy.runAction(cc.scaleTo(0.05, 1));
        // },0.3)
        // console.log(self.node.childrenCount);
        if(self.node.childrenCount == 25){
            self.scheduleOnce(function(){
                // console.log("len",self.node.childrenCount);
                // if(self.node.childrenCount == 25){
                    self.fall_check_fn(); //下落之后 检查可不可以继续相消
                // }
            },0.1)
        }
        
    },

    onEnemyKilled: function (enemy) {
        // enemy 应该是一个 cc.Node
        this.enemyPool.put(enemy); // 和初始化时的方法一样，将节点放进对象池，这个方法会同时调用节点的 removeFromParent
    },
    last_san(){
        var self =this;
        var change = true;
        self.last_timer = setInterval(change_sprite,800);
        function change_sprite(){
            if(change == true){
                self.five.children[0].getComponent(cc.Sprite).spriteFrame = self.saizi_sprite[0];
            }else{
                self.five.children[0].getComponent(cc.Sprite).spriteFrame = self.saizi_sprite[1];
            }
            change = !change;
        }
    },
    storage_fn(){
        var self = this;
        
        var node_save_arr = [];
        // var node_save_name = [];
        // var node_save_num = [];
        for(let i = 0;i<self.node.childrenCount;i++){
            var name = self.node.children[i].name;
            // var num = self.node.children[i].getComponent("block").num;
            var num = self.node.children[i].num;
            // var node_msg = {"name":name,"num":num};
            node_save_arr.push(num);
            // node_save_name.push(name);
            // node_save_num.push(num);
        }
        // // console.log(node_save_arr);
        // // console.log(node_save_arr.length);
        // node_save_arr = JSON.stringify(node_save_arr);
        // cc.sys.localStorage.setItem("node_msg_arr",node_save_arr);
        // cc.sys.localStorage.setItem("Opportunity",self.Opportunity);
        // cc.sys.localStorage.setItem("score",self.score.getComponent(cc.Label).string);
        // // console.log("json",JSON.parse(cc.sys.localStorage.getItem("node_msg_arr")));
        // // cc.sys.localStorage.setItem("node_msg_name",node_save_name);
        // // console.log(cc.sys.localStorage.getItem("node_msg_name").split(","));
        // // cc.sys.localStorage.setItem("node_msg_num",node_save_num);
        // // console.log(cc.sys.localStorage.getItem("node_msg_num").split(","));
        // // console.log(self.fengxiang_fuhuo.getComponent(cc.Sprite).spriteFrame.name);

        // if(self.fengxiang_fuhuo.getComponent(cc.Sprite).spriteFrame.name == "fenxiangfuhuo_huise"){
        //     cc.sys.localStorage.setItem("fenxiang","0");
        // }
        // if(self.shipin_fuhuo.getComponent(cc.Sprite).spriteFrame.name == "kanshipinfuhuo_huise"){
        //     cc.sys.localStorage.setItem("shipin","0");
        // }
        // if(self.fuhuobi_fuhuo.getComponent(cc.Sprite).spriteFrame.name == "fuhuobifuhuo_huise"){
        //     cc.sys.localStorage.setItem("fuhuobi","0");
        // }

        // // console.log(self.bomb_node.isValid,"whhwhwhwhwhwhhh>>>>>>>>>>>");

        // if(self.bomb_node.isValid == false){cc.sys.localStorage.setItem("bomb","0");}
        // if(self.double_node.isValid == false){cc.sys.localStorage.setItem("double","0");}
        // if(self.wanneng_node.isValid == false){cc.sys.localStorage.setItem("wanneng","0");}

        game_msg.node_msg_arr = node_save_arr;
        game_msg.Opportunity = self.Opportunity;
        game_msg.score = self.score.getComponent(cc.Label).string;
        // console.log("fenshu",self.score.getComponent(cc.Label).string);
        sdk.setToServer("GameMsg","Json",game_msg,-1); // 存档
        self.set_main.getChildByName("save").runAction(cc.fadeIn(0.1));
        self.scheduleOnce(function(){
            self.set_main.getChildByName("save").runAction(cc.fadeOut(0.5));
        },0.7);
        
    },
    // 最高分数
    top_score_fn: function (data){
        this.top_score.getComponent(cc.Label).string = data.d.top_score;
    },
    check: function(find){ //检查第一次摆放有没有重复  检测哪个点加1可以消
        var repeat = false;
        for(let i = 0;i<25;i++){
            // var matrix_1 = parseInt(this.node.children[i].getComponent("block").matrix/10);
            // var matrix_2 = this.node.children[i].getComponent("block").matrix%10;
            // var matrix_index = this.node.children[i].getComponent("block").matrix;
            // console.log(matrix_1,matrix_2);
            // if(find == false){var index_num = this.node.getChildByName("b"+i).getComponent("block").num;}
            if(find == false){var index_num = this.node.getChildByName("b"+i).num;}
            // if(find == true){var index_num = Number(this.node.getChildByName("b"+i).getComponent("block").num)+1;}
            if(find == true){var index_num = Number(this.node.getChildByName("b"+i).num)+1;}
            var same = 0;
            var around = [];
            var same_arr = [];
            if(i<20){ //上
                // var up = this.node.getChildByName("b"+ (i+5)).getComponent("block").num;
                var up = this.node.getChildByName("b"+ (i+5)).num;
                around.push(up);
                if(index_num == up){
                    // console.log(i,this.node.children[i].getComponent("block").num);
                    same++;
                    same_arr.push(i+5);
                }
            }
            if(i>4){ //下
                // var down = this.node.getChildByName("b"+ (i-5)).getComponent("block").num;
                var down = this.node.getChildByName("b"+ (i-5)).num;
                around.push(down);
                if(index_num == down){
                    same++;
                    same_arr.push(i-5);
                }
            }
            if(i>0 && i%5 != 0){ //判断左边有没有
                // var left = this.node.getChildByName("b"+ (i-1)).getComponent("block").num;
                var left = this.node.getChildByName("b"+ (i-1)).num;
                around.push(left);
                if(index_num == left){
                    // console.log(i,this.node.children[i].getComponent("block").num);
                    same++;
                    same_arr.push(i-1);
                }
            }
            if((i+1)%5 != 0){ //右
                // var right = this.node.getChildByName("b"+ (i+1)).getComponent("block").num;
                var right = this.node.getChildByName("b"+ (i+1)).num;
                around.push(right);
                if(index_num == right){
                    same++;
                    same_arr.push(i+1);
                }
            }
        //    console.log(same); 
           if(same>=2){ //如果有重复 取一个和周围不一样的数
               repeat = true;
               if(find == false){
                around = this.arr_distinct(around);
                var new_num =  this.not_repeat_fn(around);
                // this.node.getChildByName("b"+i).getComponent("block").num = new_num;
                this.node.getChildByName("b"+i).num = new_num;
             //    this.node.children[i].children[0].getComponent(cc.Label).string = new_num + this.node.children[i].name;
                this.node.getChildByName("b"+i).getComponent(cc.Sprite).spriteFrame = this.block_sprite[new_num];
               }

               if(find == true){
                //    console.log(i);
                //    console.log(this.node.getChildByName("b"+i).getPosition());
                    // around.push(i);
                    // console.log(around);
                    same_arr.push(i);
                    // console.log(same_arr);
                    for(let i = 0;i<same_arr.length;i++){
                        // this.node.getChildByName("b"+around[i]).zIndex = 999;
                        var node = cc.instantiate(this.node.getChildByName("b"+same_arr[i]));
                        node.parent = this.first_main;
                        // console.log("first",this.first_main.childrenCount);
                        node.setPosition(this.node.getChildByName("b"+same_arr[i]).getPosition());
                        node.getComponent("block").destroy();
                    }
                    
                   this.help.active = true;
                   this.help_mask.active = true;
                   this.help.setPosition(this.node.getChildByName("b"+i).getPosition());
                   this.help.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(1,1.2),cc.scaleTo(1, 1))));
                   break;
               }
            //    console.log(this.node.children[i].getComponent("block").num);
            // console.log(rand_num+"ooo");
            // this.check();
           }
        }
        // console.log(repeat);
        if(repeat == true){
            if(find == false){this.check(false);}
        }
    },
    clear: function(node,u,d,l,r,repeat){ //查可不可以相消 执行动画
        if(node == undefined || node == null){return false};
        var self = this;
        this.unclick.active = true;
        // var by_up = false,by_down = false,by_left = false,by_right = false;
        if(repeat == false){
            this.neighbor = [];
        }
        var index = node.name.substring(1);
        // this.neighbor.push(node);
        // console.log(Number(index)+1);
        if(index<20 && u == true){ //上
            var up_num = Number(index)+Number(5);
            // var up = this.node.getChildByName("b"+up_num).getComponent("block").num;
            var up = this.node.getChildByName("b"+up_num).num;
            // if(node.getComponent("block").num == up){
            if(node.num == up){
                for(var i=0;i<this.neighbor.length;i++){
                    if(this.neighbor[i].name.substring(1) == up_num){
                        break;
                    }
                    // console.log(this.neighbor.length,i);
                }
                // console.log(i+"www");
                if(i == this.neighbor.length){
                    var up_node = this.node.getChildByName("b"+up_num);
                    up_node.move_pos = "up";
                    this.neighbor.push(up_node);
                    // this.neighbor[this.neighbor.length-1].move_pos = "up";
                    // console.log(this.neighbor);
                    // by_up =  true;
                    this.clear(up_node,true,false,true,true,true);
                }
            }
        }
        if(index>4 && d == true){ //下
            var down_num = Number(index) - Number(5);
            // var down = this.node.getChildByName("b"+down_num).getComponent("block").num;
            var down = this.node.getChildByName("b"+down_num).num;
            // if(node.getComponent("block").num == down){
            if(node.num == down){
                for(var i=0;i<this.neighbor.length;i++){
                    if(this.neighbor[i].name.substring(1) == down_num){
                        break;
                    }
                }
                if(i == this.neighbor.length){
                    var down_node = this.node.getChildByName("b"+down_num);
                    down_node.move_pos = "down";
                    this.neighbor.push(down_node);
                    // by_down = true;
                    this.clear(down_node,false,true,true,true,true);
                }
            }
        }
        if(index>0 && Number(index)%5 != 0 && l == true){ //左
            var left_num = Number(index) - Number(1);
            // var left = this.node.getChildByName("b"+left_num).getComponent("block").num;
            var left = this.node.getChildByName("b"+left_num).num;
            // if(node.getComponent("block").num == left){
            if(node.num == left){
                for(var i=0;i<this.neighbor.length;i++){
                    if(this.neighbor[i].name.substring(1) == left_num){
                        break;
                    }
                }
                if(i == this.neighbor.length){
                    var left_node = this.node.getChildByName("b"+left_num);
                    left_node.move_pos = "left";
                    this.neighbor.push(left_node);
                    // by_left = true;
                    this.clear(left_node,true,true,true,false,true);
                }
            }
        }
        if((Number(index)+1)%5 != 0 && r == true){ //右
            var right_num = Number(index) + Number(1);
            // var right = this.node.getChildByName("b"+right_num).getComponent("block").num;
            var right = this.node.getChildByName("b"+right_num).num;
            // if(node.getComponent("block").num == right){
            if(node.num == right){
                // this.neighbor.push(right_node);
                // this.clear(right_node,true,true,false,true,true);//递归寻找
                // console.log("right");
                // right_node.runAction(cc.moveBy(0.3,-120,0));
                for(var i=0;i<this.neighbor.length;i++){
                    if(this.neighbor[i].name.substring(1) == right_num){
                        break;
                    }
                }
                if(i == this.neighbor.length){
                    var right_node = this.node.getChildByName("b"+right_num);
                    right_node.move_pos = "right";
                    this.neighbor.push(right_node);
                    // by_right = true;
                    this.clear(right_node,true,true,false,true,true);
                }
            }
        }
        // if(by_up == true){this.clear(up_node,true,false,true,true,true);}
        // if(by_down == true){this.clear(down_node,false,true,true,true,true);}
        // if(by_left == true){this.clear(left_node,true,true,true,false,true);}
        // if(by_right == true){this.clear(right_node,true,true,false,true,true);}
        this.neighbor = this.node_arr_distinct(this.neighbor); //节点数组去重
        // console.log(this.neighbor,node);
        if(this.neighbor.length>=2){ //执行合并效果
            // console.log(this.neighbor);
            this.neighbor_name = [];
            for(let j=0;j<this.neighbor.length;j++){
                this.neighbor_name.push(Number(this.neighbor[j].name.substring(1)));
            }
            this.neighbor_name = this.arr_distinct(this.neighbor_name);
            // console.log(this.neighbor_name);
        }else{
            this.unclick.active = false;
        }
        // console.log(this.neighbor);
    },
    result_fn:function(node_arr,node){ // 合并的结果 不是点击默认往左下角合并 下落并添加
        var self = this;
        this.Opportunity ++;
        
        // this.five.children[this.Opportunity-1].getComponent(cc.Sprite).spriteFrame = this.saizi_sprite[1];
        if(this.Opportunity<=5){
            self.five.children[self.Opportunity -1].runAction(cc.sequence(cc.spawn(cc.scaleTo(0.2, 1.4),cc.fadeOut(0.2, 0)),cc.delayTime(0.1),cc.callFunc(function(target) {
                // console.log(target);
                target.getComponent(cc.Sprite).spriteFrame = self.saizi_sprite[1];
                target.runAction(cc.fadeIn(0.1));
                target.scale = 0.9;
            },self.five.children[self.Opportunity - 1])));
        }
        if(this.Opportunity>5){this.Opportunity = 5};
        

        if(self.Opportunity > 1 && self.last_timer != null){
            // console.log(self.last_timer);
            clearInterval(self.last_timer);
            self.last_timer = null;
            // console.log(self.last_timer);
            self.five.children[0].getComponent(cc.Sprite).spriteFrame = self.saizi_sprite[1];
        }
        // console.log(node.name);
        // var len = node_arr.length;
        // console.log(node_arr,node.getPosition());
        self.jinbi_san.getComponent(sp.Skeleton).setAnimation(0,"await1",false);
        if(node){
            node.zIndex = 25;
            node_arr = this.node_arr_diff(node_arr,node);
        }
        // for(let i=0;i<self.node.childrenCount;i++){
        //     console.log(self.node.children[i].zIndex);
        // }
        
        var len = node_arr.length;
        var pos_up_node = [];

        function find_up_fn(target){ //回收并向上查找
            self.onEnemyKilled(target); //回收
            var pos_clear = Number(target.name.substring(1)); //获取消除了的节点的索引
            for(let j = pos_clear+5; j<25; j+=5){
                var add = true;
                for(let k = 0; k<len;k++){
                    if(j == node_arr[k].name.substring(1)){ // 进一步检查上面的节点是不是也包含在node_arr里
                        add = false;
                        break;
                    }
                }
                if(add == true){
                    // pos_up_node.push(self.node.getChildByName("b"+j).name);
                    pos_up_node.push(j); //把每列上空缺上的节点索引存入数组
                }
            }
            if(self.node.childrenCount == (25-len)){
                drap_fn();
            }
        }

        // var pos
        // var max_index = 0;
        if(node){
            for(let i=0;i<len;i++){
                // var zIndex = Math.round(Math.sqrt(Math.pow(node_arr[i].getPosition().x - node.getPosition().x,2) + Math.pow(node_arr[i].getPosition().y - node.getPosition().y,2)));
                var zIndex = Math.floor(Math.abs(node_arr[i].getPosition().x - node.getPosition().x) + Math.abs(node_arr[i].getPosition().y - node.getPosition().y));
                // console.log(zIndex);
                node_arr[i].zIndex = -zIndex;
                // if(max_index<zIndex){
                //     max_index = zIndex;
                // }
            }
        }
        
        node_arr = this.selectionSort_zindex(node_arr);
        node_arr[0].delay = 0;
        for(let i=0;i<len-1;i++){
            if(node_arr[i+1].zIndex - node_arr[i].zIndex > 10){
                node_arr[i+1].delay = node_arr[i].delay + 1;
            }else{
                node_arr[i+1].delay = node_arr[i].delay;
            }
        }
        // var max_index = node_arr[len-1].delay*50;
        var max_index2 = (node_arr[len-1].delay*0.05).toFixed(2);
        // var max_index3 = (node_arr[len-1].delay*0.05+0.35).toFixed(3);
        // console.log(max_index,max_index3);
        if(this.double>0){
            this.double --;
            if(node){this.add_score_fn(node,true);}
        }else{
            if(node){this.add_score_fn(node);} //block的加分效果
        }
        
        // console.log("...........");
        for(let i=0;i<len;i++){
            if(this.double>0){
                this.add_score_fn(node_arr[i],true);
            }else{
                this.add_score_fn(node_arr[i]); //block的加分效果SSS
            }
            
            var delay_time = (node_arr[i].delay*5)/100;
            // console.log(delay_time);
            // console.log((max_index+230));
            if(node_arr[i].move_pos == "up"){
                // console.log(node_arr[i].getPosition());
                // console.log(max_index+"wwwwwwww");
                // console.log(node_arr[i].zIndex);
                node_arr[i].runAction(cc.sequence(cc.delayTime(delay_time),cc.moveBy(0.23,0,-120),cc.callFunc(function(target) {
                    // self.onEnemyKilled(target); //回收
                    find_up_fn(target);
                }, node_arr[i])));
                
            }else if(node_arr[i].move_pos == "down"){
                node_arr[i].runAction(cc.sequence(cc.delayTime(delay_time),cc.moveBy(0.23,0,120),cc.callFunc(function(target) {
                    // self.onEnemyKilled(target); //回收
                    find_up_fn(target);
                }, node_arr[i])));  
            }else if(node_arr[i].move_pos == "left"){
                node_arr[i].runAction(cc.sequence(cc.delayTime(delay_time),cc.moveBy(0.23,120,0),cc.callFunc(function(target) {
                    // self.onEnemyKilled(target); //回收
                    find_up_fn(target);
                }, node_arr[i])));
            }else if(node_arr[i].move_pos == "right"){
                node_arr[i].runAction(cc.sequence(cc.delayTime(delay_time),cc.moveBy(0.23,-120,0),cc.callFunc(function(target) {
                    // self.onEnemyKilled(target); //回收
                    find_up_fn(target);
                }, node_arr[i])));
            }else{
                find_up_fn(node_arr[i]);
            }

        }
        self.scheduleOnce(function(){ // 闪动画 combo动画 
            if(node){
                self.block_san.setPosition(node.getPosition());
                self.block_san.getComponent(sp.Skeleton).setAnimation(0,"await2",false);
                // node.getComponent("block").num += 1;
                node.num += 1;
                // node.getComponent(cc.Sprite).spriteFrame = self.block_sprite[node.getComponent("block").num];
                if(node.num<20){
                    node.getComponent(cc.Sprite).spriteFrame = self.block_sprite[node.num];
                }else{
                    node.getComponent(cc.Sprite).spriteFrame = self.block_sprite[20];
                    node.getChildByName("text").getComponent(cc.Label).string = Number(node.num) + 1;
                    node.getChildByName("text").active = true;
                }
                if(game_msg.voice == true){self.xiaochu_bgm.play();}
                if(self.combo_label>=2 && self.combo_label<=5){
                    self.bonus.getChildByName("bonus_label").getComponent(cc.Label).string = 10;
                    self.score.getComponent(cc.Label).string = Number(self.score.getComponent(cc.Label).string)+10;
                }
                if(self.combo_label>=6 && self.combo_label<=10){
                    self.bonus.getChildByName("bonus_label").getComponent(cc.Label).string = 20;
                    self.score.getComponent(cc.Label).string = Number(self.score.getComponent(cc.Label).string)+20;
                }
                if(self.combo_label>=11 && self.combo_label<=15){
                    self.bonus.getChildByName("bonus_label").getComponent(cc.Label).string = 30;
                    self.score.getComponent(cc.Label).string = Number(self.score.getComponent(cc.Label).string)+30;
                }
                if(self.combo_label>=16 && self.combo_label<=20){
                    self.bonus.getChildByName("bonus_label").getComponent(cc.Label).string = 40;
                    self.score.getComponent(cc.Label).string = Number(self.score.getComponent(cc.Label).string)+40;
                }
                if(self.combo_label>20){
                    self.bonus.getChildByName("bonus_label").getComponent(cc.Label).string = 50;
                    self.score.getComponent(cc.Label).string = Number(self.score.getComponent(cc.Label).string)+50;
                }
                
                if(self.combo_label >1){
                    self.combo.getChildByName("combo_label").getComponent(cc.Label).string = "x"+self.combo_label;
                    self.combo.active = true;
                    self.combo.runAction(cc.scaleTo(0.2,1.1));
                    self.scheduleOnce(function(){
                        self.combo.active = false;
                        self.combo.scale = 1;
                    },0.5);
                    //bonus
                    
                    self.bonus.active = true;
                    self.bonus.runAction(cc.scaleTo(0.2,1.1));
                    self.scheduleOnce(function(){
                        self.bonus.active = false;
                        self.bonus.scale = 1;
                    },0.5);
                    // enemy.runAction(cc.sequence(cc.delayTime(0.25),cc.spawn(cc.show(),cc.scaleTo(0.05, 1))));
                    // self.combo.runAction(cc.sequence(cc.spawn(cc.show(),cc.scaleTo(0.2, 1.1)),cc.delayTime(0.5),cc.spawn(cc.hide(),cc.scaleTo(0,1))));
                }
                if(self.combo_label == 3){
                    self.combo_texiao.getComponent(sp.Skeleton).setAnimation(0,"await1",false);
                    // self.combo_texiao.getComponent(sp.Skeleton).clearTrack();
                }
                if(self.combo_label == 6){
                    self.combo_texiao.getComponent(sp.Skeleton).setAnimation(0,"await2",false);
                    // self.combo_texiao.getComponent(sp.Skeleton).clearTrack();
                }
                if(self.combo_label >=10 && self.combo_label%5 == 0){
                    self.combo_texiao.getComponent(sp.Skeleton).setAnimation(0,"await3",false);
                    // self.combo_texiao.getComponent(sp.Skeleton).clearTrack();
                }
                
                self.combo_label ++;
            }
            // this.node.insertChild(node);
        },max_index2)
        

        function drap_fn(){
            self.scheduleOnce(function(){ //找出下面的空缺并下落
                // node.zIndex = node.name.substring(1);
                // node.zIndex = 0;
                // console.log(node.zIndex);
                pos_up_node = self.arr_distinct(pos_up_node);
                // console.log("up",pos_up_node);
                var up_len = pos_up_node.length;
                for(let i = 0;i<up_len;i++){
                    var find_down = 5;
                    // console.log(pos_up_node[i]-find_down+"wowowo");
                    while(self.node.getChildByName("b"+(Number(pos_up_node[i])-find_down)) == undefined && pos_up_node[i]-find_down>=0){
                        find_down += 5;
                    }
                    // console.log(up_len);
                    // console.log(pos_up_node[i],find_down);
                    // console.log(self.node.getChildByName("b"+pos_up_node[i]).name);
                    
                    var new_name = "b"+(Number(pos_up_node[i]) - find_down + 5);
                    // var new_name_index = new_name.substring(1);
    
                    var drap_node = self.node.getChildByName("b"+Number(pos_up_node[i]));
                    // console.log(drap_node);
                    // drap_node.runAction(cc.moveTo(0.23,cc.v2(self.block_pos_arr[new_name_index])));
                    var find_down_index = (find_down-5)/5;
                    // console.log(find_down_index);
                    drap_node.runAction(cc.moveBy(0.23,0,-120*find_down_index));
                    drap_node.name = new_name;
    
                    // self.node.getChildByName(new_name).children[0].getComponent(cc.Label).string = self.node.getChildByName(new_name).getComponent("block").num + "b"+(pos_up_node[i]-find_down+5);
                    // self.node.children[i].getComponent(cc.Sprite).spriteFrame = self.block_sprite[rand_num];
                    // self.node.getChildByName(new_name).runAction(cc.moveTo(0.23,self.block_pos_arr[new_name_index].x,self.block_pos_arr[new_name_index].y));
    
                    // drap_node.runAction(cc.sequence(cc.moveTo(0.23,cc.v2(self.block_pos_arr[new_name_index])),cc.callFunc(function(target) {
                    //     // self.onEnemyKilled(target); //回收
                    //     target.name = new_name;
                    // }, drap_node)));
    
                    // console.log(self.node.children[25-up_len].name);
                }
                // console.log(self.node.children.length);
    
                // var node_children_len = self.node.children.length;
                // var add_node_num = [];//要添加的节点的索引
                // for(let j = 0;j<25;j++){ //待优化
                //     var add = true;
                //     for(let i = 0;i<node_children_len;i++){
                //         if(self.node.children[i].name.substring(1) == j ){
                //             add = false;
                //             break;
                //         }
                //     }
                //     if(add == true){
                //         add_node_num.push(j);
                //     }
                // }
                
                // // console.log(node_arr);
                // console.log("add",add_node_num);
    
                var add_node_num2 = [];
                for(let i = 0;i<len;i++){
                    var name = Number(node_arr[i].name.substring(1));
                    var some = Math.floor((24-name)/5);
                    // console.log(some);
                    name = name + 5*some;
                    find_up_add(name);
                }
                function find_up_add(name){
                    if(add_node_num2.indexOf(name)==-1){add_node_num2.push(name);}
                    else{
                        name -= 5;
                        find_up_add(name);
                    }
                }
                // console.log("new_add",add_node_num2);
    
                self.scheduleOnce(function(){
                    for(let i = 0;i<add_node_num2.length;i++){ //添加新节点 重新赋值 name
                        var push_index = add_node_num2[i];
                        self.createEnemy_later(self.node,push_index);
                    }
                },0.3);
            },0.1);
        } 
    },

    fall_check_fn:function(){ //下落之后 检查可不可以继续相消
        var self = this;
        var have = false;
        for(var i = 0;i<25;i++){
            // console.log(self.node.children[i].name);
            // var index = self.node.children[i].name.substring(1);
            // if(self.node.getChildByName("b"+i)){
                self.clear(self.node.getChildByName("b"+i),true,true,false,true,false); //左 false
                var len = self.neighbor.length;
                // console.log(self.node.getChildByName("b"+i).name + "长度"+len);
                if(len>=2){
                    have = true;
                    var new_neighbor_arr = [];
                    for(let i = 0; i<len;i++){
                        new_neighbor_arr.push(self.node.getChildByName("b"+self.neighbor_name[i]));
                    }
                    // setTimeout(function(){
                        // console.log(self.neighbor_name);

                        // console.log(new_neighbor_arr);

                        // var small = self.indexOfSmallest(self.neighbor_name); //应该不需要了

                        // console.log(self.neighbor_name[small]);
                        // console.log("wwwwwwwwwwwwwwww");

                        // console.log(small); 
                        // console.log(new_neighbor_arr[small]);
                        // alert("what");

                        // console.log(self.neighbor[samll]);
                        // self.neighbor.sort();
                        // console.log(self.neighbor);
                        // self.result_fn(new_neighbor_arr,new_neighbor_arr[small]);
                        self.result_fn(new_neighbor_arr,self.node.getChildByName("b"+i));
                    // },400);
                    break;
                    // return false;
                }
            // } 
        }
        if(i== 25 && have == false){
            self.unclick.active = false;
            if (cc.sys.platform === cc.sys.WECHAT_GAME) {
                // console.log(self.score.getComponent(cc.Label).string);
                self.onRankReq(3,self.score.getComponent(cc.Label).string);
                self.scheduleOnce(function(){self.subContextView.update();},0.5);
            }

            // self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = (self.score.getComponent(cc.Label).string/400000).toFixed(2);
            self.chenghao_fn(self.score.getComponent(cc.Label).string);
            // self.scheduleOnce(function(){
            //     self.render_sub_content();
            // },2);
        }
    },
    chenghao_fn(score){
        // 0	赌场小白
        // 5000	赌场菜鸟
        // 10000	赌场新秀
        // 20000	赌场精英
        // 40000	赌场大师
        // 80000	赌场至尊
        // 150000	赌侠
        // 400000	赌圣
        // 1000000	赌神

        var self = this;
        if(score<5000){
            self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = (score/5000).toFixed(2);
            
        }else if(score<10000){
            self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = ((score-5000)/5000).toFixed(2);
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌场菜鸟";
        }else if(score<20000){
            self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = ((score-10000)/10000).toFixed(2);
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌场新秀";
        }else if(score<40000){
            self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = ((score-20000)/20000).toFixed(2);
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌场精英";
        }else if(score<80000){
            self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = ((score-40000)/40000).toFixed(2);
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌场大师";
        }else if(score<150000){
            self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = ((score-80000)/70000).toFixed(2);
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌侠";
        }else if(score<400000){
            self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = ((score-150000)/250000).toFixed(2);
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌圣";
        }
        else if(score<1000000){
            self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = ((score-400000)/600000).toFixed(2);
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌神";
        }else{
            if(self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress != 1){
                self.chengjiu.getChildByName("jindu").getComponent(cc.ProgressBar).progress = 1;
            }
        }

        if(score>=5000 && game_msg.last_score <5000){
            self.baoxiang_main_show();
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌场菜鸟";
            self.chengjiu.getChildByName("head").getComponent(cc.Label).string = 5000;
            self.chengjiu.getChildByName("tail").getComponent(cc.Label).string = 10000;
        }
        if(score>=10000 && game_msg.last_score <10000){
            self.baoxiang_main_show();
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌场新秀";
            self.chengjiu.getChildByName("head").getComponent(cc.Label).string = 10000;
            self.chengjiu.getChildByName("tail").getComponent(cc.Label).string = 20000;
        }
        if(score>=20000 && game_msg.last_score <20000){
            self.baoxiang_main_show();
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌场精英";
            self.chengjiu.getChildByName("head").getComponent(cc.Label).string = 20000;
            self.chengjiu.getChildByName("tail").getComponent(cc.Label).string = 40000;
        }
        if(score>=40000 && game_msg.last_score <40000){
            self.baoxiang_main_show();
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌场大师";
            self.chengjiu.getChildByName("head").getComponent(cc.Label).string = 40000;
            self.chengjiu.getChildByName("tail").getComponent(cc.Label).string = 80000;
        }
        if(score>=80000 && game_msg.last_score <80000){
            self.baoxiang_main_show();
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌场至尊";
            self.chengjiu.getChildByName("head").getComponent(cc.Label).string = 80000;
            self.chengjiu.getChildByName("tail").getComponent(cc.Label).string = 150000;
        }
        if(score>=150000 && game_msg.last_score <150000){
            self.baoxiang_main_show();
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌侠";
            self.chengjiu.getChildByName("head").getComponent(cc.Label).string = 150000;
            self.chengjiu.getChildByName("tail").getComponent(cc.Label).string = 400000;
        }
        if(score>=400000 && game_msg.last_score <400000){
            self.baoxiang_main_show();
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌圣";
            self.chengjiu.getChildByName("head").getComponent(cc.Label).string = 400000;
            self.chengjiu.getChildByName("tail").getComponent(cc.Label).string = 1000000;
        }
        if(score>=1000000 && game_msg.last_score <1000000){
            self.baoxiang_main_show();
            // self.chengjiu.getChildByName("name").getComponent(cc.Label).string = "赌神";
            
        }
        // console.log(game_msg.last_score);
        game_msg.last_score = score;
    },
    bomb_btn:function(){
        var self = this;
        // var daoju_many = Number((this.bomb_node.getChildByName("many").getComponent(cc.Label).string).substring(1));
        // var daoju_many = Number(game_msg.hammer_time);
        function daoju_fn(){
            self.node.off("add_num");
            self.node.on('add_num', function (event) {
                // self.bomb(event.target.getComponent("block").num);
                // self.bomb(event.target.num);

                // console.log(event.target);
                self.Hammer(event.target);
                self.node.off("add_num");
                self.on_event();
                // self.bomb_node.destroy();
                self.daoju.getChildByName("bomb_tishi").active = false;
            })

            cc.find("Canvas/tips").active = false;
            cc.find("Canvas/tips/tips_bg/tips_label").getComponent(cc.Label).string = "点击敲除任意一个棋子";
            cc.find("Canvas/tips").active = true; 
        }
        if(game_msg.hammer_time > 0){
            daoju_fn();
            // sdk.Post(sdk.ip2+"/Reward/record",{"uid":sdk.userid,"token":cc.HQ.PlayerMgr.info.token,"num":1,"reward_type":"1","way_type":"game","handle":"reduce"},function(data){
            //     console.log(data);
            //     daoju_fn();
            //     daoju_many --;
            //     self.bomb_node.getChildByName("many").getComponent(cc.Label).string = "x"+daoju_many;
            //     if(daoju_many == 0){
            //         this.bomb_node.getChildByName("jia").active == true;
            //         self.bomb_node.getChildByName("many").active = false;
            //     }
            // });
        }else{
            this.lingqu("button_hammer");
            // if(this.bomb_node.getChildByName("jia").active == true){
                // sdk.shareAppMessage({type: 1, query: "" , success:function(){
                //     console.log("分享成功");
                //     // self.bomb_btn(true);
                //     daoju_fn();
                //     self.bomb_node.getChildByName("jia").active = false;
                //     self.bomb_node.getChildByName("many").active = true;
                // }});
                
                // sdk_out.shareAppMessage({
                //     title: '猫与蛇谁才是王者？猫蛇大战一触即发！',
                //     query: 'shareConfigId=xxx',
                //     imageUrl: "https://res.g.llewan.com/uploadfile/houtai/share/20180930/20180930120435_2671.png",
                //     success: (res) => {
                //         console.log('分享成功！', res);
                //         daoju_fn();
                //         self.bomb_node.getChildByName("jia").active = false;
                //         self.bomb_node.getChildByName("many").active = true;
                //     }
                // });
                
                
            // }
        }
    },
    //连锁炸弹
    bomb: function(num){
        var node_arr = [];
        var num_arr = [];
        this.combo_label = 1;
        for(let i=0;i<25;i++){
            var node = this.node.getChildByName("b"+i);
            // if(node.getComponent("block").num == num){
            if(node.num == num){
                node.move_pos = null;
                node_arr.push(node);
                num_arr.push(i);
            }
        }
        this.result_fn(node_arr);
        for(let i=0;i<num_arr.length;i++){
            this.bomb_main.children[num_arr[i]].getComponent(sp.Skeleton).setAnimation(0,"await1",false);
        }
    },
    //锤子
    Hammer(node){
        // console.log(node);
        game_msg.hammer_time --;
        this.bomb_node.getChildByName("many").getComponent(cc.Label).string = "x"+game_msg.hammer_time;
        if(game_msg.hammer_time == 0){
            // console.log("cccccc");
            this.bomb_node.getChildByName("jia").active = true;
            this.bomb_node.getChildByName("many").active = false;
        }
        var arr = [];
        arr.push(node);
        this.result_fn(arr);
        this.bomb_main.children[node.name.substring(1)].active = true;
        this.bomb_main.children[node.name.substring(1)].getComponent(sp.Skeleton).setAnimation(0,"await1",false);
    },
    wanneng_btn:function(){
        var self = this;
        var daoju_many = Number((this.wanneng_node.getChildByName("many").getComponent(cc.Label).string).substring(1));
        if(daoju_many > 0){
            self.node.off("add_num");
            self.node.on('add_num', function (event) {
                // self.bomb(event.target.getComponent("block").num);
                self.wanneng(event.target);

                // self.Opportunity_add1();
                // self.node.off("add_num");
                // self.on_event();
            })

            // sdk.Post(sdk.ip2+"/Reward/record",{"uid":sdk.userid,"token":cc.HQ.PlayerMgr.info.token,"num":1,"reward_type":"4","way_type":"game","handle":"reduce"},function(data){
            //     console.log(data);
            //     self.node.off("add_num");
            //     self.node.on('add_num', function (event) {
            //         // self.bomb(event.target.getComponent("block").num);
            //         self.wanneng(event.target);
            //     })
            // });
            
        }
        if(this.wanneng_node.getChildByName("jia").active == true){
            // sdk.shareAppMessage({type: 1, query: "" , success:function(){
            //     console.log("分享成功");
            //     self.node.off("add_num");
            //     self.node.on('add_num', function (event) {
            //         // self.bomb(event.target.getComponent("block").num);
            //         self.wanneng(event.target);
            //     })
            // }});

            // sdk_out.shareAppMessage({
            //     title: '猫与蛇谁才是王者？猫蛇大战一触即发！',
            //     query: 'shareConfigId=xxx',
            //     imageUrl: "https://res.g.llewan.com/uploadfile/houtai/share/20180930/20180930120435_2671.png",
            //     success: (res) => {
            //         console.log('分享成功！', res);
            //         self.node.off("add_num");
            //         self.node.on('add_num', function (event) {
            //             // self.bomb(event.target.getComponent("block").num);
            //             self.wanneng(event.target);
            //         })
            //     }
            // });
        }
    },
    //万能筹码
    wanneng: function(node){
        // cc.loader.loadRes("images/icon_wncm",cc.SpriteFrame,function (err, spriteFrame) {
        //     if (err) {
        //         cc.error(err.message || err);
        //         return;
        //     }
        //     node.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        // })
        var self = this;
        var node_num = node.num;
        // clear_fn
        var index = Number(node.name.substring(1));
        var around = [];
        var num_arr = [];
        if(index<20){ //上
            var num = this.node.getChildByName("b"+ (index+5)).num;
            // var msg = {"pos":"up","node":node}
            around.push(num);
        }
        if(index>4){ //下
            var num = this.node.getChildByName("b"+ (index-5)).num;
            // var msg = {"pos":"down","node":node}
            around.push(num);
        }
        if(index>0 && index%5 != 0){ //判断左边有没有
            var num = this.node.getChildByName("b"+ (index-1)).num;
            // var msg = {"pos":"left","node":node}
            around.push(num);
        }
        if((index+1)%5 != 0){ //右
            var num = this.node.getChildByName("b"+ (index+1)).num;
            // var msg = {"pos":"right","node":node}
            around.push(num);
        }
        // num_arr = this.arr_distinct(around);
        // console.log(around);
        around = this.arr_distinct(around);
        around = around.sort();
        // console.log(around);
        // num_arr = num_arr.sort();
        // console.log(around);

        var around_len = around.length-1;
        var wanneng_xiao = false;
        for(let i = around_len;i>=0;i--){
            node.num = around[i];
            this.clear(node,true,true,true,true,false);
            var len = this.neighbor.length;
            // console.log(len);
            if(len>=2){
                this.combo_label = 1;
                self.wannng_main.children[0].setPosition(node.getPosition());
                self.wannng_main.children[0].getComponent(sp.Skeleton).setAnimation(0,"await1",false);
                // console.log(i);
                this.result_fn(this.neighbor,node); //合并效果 下坠 添加新节点
                self.neighbor = [];
                wanneng_xiao = true;

                var daoju_many = Number((this.wanneng_node.getChildByName("many").getComponent(cc.Label).string).substring(1));
                if(daoju_many > 0){
                    daoju_many --;
                    self.wanneng_node.getChildByName("many").getComponent(cc.Label).string = "x"+daoju_many;
                    if(daoju_many == 0){
                        self.wanneng_node.getChildByName("jia").active = true;
                        self.wanneng_node.getChildByName("many").active = false;
                    }
                }else{
                    if(self.wanneng_node.getChildByName("jia").active == true){
                        self.wanneng_node.getChildByName("jia").active = false;
                        self.wanneng_node.getChildByName("many").active = true;
                    }
                }

                // self.wanneng_node.destroy();
                self.daoju.getChildByName("wanneng_tishi").active = false;
                self.node.off("add_num");
                self.on_event();
                break;
            }
        }
        if(wanneng_xiao == false){
            node.num = node_num;
            // console.log(node.num);
            self.wanneng_no.active = true;
            self.scheduleOnce(function(){
                self.wanneng_no.active = false;
            },1.5);
        }
    },
    //加一步
    Opportunity_add1(){
        var self = this;
        if(this.Opportunity < 5){
            if(game_msg.Opportunity_add_time>0){
                game_msg.Opportunity_add_time --;
                if(self.Opportunity == 1){
                    // console.log("")
                    self.five.children[0].getComponent(cc.Sprite).spriteFrame = self.saizi_sprite[1];
                    clearInterval(self.last_timer);
                    self.last_timer = null;
                }
                this.Opportunity ++;
                self.double_node.getChildByName("many").getComponent(cc.Label).string = "x"+game_msg.Opportunity_add_time;
                if(game_msg.Opportunity_add_time <= 0){
                    self.double_node.getChildByName("jia").active = true;
                    self.double_node.getChildByName("many").active = false;
                }
                for(let i=0; i<this.Opportunity;i++){
                    this.five.children[i].getComponent(cc.Sprite).spriteFrame = this.saizi_sprite[1];
                } 
            }else{
                this.lingqu("button_opportunity_add");
            } 
        }else{
            cc.find("Canvas/tips").active = false;
            cc.find("Canvas/tips/tips_bg/tips_label").getComponent(cc.Label).string = "步数已满";
            cc.find("Canvas/tips").active = true;
            // console.log("步数满",this.Opportunity);
            // if(game_msg.Opportunity_add_time<=0){

            // }
        }      
    },
    //刷新
    Refresh(){
        if(game_msg.refresh_time>0){
            game_msg.refresh_time --;
            if(game_msg.refresh_time <=0){
                this.wanneng_node.getChildByName("many").active = false;
                this.wanneng_node.getChildByName("jia").active = true;
            }
            this.wanneng_node.getChildByName("many").getComponent(cc.Label).string = "x"+game_msg.refresh_time;

            var pos_arr = [].concat(this.block_pos_arr);
            this.unclick.active = true;
            for(let i=0;i<25;i++){
                var suiji = this.rand(0,pos_arr.length-1);
                // console.log(suiji,pos_arr.length);
                this.node.children[i].runAction(cc.moveTo(0.3,cc.v2(pos_arr[suiji])));
                var index = this.block_pos_arr.indexOf(pos_arr[suiji]);
                // console.log(index, this.block_pos_arr[index],pos_arr[suiji])
                this.node.children[i].name = 'b'+index;
                pos_arr.splice(suiji, 1);
                // console.log(pos_arr);
                if(i == 24){
                    this.scheduleOnce(function(){
                        this.fall_check_fn();
                        // this.unclick.active = false;
                    },0.4)
                }
            }
        }else{
            this.lingqu("button_refresh");
        }
        
        
        
    },
    
    
    //五步双倍积分
    double_btn: function(){
        var self = this;
        var daoju_many = Number((this.double_node.getChildByName("many").getComponent(cc.Label).string).substring(1));
        // if(this.double_node.getChildByName("jia").active == true || daoju_many > 0){
            // this.double_node.destroy();
            if(daoju_many>0){
                
                // sdk.Post(sdk.ip2+"/Reward/record",{"uid":sdk.userid,"token":cc.HQ.PlayerMgr.info.token,"num":1,"reward_type":"2","way_type":"game","handle":"reduce"},function(data){
                //     console.log(data);
                //     self.double = 6;
                //     daoju_many --;
                //     self.double_node.getChildByName("many").getComponent(cc.Label).string = "x"+daoju_many;
                //     if(daoju_many == 0){
                //         self.double_node.getChildByName("jia").active = true;
                //         self.double_node.getChildByName("many").active = false;
                //     }
                // })  
            }else{
                if(self.double_node.getChildByName("jia").active == true){
                    // sdk.shareAppMessage({type: 1, query: "" , success:function(){
                    //     self.double = 6;
                    //     self.double_node.getChildByName("jia").active = false;
                    //     self.double_node.getChildByName("many").active = true;
                    // }});

                    // sdk_out.shareAppMessage({
                    //     title: '猫与蛇谁才是王者？猫蛇大战一触即发！',
                    //     query: 'shareConfigId=xxx',
                    //     imageUrl: "https://res.g.llewan.com/uploadfile/houtai/share/20180930/20180930120435_2671.png",
                    //     success: (res) => {
                    //         console.log('分享成功！', res);
                    //         self.double = 6;
                    //         self.double_node.getChildByName("jia").active = false;
                    //         self.double_node.getChildByName("many").active = true;
                    //     }
                    // });
                }
                
            }
            self.daoju.getChildByName("double_tishi").active = false;
        // } 
    },
    //分享获得炸弹
    share_bomb: function(){
        var self = this;
        sdk.shareAppMessage({type: 1, query: "" , success:function(){
            console.log("分享成功");
            self.bomb_btn(true);
        }});
    },
    //分享获得双倍积分
    share_double: function(){
        var self = this;
        sdk.shareAppMessage({type: 1, query: "" , success:function(){
            console.log("分享成功");
            self.double_btn(true);
        }});
    },

    //分享获得万能筹码
    share_wanneng: function(){
        var self = this;
        sdk.shareAppMessage({type: 1, query: "" , success:function(){
            console.log("分享成功");
            self.wanneng_btn(true);
        }});
    },


    //排行榜的主域向子域发送请求
    onRankReq: function(n,score){
        //好友排行榜
        var mydata = {
            type:'FriendCloud',
            data:'',
            key:['score'],
            num:n,
            curScore:score
        };
        send_data_to_sub(mydata);
        // console.log("cc.HQ.PlayerMgr.info.openid--------->" +cc.HQ.PlayerMgr.info.openid);

        //我的数据
        // var mydata1 ={
        //     type:'UserCloud',
        //     data:'',
        //     key:['score'],
        //     openid:game_msg.openid,
        // };
        // cc.HQ.WechatApi.send_data_to_sub(mydata1);
    },
    //渲染子域的内容(这个需要等子域处理完再调，一般可以等个1秒钟)
    render_sub_content:function(){
        // if(this._tex){
        //     this._tex.initWithElement(window.sharedCanvas);
        //     this._tex.handleLoadedTexture();
        //     this.beyond_main.spriteFrame = new cc.SpriteFrame(this._tex);
        // }
    },
    add_score_fn:function(node,double){ //加分效果
        var self = this;
        var index = node.name.substring(1);
        // var node_num = node.getComponent("block").num;
        // var number = (Number(node.getComponent("block").num)+1)*10;
        if(double){
            var number = (Number(node.num)+1)*20;
            self.double_texiao.getComponent(sp.Skeleton).setAnimation(0,"await1",false);
            self.double_texiao.getComponent(sp.Skeleton).addAnimation(0,"await2",false);
            self.double_texiao.getComponent(sp.Skeleton).addAnimation(0,"await3",false);
        }else{
            var number = (Number(node.num)+1)*10;
        }
        this.add_main.children[index].getComponent(cc.Label).string = "+" + number;
        this.score.getComponent(cc.Label).string = Number(this.score.getComponent(cc.Label).string) + number;
        this.add_main.children[index].active = true;
        this.add_main.children[index].runAction(cc.moveBy(0.3,cc.v2(0,18)));
        self.scheduleOnce(function(){
            self.add_main.children[index].active = false;
            self.add_main.children[index].setPosition(cc.v2(self.block_pos_arr[index]));
        },0.6);
    },
    //游戏结束请求服务器
    // gameEndReq: function(num){
    //     var mydata = {"a":"game_over","m":"init","d":{"fs":num,"bs":1}};
    //     cc.HQ.net.packAjaxSend(cc.HQ.Global.game_url,mydata,"POST");  
    // },

    tanchuang(){
        this.set_main.getChildByName("sure").active = true;
    },
    quxiao(){
        this.set_main.getChildByName("sure").active = false;
    },
    //重新开始按钮
    restart_btn(){
        var self =this;
        this.Opportunity = 5;
        for(let i = 0;i<5;i++){
            self.five.children[i].getComponent(cc.Sprite).spriteFrame = self.saizi_sprite[1];
        }
        if(self.last_timer != null){
            clearInterval(self.last_timer);
            self.last_timer = null;
        }
        this.set_main.active = false;
        this.set_main.getChildByName("sure").active = false;
        this.score.getComponent(cc.Label).string = 0;
        for(let i = 0;i<25;i++){
            var rand_num = self.rand(0,4);
            // self.node.children[i].getComponent("block").num = rand_num;
            self.node.children[i].num = rand_num;
            self.node.children[i].getComponent(cc.Sprite).spriteFrame = self.block_sprite[rand_num];
        }
        self.check(false);

        // cc.sys.localStorage.removeItem("node_msg_arr");
        // cc.sys.localStorage.removeItem("fenxiang");
        // cc.sys.localStorage.removeItem("shipin");
        // cc.sys.localStorage.removeItem("fuhuobi");
        // cc.sys.localStorage.removeItem("bomb");
        // cc.sys.localStorage.removeItem("double");
        // cc.sys.localStorage.removeItem("wanneng");
        // self.daoju_houtai_msg();

        game_msg.node_msg_arr = [];
        game_msg.score = 0,
        game_msg.last_score = 0,
        game_msg.fengxiang_fuhuo = true;
        game_msg.shipin_fuhuo = true;
        game_msg.danger_tip = true;
        game_msg.daojishi = true;
        sdk.setToServer("GameMsg","Json",game_msg,-1); // 重新开始保存一次
    },
    fuhuo_san: function(){
        var self = this;
        
        // sdk.Post(sdk.ip2+"/Reward/record",{"uid":sdk.userid,"token":cc.HQ.PlayerMgr.info.token,"num":1,"reward_type":"3","way_type":"game","handle":"reduce"},function(data){
        //     console.log(data); 
        // });
        
        this.unclick.active = false;
        this.result_page.active =false;
        this.node.parent.parent.active = true;
        
        clearInterval(self.last_timer);
        self.last_timer = null;
        
        this.Opportunity = 5;
        for(let i=0; i<this.Opportunity;i++){
            this.five.children[i].getComponent(cc.Sprite).spriteFrame = this.saizi_sprite[1];
        }
        // self.fuhuobi_fuhuo.getComponent(cc.Button).interactable = false;
        //     // console.log("interactable",self.fengxiang_fuhuo.getComponent(cc.Button).interactable);
        // cc.loader.loadRes("images/fuhuobifuhuo_huise",cc.SpriteFrame,function (err, spriteFrame) {
        //     if (err) {
        //         cc.error(err.message || err);
        //         return;
        //     }
        //     self.fuhuobi_fuhuo.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        // });
    },
    //分享复活按钮
    onShare_live: function(){
        // var LaunchOption = wx.getLaunchOptionSync();
        // console.log("分享的uid",LaunchOption.query);
        var self = this;
        // //设置分享的值
        // cc.HQ.WechatApi.setShareInfo("",cc.HQ.WechatApi.shareInfoData.fs);
        // //处理分享
        // cc.HQ.WechatApi.shareAppMessage();

        //  //设置分享的值
        //  cc.HQ.WechatApi.setShareInfo(cc.HQ.WechatApi.NORMAL,cc.HQ.WechatApi.shareInfoData.bs);
        //  cc.HQ.WechatApi.shareAppMessage(function(res){
        //      console.log('分享成功',res);
        //      if(res.shareTickets){
        //         //  this._shareState =true;
        //          //分享后可以继续游戏了
        //         //  self.fengxiang_fuhuo.active = false;
        //          self.fuhuo_san();
        //         // console.log("interactable",self.fengxiang_fuhuo.getComponent(cc.Button).interactable);
        //         self.fengxiang_fuhuo.getComponent(cc.Button).interactable = false;
        //         // console.log("interactable",self.fengxiang_fuhuo.getComponent(cc.Button).interactable);
        //         cc.loader.loadRes("images/fenxiangfuhuo_huise",cc.SpriteFrame,function (err, spriteFrame) {
        //             if (err) {
        //                 cc.error(err.message || err);
        //                 return;
        //             }
        //             self.fengxiang_fuhuo.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        //         });
        //      }else{
        //         //  console.log("分享给个人不给续命");
        //         //  this._shareState =false;      
        //      }
        //  }.bind(this),function(res){
        //      console.log('分享失败');
        //     //  this._shareState =false; 
        //  }.bind(this),function(){
        //      console.log('分享完成');
        //  }.bind(this))

        //  sdk.shareAppMessage({type: 1, query: "" , success:function(){
        //     console.log("分享成功");
        //     self.fuhuo_san();
        //     self.fengxiang_fuhuo.getComponent(cc.Button).interactable = false;
        //     cc.loader.loadRes("images/fenxiangfuhuo_huise",cc.SpriteFrame,function (err, spriteFrame) {
        //         if (err) {
        //             cc.error(err.message || err);
        //             return;
        //         }
        //         self.fengxiang_fuhuo.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        //     });
        // }});

        // sdk_out.shareAppMessage({
        //     title: '猫与蛇谁才是王者？猫蛇大战一触即发！',
        //     query: 'shareConfigId=xxx',
        //     imageUrl: "https://res.g.llewan.com/uploadfile/houtai/share/20180930/20180930120435_2671.png",
        //     success: (res) => {
        //         console.log('分享成功！', res);
        //         self.fuhuo_san();
        //         self.fengxiang_fuhuo.getComponent(cc.Button).interactable = false;
        //         cc.loader.loadRes("images/fenxiangfuhuo_huise",cc.SpriteFrame,function (err, spriteFrame) {
        //             if (err) {
        //                 cc.error(err.message || err);
        //                 return;
        //             }
        //             self.fengxiang_fuhuo.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        //         });
        //     }
        // });

    },
    //看视频复活
    shipin_live(){
        var self = this;

        this.bgm.mute = true;
        this.xiaochu_bgm.mute = true;
        

        // sdk_out.checkVideoAd({adUnitId:"adunit-425a1e8b71036823",function() {
        //     console.log("获取成功。。。。。。。。。。。")
        // }, function() {
        //     console.log("error")
        // } });

        // sdk_out.showVideoAd({ adUnitId:"adunit-425a1e8b71036823", onShow:(res) =>{
        //     console.log("展示广告。。。。。。。。。。。")
        // }, onClose: (res) => {
        //     // 微信基础库 2.1.0 之前无法判断是否看完，关闭就默认看完，2.1.0以后根据 res.isEnded 判断是否看完广告
        //     if (!res || res.isEnded) {
        //         // 广告看完关闭
        //         self.fuhuo_san();
        //         self.shipin_fuhuo.getComponent(cc.Button).interactable = false;
        //         cc.loader.loadRes("images/kanshipinfuhuo_huise",cc.SpriteFrame,function (err, spriteFrame) {
        //             if (err) {
        //                 cc.error(err.message || err);
        //                 return;
        //             }
        //             self.shipin_fuhuo.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        //         });

        //         if(self.voice == false){
        //             self.bgm.mute = false;
        //             self.xiaochu_bgm.mute = false; 
        //         }
        //     } else {
        //         // 广告未看完关闭
        //     }
        // }, onError:(res) =>{
        //     console.log("onerror");
        // } })


        // var videoAd = sdk.createRewardedVideoAd();
        // videoAd.load().then(() => videoAd.show());

    },
    bgm_control_fn(){ //声音开关
        // console.log(this.voice);
        // this.voice = !this.voice;
        // console.log(this.voice);
        game_msg.voice = !game_msg.voice;
        if(game_msg.voice == true){
            // this.bgm.mute = true;
            // this.xiaochu_bgm.mute = true;
            this.bgm.play();
            this.xiaochu_bgm.play();
            this.bgm_control.children[0].active = true;
        }else{
            // this.bgm.mute = false;
            // this.xiaochu_bgm.mute = false;
            this.bgm.pause();
            this.xiaochu_bgm.pause();
            this.bgm_control.children[0].active = false;
        }
        // this.set_main.active = false;
    },
    not_repeat_fn:function(arr){
        var arr_all = [0,1,2,3,4];
        var remain = this.arr_diff(arr_all,arr); //取一个和周围不一样的数
        // console.log(remain);
        var new_num = remain[this.rand(0,remain.length-1)];
        // console.log(new_num);
        return new_num;
    },
    rand:function(min,max){
        return Math.floor(Math.random()*(max-min+1) + min);
    },
    arr_distinct:function(arr){ //数组去重
        var result = [],i,j,len = arr.length;
        for(i = 0; i < len; i++){
         for(j = i + 1; j < len; j++){
          if(arr[i] == arr[j]){
           j = ++i;
          }
         }
         result.push(arr[i]);
        }
        return result;
    },
    arr_diff:function(a, b) { //两个数组比较去重
        for(var i=0;i<b.length;i++)
        {
          for(var j=0;j<a.length;j++)
          {
            if(a[j]==b[i]){
              a.splice(j,1);
              j=j-1;
            }
          }
        } 
      return a;
    },
    node_arr_distinct:function(arr){ //节点数组去重
        var result = [],i,j,len = arr.length;
        for(i = 0; i < len; i++){
         for(j = i + 1; j < len; j++){
          if(arr[i].name == arr[j].name){
           j = ++i;
          }
         }
         result.push(arr[i]);
        }
        return result;
    },
    node_arr_diff:function(a, b) { //节点数组去除当前点击的节点
          for(var j=0;j<a.length;j++)
          {
            if(a[j].name == b.name){
              a.splice(j,1);
              j=j-1;
            }
          }
      return a;
    },
    indexOfSmallest:function (a) { //求数组最小值
        var lowest = 0;
        for (let i = 1; i < a.length; i++) {
         if (a[i] < a[lowest]) lowest = i;
        }
        return lowest;
    },
    selectionSort: function (arr) { // 按name排序
    　　var len = arr.length;
    　　var minIndex, temp;
    　　for (var i = 0; i < len - 1; i++) {
    　　　　minIndex = i;
    　　　　for (var j = i + 1; j < len; j++) {
    　　　　　　if (Number(arr[j].name) < Number(arr[minIndex].name)) { //寻找最小的数
    　　　　　　　　minIndex = j; //将最小数的索引保存
    　　　　　　}
    　　　　}
    　　　　temp = arr[i];
    　　　　arr[i] = arr[minIndex];
    　　　　arr[minIndex] = temp;
    　　}
    　　return arr;
    },
    selectionSort_zindex: function (arr) { // 按name排序
    　　var len = arr.length;
    　　var minIndex, temp;
    　　for (var i = 0; i < len - 1; i++) {
    　　　　minIndex = i;
    　　　　for (var j = i + 1; j < len; j++) {
    　　　　　　if (Number(arr[j].zIndex) < Number(arr[minIndex].zIndex)) { //寻找最小的数
    　　　　　　　　minIndex = j; //将最小数的索引保存
    　　　　　　}
    　　　　}
    　　　　temp = arr[i];
    　　　　arr[i] = arr[minIndex];
    　　　　arr[minIndex] = temp;
    　　}
    　　return arr;
    },
    selectionSort_num: function (arr) { // 按num排序
    　　var len = arr.length;
    　　var minIndex, temp;
    　　for (var i = 0; i < len - 1; i++) {
    　　　　minIndex = i;
    　　　　for (var j = i + 1; j < len; j++) {
    　　　　　　if (Number(arr[j].num) < Number(arr[minIndex].num)) { //寻找最小的数
    　　　　　　　　minIndex = j; //将最小数的索引保存
    　　　　　　}
    　　　　}
    　　　　temp = arr[i];
    　　　　arr[i] = arr[minIndex];
    　　　　arr[minIndex] = temp;
    　　}
    　　return arr;
    },

    // update (dt) {
        
    // },

    fail_fn(){
        cc.find("Canvas/tips").active = false;
        cc.find("Canvas/tips/tips_bg/tips_label").getComponent(cc.Label).string = "未看完视频，获取奖励失败";
        cc.find("Canvas/tips").active = true; 
        this.click_after();
    },
    success_fn(self,button_name){
        if(button_name == "button_opportunity_add"){
            // sdk.setSceneEvent("加一步","点击","加一步视频",{},null);
            game_msg.Opportunity_add_time ++;
        }
        if(button_name == "button_hammer"){
            // sdk.setSceneEvent("锤子","点击","锤子视频",{},null);
            game_msg.hammer_time ++;
        }
        if(button_name == "button_refresh"){
            // sdk.setSceneEvent("刷新","点击","刷新视频",{},null);
            game_msg.refresh_time ++;
        }
        if(button_name == "fuhuo_daojishi"){
            self.fuhuo_san();
            self.daojishi10.active = false;
            self.click_after();
            return false;
        }
        self.get_daoju_open(button_name);
        self.daoju_many();
        self.click_after();
        self.baoxiang_main.active = false;
        self.dander_main.active = false;
        return false;
    },
    click_after(){
        var self = this;
        self.click = true;
        // self.share_video = sdk.getButtonConfig("aixinbuzu");

        // if(self.share_video.type == "video"){
        //     self.node.getChildByName("red_kuang").getChildByName("label").getComponent(cc.Label).string ="观看视频";
        // }else{
        //     self.node.getChildByName("red_kuang").getChildByName("label").getComponent(cc.Label).string ="领取奖励";
        // }
    },
    videoError(self,button_name){
        sdk.shareAppMessage({type: 3, query: "" , cancel:function(){
            cc.find("Canvas/tips").active = false;
            cc.find("Canvas/tips/tips_bg/tips_label").getComponent(cc.Label).string = game_msg.share_tip;
            cc.find("Canvas/tips").active = true;
            self.click_after();
        }, success:function(){
            console.log("分享成功");
            self.success_fn(self,button_name);
        }});
    },
    lingqu(button_name){
        var self = this;
        // console.log("次数",quju_global.love_buzu_time);
        // if(quju_global.love_buzu_time>10){
        //     cc.find("Canvas/tips").active = false;
        //     // cc.find("Canvas/tips/tips_bg/tips_label").getComponent(cc.Label).string = "今日次数已达到上限";
        //     cc.find("Canvas/tips/tips_bg/tips_label").getComponent(cc.Label).string = this.label_arr[self.rand(0,2)];
        //     cc.find("Canvas/tips").active = true;
        //     return false;
        // }
        // console.log("视频分享",share_video);

        // console.log(typeof button_name);

        if(typeof button_name == "string"){
            var share_video = sdk.getButtonConfig(button_name);
        }else{
            var share_video = this.share_video;
            button_name = this.houtai_button_name;
            // console.log(this.share_video,this.houtai_button_name)
        }
        
        // console.log(share_video);

        if(this.click == true){
            if(share_video.type == "video"){
                var video_rand = quju_rand(1,2);
                    adSdk.videoSuccess = null;
                    adSdk.videoSuccess = function(){self.success_fn(self,button_name);};
                    adSdk.videoFail = function(){self.fail_fn();};
                    adSdk.videoError = null;
                    adSdk.videoError = function(){self.videoError(self,button_name);};
                    var videoAd = adSdk.createRewardedVideoAd(video_rand,quju_video.video[video_rand-1]);
                    videoAd.load().then(() => videoAd.show());

                    if(button_name == "button_opportunity_add"){
                        sdk.setSceneEvent("加一步","点击","加一步视频",{},null);
                    }
                    if(button_name == "button_hammer"){
                        sdk.setSceneEvent("锤子","点击","锤子视频",{},null);
                    }
                    if(button_name == "button_refresh"){
                        sdk.setSceneEvent("刷新","点击","刷新视频",{},null);
                    }
                    if(button_name == "fuohuo_daojishi"){
                        self.unschedule(self.callback);
                        sdk.setSceneEvent("复活","点击","复活视频",{},null);   
                    }
            }else{
                if(button_name == "button_opportunity_add"){
                    sdk.setSceneEvent("加一步","点击","加一步分享",{},null);
                    var type = 6;
                }
                if(button_name == "button_hammer"){
                    sdk.setSceneEvent("锤子","点击","锤子分享",{},null);
                    var type = 7;
                }
                if(button_name == "button_refresh"){
                    sdk.setSceneEvent("刷新","点击","刷新分享",{},null);
                    var type = 8;
                }
                if(button_name == "fuohuo_daojishi"){
                    self.unschedule(self.callback);
                    sdk.setSceneEvent("复活","点击","复活分享",{},null);
                    var type = 5;
                }
                
                sdk.shareAppMessage({type: type, query: "" , cancel:function(){
                    cc.find("Canvas/tips").active = false;
                    cc.find("Canvas/tips/tips_bg/tips_label").getComponent(cc.Label).string = game_msg.share_tip;
                    cc.find("Canvas/tips").active = true;
                    self.click_after();
                }, success:function(){
                    console.log("分享成功");
                    self.success_fn(self,button_name);
                }});
            }
    
            this.click = false;
            self.scheduleOnce(function(){
                self.click = true;
            },3)
        }
        

        
    },
   
    
});
