import GameModel from "../Model/GameModel"; import Toast from "../Utils/Toast"; import SdkUtil from "../Utils/SdkUtil" import MusicImgChange from "../Utils/MusicImgChange" // import AudioUtils from "../Utils/AudioUtils"; import Utils from "../Utils/Utils"; cc.Class({ extends: cc.Component, properties: { grid:{ default:null, type:cc.Node }, audioButton:{ default: null, type: cc.Node }, audioSource:{ type:cc.AudioSource }, skillTip:{ default:null, type:cc.Node }, //点击时的音效 click:{ default:null, type: cc.AudioClip }, isVideoAd:false, //静音按钮是否按下:false表示未按下 musicBtnState: false, }, isCrushOne: false, //消除一个格子 isStepPause: false, //计步器 isCrushRow: false, //消除整行 isCrushCol: false, //消除整列 isCrushOneType: false, //消除一种类型 // LIFE-CYCLE CALLBACKS: onLoad () { //只消除一个的道具数量 this.eliminateOneNum = 10; //暂停步数的道具数量 this.stepPauseNum = 10; //剩余刷新次数 this.refreshNum = 10; //消除整行的道具数量 this.crushRowAllNum = 10; //消除整列的道具数量 this.crushColAllNum = 10; //消除一种类型的道具数据 this.crushOneTypeNum = 10; //已完成的关卡数量 // this.levelNum = 6; // if (this.levelNum > 10){ // //初始化加载的动物种类的数量 // this.initTypeNum = 6; // }else if (this.levelNum > 5){ // //初始化加载的动物种类的数量 // this.initTypeNum = 5; // }else { // //初始化加载的动物种类的数量 // this.initTypeNum = 4; // } //已获取的分数 // this.scoreTotal = 100; // let audioButton = this.node.parent.getChildByName("AudioButton") // audioButton.on("click",this.callback,this) SdkUtil.Instance.motivational_Video_Load() this.gameModel = new GameModel(); // this.gameModel.init(this.initTypeNum); this.gameModel.init(4); this.gridScript = this.grid.getComponent("GridView"); this.gridScript.setController(this); this.gridScript.initWithCellModels(this.gameModel.getCells()); this.audioSource = cc.find("Canvas/GameScene")._components[1].audio; // console.log("num:",this.initTypeNum) }, // callback(){ // let state = this.audioSource._state; // state === 1 ? this.audioSource.pause() : this.audioSource.play(); // Toast(state === 1 ? "关闭背景音乐🎵" : "打开背景音乐🎵"); // }, //音乐开关按钮 musicBtn(){ let sprite = cc.find("Canvas/MusicBtn") this.musicBtnState = !this.musicBtnState; if (this.musicBtnState){ // console.log("音乐关") this.audioSource.pause() sprite.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("MusicImgChange").imgOff }else { // console.log("音乐开") this.audioSource.play() sprite.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("MusicImgChange").imgOn } }, selectCell(pos){ // console.log("ppos:",pos) return this.gameModel.selectCell(pos); }, cleanCmd(){ this.gameModel.cleanCmd(); }, start () { //根据初始化的动物种类数量,生成随机数组 // let arr = Math.random()*this.initTypeNum+1 // console.log("arr:",arr) }, update (dt) { //当前的关卡数 // let curLevel = cc.find("Canvas/TopResult/LevelNum").getComponent(cc.Label) // let curLevelNum = this.levelNum + 1; // curLevel.string = "第" + curLevelNum + "关"; // let sprite = cc.find("Canvas/TopResult/TargetArea") // // //关卡目标 // if (this.levelNum >= 8){ // let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne"); // let targetTwo = cc.find("Canvas/TopResult/TargetArea/Layout/TargetTwo"); // let targetThree = cc.find("Canvas/TopResult/TargetArea/Layout/TargetThree"); // targetOne.active = true; // targetTwo.active = true; // targetThree.active = true; // // targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear; // targetTwo.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").cat; // targetThree.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").fox; // // }else if (this.levelNum >= 5){ // let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne"); // let targetTwo = cc.find("Canvas/TopResult/TargetArea/Layout/TargetTwo"); // targetOne.active = true; // targetTwo.active = true; // targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear; // targetTwo.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").cat; // }else { // let targetOne = cc.find("Canvas/TopResult/TargetArea/Layout/TargetOne"); // targetOne.active = true; // targetOne.getComponent(cc.Sprite).spriteFrame = sprite.getComponent("TargetUtils").bear; // } //获取只消除一个的道具数量 let eliminateNum = cc.find("Canvas/BottomUtils/Utils/eliminateOne/eliminateOneNum").getComponent(cc.Label); eliminateNum.string = this.eliminateOneNum; //获取暂停步数的道具数量 let stepPauseNum = cc.find("Canvas/BottomUtils/Utils/stepPause/stepPauseNum").getComponent(cc.Label); stepPauseNum.string = this.stepPauseNum; //获取刷新次数 let refreshNum = cc.find("Canvas/BottomUtils/Utils/refresh/refreshNum").getComponent(cc.Label); refreshNum.string = this.refreshNum; //获取消除整行的道具数量 let crushOneRow = cc.find("Canvas/BottomUtils/Utils/crushRow/crushRowNum").getComponent(cc.Label); crushOneRow.string = this.crushRowAllNum; //获取消除整列的道具数量 let crushOneCol = cc.find("Canvas/BottomUtils/Utils/crushCol/crushColNum").getComponent(cc.Label); crushOneCol.string = this.crushColAllNum; //获取消除一种类型的道具数量 let crushOneType = cc.find("Canvas/BottomUtils/Utils/bombOne/crushOneTypeNum").getComponent(cc.Label); crushOneType.string = this.crushOneTypeNum; }, //道具消除一个块 processCrushOne(pos){ return this.gameModel.processCrushOne(pos); }, //道具消除一行 processCrushRow(pos){ return this.gameModel.processCrushRow(pos); }, //道具消除一列 processCrushCol(pos){ return this.gameModel.processCrushCol(pos); }, //道具消除一种类型 processCrushOneType(pos){ return this.gameModel.processCrushOneType(pos); }, onSkill(e,type){ if(this.isVideoAd){ SdkUtil.Instance.motivational_Video_Show(()=>{ this[type]() }, ()=>{ console.log('激励广告加载失败') }) }else{ this[type]() } }, //道具消除一个 onEliminateOne(){ cc.audioEngine.play(this.click, false, 1); if (this.gridScript.isInPlayAni) { return } if (this.eliminateOneNum > 0){ // this.eliminateOneNum--; this.isCrushOne = true; const msg = this.skillTip.getChildByName("msg"); msg.getComponent(cc.Label).string = "选择一个需要消除的块" this.showSkillTip(true); }else { Toast("道具已用完") } }, //步数暂停 onStepPause(){ cc.audioEngine.play(this.click, false, 1); if (this.gridScript.isInPlayAni) { return }; if (this.stepPauseNum > 0){ this.stepPauseNum--; this.isStepPause = true; const msg = this.skillTip.getChildByName("msg"); msg.getComponent(cc.Label).string = "步数暂停中"; this.showSkillTip(true); }else { Toast("道具已用完") } }, //刷新 onRefresh(){ cc.audioEngine.play(this.click, false, 1); if (this.gridScript.isInPlayAni) { return }; if (this.refreshNum > 0){ this.refreshNum--; this.grid.children.forEach(item => { if (item.name != "bg"){ item.destroy(); } }) this.gameModel = new GameModel(); // this.gameModel.init(this.initTypeNum); this.gameModel.init(4); this.gridScript = this.grid.getComponent("GridView"); this.gridScript.setController(this); // console.log("this:",this) this.gridScript.initWithCellModels(this.gameModel.getCells()); // console.log(this.refreshNum) }else { Toast("刷新次数已用完") } }, showSkillTip(isShow){ // console.log("isShow:",isShow) this.skillTip.active = isShow; }, //道具消除整行 onSkillRowAll(){ // console.log("点击了消除整行按钮") cc.audioEngine.play(this.click, false, 1); if (this.gridScript.isInPlayAni) { return } if (this.crushRowAllNum > 0){ // this.crushRowAllNum--; this.isCrushRow = true; const msg = this.skillTip.getChildByName("msg"); msg.getComponent(cc.Label).string = "选择需要删除的行"; this.showSkillTip(true); }else { Toast("道具已用完") } }, //道具消除整列 onSkillColAll(){ // console.log("点击了消除整列") cc.audioEngine.play(this.click, false, 1); //增加点击音效 if (this.gridScript.isInPlayAni) { return } if (this.crushColAllNum > 0){ // this.crushColAllNum--; this.isCrushCol = true; const msg = this.skillTip.getChildByName("msg"); msg.getComponent(cc.Label).string = "选择需要删除的列"; this.showSkillTip(true); }else { Toast("道具已用完") } }, //道具消除一种类型 onSkillOneType(){ cc.audioEngine.play(this.click, false, 1); if (this.gridScript.isInPlayAni) { return } if (this.crushOneTypeNum > 0){ // this.crushOneTypeNum--; this.isCrushOneType = true; const msg = this.skillTip.getChildByName("msg"); msg.getComponent(cc.Label).string = "选择需要删除的类型"; this.showSkillTip(true); }else { Toast("道具已用完") } } }); /** * 组件脚本: * AudioUtils.js、CellView.js、EffectLayer.js、GameController.js、GridView.js、LoginController.js * */