| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909 |
- import CellItem from "./view/uiItem/CellItem";
- import PoolMgr, { NODEPOOLPREFABTYPE } from "./mgr/PoolMgr";
- import GameConst from "./data/GameConst";
- import GameLogic from "./util/GameLogic";
- import BonusTip from "./view/effect/BonusTip";
- import EffectMgr, { TIP_SPRITEITEM_TYPE } from "./mgr/EffectMgr";
- import { DataEventId, EVENT_TYPE, GameProp, VideoAdType } from "../game/data/GameData";
- import JsbSystem from "../mk/system/JsbSystem";
- import Util from "./util/Util";
- import { RedPoinNode } from "../game/game/Game";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export default class GamePlay extends cc.Component {
- /**单例模式 */
- public static Inst: GamePlay = null;
- /**背景 */
- @property(cc.Node)
- node_bg: cc.Node = null;
- @property({ type: cc.Sprite, displayName: "头像" })
- img_head: cc.Sprite = null;
- @property({ type: cc.Label, displayName: "红包币" })
- lbl_redMoney: cc.Label = null;
- @property({ type: cc.Sprite, displayName: "红包提现" })
- btn_cashOutNormal: cc.Sprite = null;
- @property(cc.Label)
- label_level: cc.Label = null;
- /**内容 */
- @property(cc.Node)
- node_content: cc.Node = null;
- /**cell背景块 */
- @property(cc.Node)
- node_cellBg: cc.Node = null;
- /**进度条UI */
- @property(cc.Node)
- node_progressUI: cc.Node = null;
- @property(cc.Sprite)
- spr_progress: cc.Sprite = null;
- /**特效UI */
- @property(cc.Node)
- node_effectUI: cc.Node = null;
- /**关卡红包UI */
- @property(cc.Node)
- node_levelRedPacketUI: cc.Node = null;
- @property({ type: cc.Node, displayName: "签到红点" })
- node_signRed: cc.Node = null;
- /** 是否开启关卡红包 */
- public ifOpenLevelRedBag: boolean = false;
- /**当前进度得分 */
- public curProgressScore: number = 0;
- /**当前得分 */
- public curGetScore: number = 0;
- /**目标分数 */
- public targetScore: number = 0;
- /**最终得分 */
- public finalGetScore: number = 0;
- /**增加得分速度 */
- public addScoreSpeed: number = 4;
- /**消消的方块数组
- * @param:key index_x
- * @param: value 整个纵列数组
- */
- public cellItemDic: { [key: number]: CellItem[] } = {};
- public cellItemArr: CellItem[] = [];
- /**清理CellItem的Vec数组 */
- public cleanedVecArr: cc.Vec2[] = [];
- /**能够清理的vecArr组 */
- public couldCleanVecArr: cc.Vec2[] = [];
- /**清理纵列的x */
- public cleanXIndexArr: number[] = [];
- /**所有的清理 */
- public allCleanedXArr: number[] = [];
- /**剩余未移除的xIndex */
- public leftXIndexArr: number[] = [];
- /**当前选择的cellItem */
- public curSelectCellItem: CellItem = null;
- /**当前点击得cellItem */
- public curClickCellItem: CellItem = null;
- /**当前选择的道具按钮 */
- public curSelectPropBtn: cc.Node = null;
- /**是否可以点击 */
- public ifCouldClick: boolean = true;
- /**是否已经通关 */
- public ifPass: boolean = false;
- /**是否获取后台回调 */
- public ifGetPass: boolean = false;
- /**是否打开积分红包 */
- public ifOpenScoreRedPacket: boolean = false;
- @property({ type: RedPoinNode, displayName: "红点组" })
- nodeRedPoint: RedPoinNode = null;
- onLoad() {
- GamePlay.Inst = this;
- mk.event.register("event_guide", this.clickGuide, this);
- this.checkLevelRedBagSwitch();
- }
- private async initHead() {
- let result = await mk.loader.loadRemote(gData.wechatData.avatar + "?aaa=aa.jpg", null);
- this.img_head.spriteFrame = new cc.SpriteFrame(result);
- }
- private initInfo() {
- this.lbl_redMoney.string = (gData.gameData.gameData.redMoney * 0.0001).toFixed(2) + '元';
- gData.gameData.init_coin = false;
- }
- private changeInfo() {
- this.lbl_redMoney.node.getComponent(mk.component.numberAnim).setValue(gData.gameData.gameData.redMoney * 0.0001, 2) + '元';
- gData.gameData.init_coin = false;
- }
- private clickGuide(data: string) {
- if (data == "1_3") {//点击即可消除哦!
- this.cellItemDic[0][0] && this.cellItemDic[0][0].onClick();
- }
- else if (data == "1_5") {//再点击一次增加大量进度哦
- this.cellItemDic[1][1] && this.cellItemDic[1][1].onClick();
- }
- }
- public start() {
- mk.data.sendDataEvent(DataEventId.level, "关卡开启");
- PoolMgr.Inst.initPoolPrefab();
- GameConst.loadConfig().then(() => {
- mk.audio.playMusic("music_gameBg");
- //读取在线分数数据
- gData.gameData.setProp(GameProp.curTotalScore, 0);//杀掉进程,则清零积分
- let score = gData.gameData.getProp(GameProp.curTotalScore);
- this.curGetScore = score;
- this.curProgressScore = score;
- this.finalGetScore = score;
- console.log("score", score);
- this.initView();
- this.initEvent();
- this.intervalShowGuide();
- }).catch();
- this.initInfo();
- let level = gData.gameData.getProp(GameProp.levelNum);
- mk.data.setTAEventUser(0, 'level', level + 1);
- this.schedule(this.firstShowBanner, 2)
- }
- firstShowBanner() {
- if (mk.ad.hasBannerReady()) {
- mk.ad.showBanner();
- this.unschedule(this.firstShowBanner)
- }
- }
- onDisable() {
- //退出游戏归置下道具状态
- if (this.curSelectCellItem) {
- this.curSelectCellItem.normal();
- }
- }
- /** [FC][V2.0.1]检测关卡红包开关 */
- checkLevelRedBagSwitch() {
- let levelRedBagSwitch = gData.gameData.configs.GlobalCfg.levelRedBagSwitch;
- if (levelRedBagSwitch) {
- this.ifOpenLevelRedBag = levelRedBagSwitch == 0 ? false : true;
- }
- else {
- this.ifOpenLevelRedBag = false;
- }
- }
- update(dt) {
- if (gData.gameData.init_coin) {
- this.changeInfo();
- }
- if (gData.gameData.init_head) {
- this.initHead();
- }
- if (gData.gameData.init_red_point) {
- this.initRedPoint();
- }
- if (this.curProgressScore >= this.curGetScore) {
- if (this.curProgressScore == 0) {
- this.spr_progress.fillRange = 0;
- }
- return;
- }
- else {
- if (this.curProgressScore >= this.targetScore) {
- this.curProgressScore = this.curGetScore;
- this.initScore();
- }
- else {
- let nextProgressScore: number = this.curProgressScore + this.addScoreSpeed;
- if (/**this.curProgressScore < GamePlay.Inst.targetScore && */nextProgressScore >= GamePlay.Inst.targetScore) {
- let node_getTargetScoreTip = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.GetTargetScoreTip);
- GamePlay.Inst.node_effectUI.addChild(node_getTargetScoreTip);
- //进度到达开始显示(挪到initScore判断)
- // gData.reward.subType = 2;
- // mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
- // mk.ui.openPanel("module/reward/rewardLuck");
- }
- this.curProgressScore = nextProgressScore;
- if (this.curProgressScore >= this.curGetScore) {
- this.curProgressScore = this.curGetScore;
- }
- this.initScore();
- }
- }
- }
- lateUpdate() {
- gData.gameData.init_head = false;
- }
- /**初始化视图 */
- initView() {
- this.initLevel();
- this.initTotalScore();
- this.initScore();
- this.initProgress();
- this.initCellBg();
- this.initCell();
- }
- /**初始化事件 */
- initEvent() {
- mk.event.register(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
- }
- /**初始化关卡数目 */
- initLevel() {
- mk.console.log("[Game] levelNum", gData.gameData.getProp(GameProp.levelNum));
- let level = gData.gameData.getProp(GameProp.levelNum);
- this.label_level.string = `第${level + 1}关`
- }
- /**初始化总分数 */
- initTotalScore() {
- if (this.targetScore) {
- return;
- }
- let level = gData.gameData.getProp(GameProp.levelNum);
- //加入一些随机值,而不是都能获得过关红包
- this.targetScore = 450 + level * (5 + Math.floor(Math.random() * 15));
- // //测试切换
- // this.targetScore = 5000;
- this.addScoreSpeed = Math.floor(this.targetScore / 200) * 2 + 4;
- mk.console.log("this.addScoreSpeed", this.addScoreSpeed);
- }
- /**初始化得分 */
- initScore() {
- this.initProgress();
- }
- /**初始化进度 */
- initProgress() {
- let progress = this.curProgressScore / this.targetScore;
- progress = progress > 1 ? 1 : progress;
- this.spr_progress.fillRange = progress;
- // if (progress >= 1) {
- // let level = gData.gameData.getProp(GameProp.levelNum);
- // //如果未开启关卡红包
- // if (level <= 0 || !this.ifOpenLevelRedBag) {
- // //进度到达开始显示
- // gData.reward.subType = 2;
- // mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
- // let node_rewardLuck = mk.ui.getCurOnPanel("rewardLuck");
- // if (!node_rewardLuck && gData.gameData.funOpenData['6'] == '1') {
- // mk.ui.openPanel("module/reward/rewardLuck");
- // }
- // }
- // }
- }
- /**初始化cellBg */
- initCellBg() {
- for (var i = 0; i < GameConst.col_num; i++) {
- for (var j = 0; j < GameConst.row_num; j++) {
- let prefab_cellBg = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellBg);
- // LogUtil.log("prefab_cellBg", prefab_cellBg);
- let node_cellBg = cc.instantiate(prefab_cellBg);
- this.node_cellBg.addChild(node_cellBg);
- }
- }
- }
- /**初始化cell */
- public initCell() {
- //关卡配置从100关开始随机关卡50-99
- let level = gData.gameData.getProp(GameProp.levelNum);
- let levelIndex = 0;
- if (level <= GameConst.configCount - 1) {
- levelIndex = level;
- }
- else {
- levelIndex = Util.rnd(50, GameConst.configCount - 1);
- }
- GameConst.curLevelCfg = GameConst.config_level[levelIndex];
- this.addCellItemFuc = () => { this.addCellItem(); };
- this.schedule(this.addCellItemFuc, 0.05);
- }
- public addCellItemFuc: Function = null;
- public curXIndex: number = 0;
- public curYIndex: number = 7;
- /**添加CellItem */
- public addCellItem() {
- mk.console.log("addCellItem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- this.addColCellItem();
- this.curXIndex++;
- if (this.curXIndex >= GameConst.col_num) {
- this.unschedule(this.addCellItemFuc);
- // this.getStartRedPacketCellItem();
- }
- }
- /**添加纵列的cellItem */
- public addColCellItem() {
- this.cellItemDic[this.curXIndex] = [];
- for (var i = GameConst.row_num - 1; i >= 0; i--) {
- let prefab_cellItem = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellItem);
- let node_prefab = cc.instantiate(prefab_cellItem);
- let cellItem = node_prefab.getComponent(CellItem);
- cellItem.init(this.curXIndex, i);
- this.cellItemDic[this.curXIndex][i] = cellItem;
- this.cellItemArr.push(cellItem);
- this.node_content.addChild(node_prefab);
- }
- }
- /**点击分享 */
- public onClickShare() {
- if (!gData.loginData.isAuth) {
- // mk.tip.pop("请先点击头像,在设置界面授权");
- JsbSystem.WxAuth();
- return;
- }
- JsbSystem.sharePic();
- }
- // /** 点击关卡气泡红包 */
- // onClickLevelQiPaoPacket() {
- // mk.ad.videoAdType = VideoAdType.LevelQiPaoRedBag;
- // }
- // /**更改cellItem类型
- // * @param cellItemType
- // */
- // changeCellItemType(cellItemType: number) {
- // let pos_x = this.curSelectCellItem.node.x + GamePlay.Inst.node_content.x;
- // let pos_y = this.curSelectCellItem.node.y + GamePlay.Inst.node_content.y;
- // let node_change = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Change);
- // node_change.setPosition(pos_x, pos_y);
- // GamePlay.Inst.node_effectUI.addChild(node_change);
- // this.curSelectCellItem.setType(cellItemType)
- // mk.audio.playEffect("ef_change");
- // this.curSelectCellItem = null;
- // }
- //找到红包的那个水果
- /**
- * 获取红包cellItem
- */
- public getStartRedPacketCellItem() {
- let totalCellItemArr: CellItem[] = this.cellItemArr.concat();
- let largeCellItemVec: cc.Vec2[] = [];
- for (var i = 0; i < totalCellItemArr.length; i++) {
- let cellItem = totalCellItemArr[i];
- if (!!cellItem) {
- GameLogic.getCouldCleanVecList(cellItem.x, cellItem.y, cellItem.type, true);
- // console.log("this.couldCleanVecArr", this.couldCleanVecArr);
- console.log("largeCellItemVec.length", largeCellItemVec.length)
- if (largeCellItemVec.length < this.couldCleanVecArr.length) {
- largeCellItemVec = this.couldCleanVecArr;
- }
- this.couldCleanVecArr.forEach(element => {
- let index = GameConst.col_num * element.x + (GameConst.row_num - 1 - element.y);
- totalCellItemArr[index] = null;
- this.cellItemDic[element.x][element.y].ifRemoved = false;
- });
- this.couldCleanVecArr = [];
- }
- }
- console.log("FC------------------------------------------------------------");
- let random_index = mk.math.random(0, largeCellItemVec.length - 1);
- let vec = largeCellItemVec[random_index];
- let redPcaketCellItem: CellItem = this.cellItemDic[vec.x][vec.y];
- redPcaketCellItem.showRedPacket();
- return redPcaketCellItem;
- }
- //自定义事件---------------------------------------------------------------------
- /**微信授权返回 */
- onWxAuthBack() {
- if (this.node.active) {
- this.restart();
- //
- let node_redPacketUI = mk.ui.getCurOnPanel("RedPacketUI")
- if (node_redPacketUI) {
- mk.ui.closePanel("RedPacketUI");
- }
- }
- this.initLevel();
- this.initTotalScore();
- // this.initPropNum();
- mk.event.remove(EVENT_TYPE.BACK_WxAuth, this.onWxAuthBack, this);
- }
- //其他显示或逻辑项-------------------------------------------------------------------
- /**根据vecList清除cellItem */
- public cleanCellItemByVecList() {
- //没有可清清除
- if (GamePlay.Inst.cleanedVecArr.length <= 0) {
- //FC:+ 是否可以点击
- this.ifCouldClick = true;
- EffectMgr.Inst.addTip("点击两个或以上消除哦");
- return;
- }
- //区分消除音效
- if (GamePlay.Inst.cleanedVecArr.length >= 4) {
- mk.audio.playEffect("ef_eliminate_bonus");
- }
- else {
- mk.audio.playEffect("ef_eliminate");
- }
- mk.audio.playEffect("ef_fly");
- //同时消除
- for (var i = 0; i < GamePlay.Inst.cleanedVecArr.length; i++) {
- let vec = GamePlay.Inst.cleanedVecArr[i];
- //最后一个判定
- if (i == GamePlay.Inst.cleanedVecArr.length - 1) {
- this.checkBonusNum(GamePlay.Inst.cleanedVecArr.length);
- GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle(false, true);
- }
- else {
- GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle();
- }
- if (this.cleanXIndexArr.indexOf(vec.x) == -1) {
- this.cleanXIndexArr.push(vec.x);
- }
- }
- this.cleanXIndexArr.sort();
- //计算下全部移除的
- this.allCleanedXArr = GameLogic.getAllCleanXIndex(this.cleanXIndexArr);
- //FC:移除完,检测下落
- this.scheduleOnce(() => {
- //检测下落
- this.checkMoveDownCellItem();
- }, 0.2)
- }
- /**检测向下移动的cellItem */
- checkMoveDownCellItem() {
- mk.console.log("this.cleanXIndexArr", this.cleanXIndexArr);
- for (var i = 0; i < this.cleanXIndexArr.length; i++) {
- let xIndex = this.cleanXIndexArr[i];
- this.moveYCellItem(xIndex);
- }
- }
- /**移动
- * @param xIndex 移除的纵列
- * @param removedYIndex 移除的横向index
- */
- public moveYCellItem(xIndex: number) {
- /**移动的次序(第几个移动的用来控制延迟移动的时间) */
- let movedIndex: number = 0;
- //移动位置间隔(比如前面两个空位就移动两格)
- let intervalNum: number = 0;
- /**是否是全部清理的x */
- let ifAllCleanedX: boolean = this.allCleanedXArr.indexOf(xIndex) != -1;
- /**是否是最后清理的x(全部清理完才开始左移) */
- let ifLastCleanX: boolean = (xIndex == this.cleanXIndexArr[this.cleanXIndexArr.length - 1]);
- let cellItemDic = GamePlay.Inst.cellItemDic[xIndex];
- //计算y方向移动的最后一位(这样只计算一次不用循环)
- let lastMoveCellItemY: number = null;
- let leftLastCellItemY: number = null;
- if (ifLastCleanX) {
- let lastCellItemArrSort = this.cleanedVecArr.filter((vec) => vec.x == xIndex).sort();
- lastMoveCellItemY = lastCellItemArrSort[0].y;
- // LogUtil.log("lastCellItemY", xIndex, lastMoveCellItemY, lastCellItemArrSort);
- for (var i = 0; i < GameConst.row_num; i++) {
- if (cellItemDic) {
- let cellItem = cellItemDic[i];
- if (cellItem) {
- leftLastCellItemY = cellItem.y;
- // LogUtil.log("leftLastCellItemY", leftLastCellItemY);
- break;
- }
- }
- }
- // let leftCellItemArrSort = this.cl
- }
- //如果最后一行 并且 是被全部清除的x
- if (ifLastCleanX && ifAllCleanedX) {
- // LogUtil.log("【checkMoveLeftCellItem】检测消除 全部消除的一列就是消除xIndex中最后一列");
- this.checkMoveLeftCellItem();
- return;
- }
- //y方向从下至上循环排查
- for (var i = GameConst.row_num - 1; i >= 0; i--) {
- if (cellItemDic) {
- let cellItem = cellItemDic[i];
- //该xIndex纵列没有全部移除
- if (cellItem) {
- if (ifLastCleanX && i == leftLastCellItemY) {
- // LogUtil.log("【checkMoveLeftCellItem】检测消除 移除了最后一个");
- cellItem.moveDown(xIndex, i + intervalNum, movedIndex, true);
- }
- else {
- cellItem.moveDown(xIndex, i + intervalNum, movedIndex);
- }
- movedIndex++;
- }
- else {
- intervalNum += 1;
- }
- }
- else {
- continue;
- }
- }
- }
- /**检测向左移动的cellItem */
- checkMoveLeftCellItem() {
- //计算消除的纵列中,有没有被全部移除
- //let allCleanedXArr = GameUtil.getAllCleanXIndex(this.cleanXIndexArr);
- // LogUtil.log("[Game] checkMoveLeftCellItem allCleanXArr ---------------------", this.allCleanedXArr);
- //如果没有全部移除得就return
- if (this.allCleanedXArr.length <= 0) {
- //LogUtil.log("【checkMoveLeftCellItem】检测是否能消除 没有全部移除的");
- GamePlay.Inst.ifCouldClick = true;
- GamePlay.Inst.checkIfEliminate();
- return;
- }
- //剩余一列未移除的xIndex
- let leftXIndexArr: number[] = GameLogic.getLeftXIndexArr();
- let leftMaxXIndex: number = leftXIndexArr[leftXIndexArr.length - 1];
- if (leftXIndexArr.length <= 0) {
- //检测是否移除
- this.checkIfEliminate();
- }
- else {
- mk.console.log("leftXIndexArr", leftXIndexArr);
- let intervalNum: number = 0;
- for (var i = 0; i < GameConst.col_num; i++) {
- let cellItemArr = GamePlay.Inst.cellItemDic[i];
- if (this.allCleanedXArr.indexOf(i) == -1) {
- //剩余存在的cellItem
- let leftCellItemArr = cellItemArr.filter((cellItem) => cellItem != null);
- if (intervalNum > 0) {
- for (var j = 0; j < cellItemArr.length; j++) {
- let cellItem = cellItemArr[j];
- if (cellItem) {
- if (i == leftMaxXIndex && j == (leftCellItemArr[0].y)) {
- mk.console.log("i,j,intervalNum", i, j, intervalNum);
- cellItem.moveLeft(i - intervalNum, j, true);
- }
- else {
- cellItem.moveLeft(i - intervalNum, j);
- }
- }
- }
- }
- else {
- //对应 1 2 3 列 中 3全部消除
- if (i == leftMaxXIndex) {
- GamePlay.Inst.ifCouldClick = true;
- GamePlay.Inst.checkIfEliminate();
- }
- }
- }
- else {
- intervalNum += 1;
- }
- }
- }
- }
- public timeout_pass: number = null;
- /**检测是否能移除 */
- checkIfEliminate() {
- mk.console.log("开始检测是否还能够消除!!!!!!!!!!!!!!!!!!!!!");
- //FC:替换
- GameLogic.getCouldCleanVec();
- if (this.couldCleanVecArr.length <= 0 && !this.ifPass) {
- EffectMgr.Inst.addSpriteTip(TIP_SPRITEITEM_TYPE.NormalPass);
- let timeOut = setTimeout(() => {
- this.pass();
- clearTimeout(timeOut);
- }, 1500);
- }
- }
- getCouldCleanCellItem() {
- for (var i = 0; this.cellItemArr.length; i++) {
- let cellItem = this.cellItemArr[i];
- let aroundSameType = GameLogic.getAroundSameType(cellItem.x, cellItem.y, cellItem.type, false);
- if (aroundSameType.length > 0) {
- return;
- }
- }
- //this.nextLevel();
- this.pass();
- //this.recycleAllCellItem();
- }
- /**restart
- * @param 是否扣除体力
- */
- restart() {
- mk.console.log("restart!!!!!!!!!!!!!!!")
- this.refreshGame();
- }
- /**下一关 */
- nextLevel() {
- mk.console.log("nextLevel!!!!!!!!!!!!!!!")
- this.targetScore = 0;//下一关才重置目标分数
- this.refreshGame();
- let level = gData.gameData.getProp(GameProp.levelNum);
- if (level % 5 == 0) {
- mk.ad.showInterAd(1);
- }
- }
- /**刷新关卡 */
- refreshGame() {
- mk.data.sendDataEvent(DataEventId.level, "关卡开启");
- this.recycleAllCellItem();
- this.ifPass = false;
- this.ifGetPass = false;
- this.ifCouldClick = true;
- this.initLevel();
- this.initTotalScore();
- //FC:改成累分制而不是每关重置
- // this.curProgressScore = 0;
- // this.curGetScore = 0;
- // this.finalGetScore = 0;
- this.initScore();
- this.freshBanner();
- let level = gData.gameData.getProp(GameProp.levelNum);
- mk.data.setTAEventUser(0, 'level', level + 1);
- }
- /**回收所有的 */
- recycleAllCellItem() {
- for (var i = 0; i < GameConst.col_num; i++) {
- for (var j = 0; j < GameConst.row_num; j++) {
- let cellItem = this.cellItemDic[i][j];
- if (cellItem) {
- // mk.console.log("回收把>>>>>>>>>>>>>>>>>>>>>>");
- cellItem.recycle(true, false, false);
- }
- }
- }
- this.cellItemArr = [];
- this.cellItemDic = {};
- this.curXIndex = 0;
- this.curYIndex = GameConst.row_num - 1;
- this.initCell();
- }
- /**通关 */
- pass() {
- //这边会多次进入
- if (GamePlay.Inst.node.active == false || this.ifPass) {
- return;
- }
- mk.data.sendDataEvent(DataEventId.level, "关卡通关");
- this.ifPass = true;
- GamePlay.Inst.ifGetPass = false;
- let levelNum = gData.gameData.getProp(GameProp.levelNum);
- if (levelNum == 0) {
- mk.data.sendXYEvent("firstlevel", "完成第一关");
- }
- mk.console.log("[Game]pass passLevelNum", levelNum);
- GamePlay.Inst.ifGetPass = true;
- gData.gameData.setProp(GameProp.levelNum, ++levelNum);
- //游戏结算
- this.gameCount();
- // if (!this.ifOpenLevelRedBag) {
- // if (gData.gameData.funOpenData['6'] == '1') {
- // let node_rewardLuck = mk.ui.getCurOnPanel("rewardLuck");
- // if (node_rewardLuck || this.finalGetScore >= this.targetScore) {
- // return;
- // }
- // else {
- // //游戏结算
- // this.gameCount();
- // console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
- // }
- // }
- // else {
- // //游戏结算
- // this.gameCount();
- // console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
- // }
- // }
- // else {
- // //游戏结算
- // this.gameCount();
- // }
- }
- /**游戏结算 */
- gameCount() {
- this.gameOver();
- }
- /**游戏结束 */
- gameOver() {
- mk.data.setTAEventUser(1, 'video_play_time', 1);
- gData.reward.subType = 2;
- mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
- mk.ui.openPanel("module/reward/rewardMission");
- }
- checkBonusNum(cleanCellItemNum: number) {
- if (cleanCellItemNum >= 4) {
- let node_bonusTip = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.BonusTip);
- let bonusTip = node_bonusTip.getComponent(BonusTip);
- //LogUtil.log("bonusTip",bonusTip);
- if (cleanCellItemNum == 4) {
- bonusTip.init(4);
- mk.audio.playEffect("ef_bonus4");
- }
- else if (cleanCellItemNum == 5) {
- bonusTip.init(5);
- mk.audio.playEffect("ef_bonus5");
- }
- else if (cleanCellItemNum == 6) {
- bonusTip.init(6);
- mk.audio.playEffect("ef_bonus6");
- }
- else if (cleanCellItemNum == 7) {
- bonusTip.init(7);
- mk.audio.playEffect("ef_bonus7");
- }
- else if (cleanCellItemNum == 8) {
- bonusTip.init(8);
- mk.audio.playEffect("ef_bonus8");
- }
- else {
- bonusTip.init(8);
- mk.audio.playEffect("ef_bonus8");
- }
- this.node_effectUI.addChild(node_bonusTip);
- }
- }
- public interval_ShowGuide: number = null;
- //间隔显示
- intervalShowGuide() {
- this.cancelShowCouldCleanCellItem();
- this.interval_ShowGuide = setInterval(() => {
- this.showCouldCleanCellItem();
- }, 10000);
- }
- /**显示 */
- showCouldCleanCellItem() {
- if (mk.ui.getCurOnPanel("RedPacketUI") || mk.ui.getCurOnPanel("GameOverUI") || !this.couldCleanVecArr || !this.cellItemDic) {
- return;
- }
- if (this.couldCleanVecArr.length <= 0) {
- GameLogic.getCouldCleanVec();
- }
- if (this.couldCleanVecArr.length > 0) {
- for (var i = 0; i < this.couldCleanVecArr.length; i++) {
- let vec = this.couldCleanVecArr[i];
- if (this.cellItemDic[vec.x]) {
- let cellItem = this.cellItemDic[vec.x][vec.y];
- if (cellItem) {
- cellItem.shake();
- }
- }
- else {
- }
- }
- }
- }
- /**取消显示 */
- cancelShowCouldCleanCellItem() {
- if (this.interval_ShowGuide) {
- clearInterval(this.interval_ShowGuide);
- this.interval_ShowGuide = null;
- if (this.couldCleanVecArr.length > 0) {
- for (var i = 0; i < this.couldCleanVecArr.length; i++) {
- let vec = this.couldCleanVecArr[i];
- let cellItem = this.cellItemDic[vec.x][vec.y];
- if (cellItem) {
- cellItem.normal();
- }
- }
- }
- this.couldCleanVecArr = [];
- }
- }
- //刷新banner
- freshBanner() {
- mk.ad.destoryBanner();
- this.scheduleOnce(() => {
- mk.ad.showBanner();
- }, 1)
- }
- /**
- * 初始化红点
- */
- private initRedPoint() {
- this.nodeRedPoint.node_sign.active = gData.sign.redPoint();
- this.nodeRedPoint.node_redbagCash.active = gData.redBagCash.redPoint();
- gData.gameData.init_red_point = false;
- }
- }
|