GamePlay.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817
  1. import CellItem from "./view/uiItem/CellItem";
  2. import PoolMgr, { NODEPOOLPREFABTYPE } from "./mgr/PoolMgr";
  3. import GameConst from "./data/GameConst";
  4. import GameLogic from "./util/GameLogic";
  5. import BonusTip from "./view/effect/BonusTip";
  6. import EffectMgr, { TIP_SPRITEITEM_TYPE } from "./mgr/EffectMgr";
  7. import { DataEventId, EVENT_TYPE, GameProp, VideoAdType } from "../game/data/GameData";
  8. import JsbSystem from "../mk/system/JsbSystem";
  9. import Util from "./util/Util";
  10. import { AdFun } from "../game/data/AdData";
  11. const { ccclass, property } = cc._decorator;
  12. @ccclass
  13. export default class GamePlay extends cc.Component {
  14. /**单例模式 */
  15. public static Inst: GamePlay = null;
  16. @property(cc.Label)
  17. label_level: cc.Label = null;
  18. /**内容 */
  19. @property(cc.Node)
  20. node_content: cc.Node = null;
  21. /**cell背景块 */
  22. @property(cc.Node)
  23. node_cellBg: cc.Node = null;
  24. /**进度条UI */
  25. @property(cc.Node)
  26. node_progressUI: cc.Node = null;
  27. @property(cc.Sprite)
  28. spr_progress: cc.Sprite = null;
  29. /**特效UI */
  30. @property(cc.Node)
  31. node_effectUI: cc.Node = null;
  32. /** 是否开启关卡红包 */
  33. public ifOpenLevelRedBag: boolean = false;
  34. /**当前进度得分 */
  35. public curProgressScore: number = 0;
  36. /**当前得分 */
  37. public curGetScore: number = 0;
  38. /**目标分数 */
  39. public targetScore: number = 0;
  40. /**最终得分 */
  41. public finalGetScore: number = 0;
  42. /**增加得分速度 */
  43. public addScoreSpeed: number = 4;
  44. public curTotalScore: number = 0;
  45. /**消消的方块数组
  46. * @param:key index_x
  47. * @param: value 整个纵列数组
  48. */
  49. public cellItemDic: { [key: number]: CellItem[] } = {};
  50. public cellItemArr: CellItem[] = [];
  51. /**清理CellItem的Vec数组 */
  52. public cleanedVecArr: cc.Vec2[] = [];
  53. /**能够清理的vecArr组 */
  54. public couldCleanVecArr: cc.Vec2[] = [];
  55. /**清理纵列的x */
  56. public cleanXIndexArr: number[] = [];
  57. /**所有的清理 */
  58. public allCleanedXArr: number[] = [];
  59. /**剩余未移除的xIndex */
  60. public leftXIndexArr: number[] = [];
  61. /**当前选择的cellItem */
  62. public curSelectCellItem: CellItem = null;
  63. /**当前点击得cellItem */
  64. public curClickCellItem: CellItem = null;
  65. /**当前选择的道具按钮 */
  66. public curSelectPropBtn: cc.Node = null;
  67. /**是否可以点击 */
  68. public ifCouldClick: boolean = true;
  69. /**是否已经通关 */
  70. public ifPass: boolean = false;
  71. /**是否获取后台回调 */
  72. public ifGetPass: boolean = false;
  73. /**是否打开积分红包 */
  74. public ifOpenScoreRedPacket: boolean = false;
  75. onLoad() {
  76. GamePlay.Inst = this;
  77. mk.event.register("event_guide", this.clickGuide, this);
  78. this.checkLevelRedBagSwitch();
  79. }
  80. private clickGuide(data: string) {
  81. if (data == "1_3") {//点击即可消除哦!
  82. this.cellItemDic[0][0] && this.cellItemDic[0][0].onClick();
  83. }
  84. else if (data == "1_5") {//再点击一次增加大量进度哦
  85. this.cellItemDic[1][1] && this.cellItemDic[1][1].onClick();
  86. }
  87. }
  88. public start() {
  89. GameConst.loadConfig().then(() => {
  90. // mk.audio.playMusic("music_gameBg");
  91. //读取在线分数数据
  92. this.curTotalScore = 0;
  93. let score = this.curTotalScore;
  94. this.curGetScore = score;
  95. this.curProgressScore = score;
  96. this.finalGetScore = score;
  97. console.log("score", score);
  98. this.initView();
  99. this.intervalShowGuide();
  100. }).catch();
  101. }
  102. onDisable() {
  103. //退出游戏归置下道具状态
  104. if (this.curSelectCellItem) {
  105. this.curSelectCellItem.normal();
  106. }
  107. }
  108. /** [FC][V2.0.1]检测关卡红包开关 */
  109. checkLevelRedBagSwitch() {
  110. // let levelRedBagSwitch = gData.gameData.configs.GlobalCfg.levelRedBagSwitch;
  111. let levelRedBagSwitch = false;
  112. if (levelRedBagSwitch) {
  113. this.ifOpenLevelRedBag = levelRedBagSwitch == 0 ? false : true;
  114. }
  115. else {
  116. this.ifOpenLevelRedBag = false;
  117. }
  118. }
  119. async update(dt) {
  120. if (this.curProgressScore >= this.curGetScore) {
  121. if (this.curProgressScore == 0) {
  122. this.spr_progress.fillRange = 0;
  123. }
  124. return;
  125. }
  126. else {
  127. if (this.curProgressScore >= this.targetScore) {
  128. this.curProgressScore = this.curGetScore;
  129. this.initScore();
  130. }
  131. else {
  132. let nextProgressScore: number = this.curProgressScore + this.addScoreSpeed;
  133. if (/**this.curProgressScore < GamePlay.Inst.targetScore && */nextProgressScore >= GamePlay.Inst.targetScore) {
  134. let node_getTargetScoreTip = await PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.GetTargetScoreTip);
  135. GamePlay.Inst.node_effectUI.addChild(node_getTargetScoreTip);
  136. //进度到达开始显示(挪到initScore判断)
  137. // gData.reward.subType = 2;
  138. // mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
  139. // mk.ui.openPanel("module/reward/rewardLuck");
  140. }
  141. this.curProgressScore = nextProgressScore;
  142. if (this.curProgressScore >= this.curGetScore) {
  143. this.curProgressScore = this.curGetScore;
  144. }
  145. this.initScore();
  146. }
  147. }
  148. }
  149. lateUpdate() {
  150. gData.gameData.init_head = false;
  151. }
  152. /**初始化视图 */
  153. initView() {
  154. this.initLevel();
  155. this.initTotalScore();
  156. this.initScore();
  157. this.initProgress();
  158. this.initCellBg();
  159. this.initCell();
  160. }
  161. /**初始化关卡数目 */
  162. initLevel() {
  163. mk.console.log("[Game] levelNum", gData.gameData.getProp(GameProp.levelNum));
  164. let level = gData.gameData.getProp(GameProp.levelNum);
  165. if (level == undefined) {
  166. level = 0;
  167. gData.gameData.setProp(GameProp.levelNum, level);
  168. }
  169. this.label_level.string = `第${level + 1}关`
  170. }
  171. /**初始化总分数 */
  172. initTotalScore() {
  173. if (this.targetScore) {
  174. return;
  175. }
  176. let level = gData.gameData.getProp(GameProp.levelNum);
  177. //加入一些随机值,而不是都能获得过关红包
  178. this.targetScore = 450 + level * (5 + Math.floor(Math.random() * 15));
  179. // //测试切换
  180. // this.targetScore = 5000;
  181. this.addScoreSpeed = Math.floor(this.targetScore / 200) * 2 + 4;
  182. mk.console.log("this.addScoreSpeed", this.addScoreSpeed);
  183. }
  184. /**初始化得分 */
  185. initScore() {
  186. this.initProgress();
  187. }
  188. /**初始化进度 */
  189. initProgress() {
  190. let progress = this.curProgressScore / this.targetScore;
  191. progress = progress > 1 ? 1 : progress;
  192. this.spr_progress.fillRange = progress;
  193. // if (progress >= 1) {
  194. // let level = gData.gameData.getProp(GameProp.levelNum);
  195. // //如果未开启关卡红包
  196. // if (level <= 0 || !this.ifOpenLevelRedBag) {
  197. // //进度到达开始显示
  198. // gData.reward.subType = 2;
  199. // mk.ad.videoAdType = VideoAdType.LevelScoreRedBag;
  200. // let node_rewardLuck = mk.ui.getCurOnPanel("rewardLuck");
  201. // if (!node_rewardLuck && gData.gameData.funOpenData['6'] == '1') {
  202. // mk.ui.openPanel("module/reward/rewardLuck");
  203. // }
  204. // }
  205. // }
  206. }
  207. /**初始化cellBg */
  208. async initCellBg() {
  209. for (var i = 0; i < GameConst.col_num; i++) {
  210. for (var j = 0; j < GameConst.row_num; j++) {
  211. let node_cellBg = await PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellBg);
  212. // LogUtil.log("prefab_cellBg", prefab_cellBg);
  213. // let node_cellBg = cc.instantiate(prefab_cellBg);
  214. this.node_cellBg.addChild(node_cellBg);
  215. }
  216. }
  217. }
  218. /**初始化cell */
  219. public async initCell() {
  220. //关卡配置从100关开始随机关卡50-99
  221. let level = gData.gameData.getProp(GameProp.levelNum);
  222. let levelIndex = 0;
  223. if (level <= GameConst.configCount - 1) {
  224. levelIndex = level;
  225. }
  226. else {
  227. levelIndex = Util.rnd(50, GameConst.configCount - 1);
  228. }
  229. GameConst.curLevelCfg = GameConst.config_level[levelIndex];
  230. this.addCellItemFuc = async () => { await this.addCellItem(); };
  231. this.schedule(this.addCellItemFuc, 0.05);
  232. }
  233. public addCellItemFuc: Function = null;
  234. public curXIndex: number = 0;
  235. public curYIndex: number = 7;
  236. /**添加CellItem */
  237. public async addCellItem() {
  238. mk.console.log("addCellItem!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
  239. await this.addColCellItem();
  240. this.curXIndex++;
  241. if (this.curXIndex >= GameConst.col_num) {
  242. this.unschedule(this.addCellItemFuc);
  243. // this.getStartRedPacketCellItem();
  244. }
  245. }
  246. /**添加纵列的cellItem */
  247. public async addColCellItem() {
  248. this.cellItemDic[this.curXIndex] = [];
  249. for (var i = GameConst.row_num - 1; i >= 0; i--) {
  250. let node_prefab = await PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.CellItem);
  251. // let node_prefab = cc.instantiate(prefab_cellItem);
  252. let cellItem = node_prefab.getComponent(CellItem);
  253. cellItem.init(this.curXIndex, i);
  254. this.cellItemDic[this.curXIndex][i] = cellItem;
  255. this.cellItemArr.push(cellItem);
  256. this.node_content.addChild(node_prefab);
  257. }
  258. }
  259. /**点击分享 */
  260. public onClickShare() {
  261. if (!gData.loginData.isAuth) {
  262. // mk.tip.pop("请先点击头像,在设置界面授权");
  263. JsbSystem.WxAuth();
  264. return;
  265. }
  266. JsbSystem.sharePic();
  267. }
  268. // /** 点击关卡气泡红包 */
  269. // onClickLevelQiPaoPacket() {
  270. // mk.ad.videoAdType = VideoAdType.LevelQiPaoRedBag;
  271. // }
  272. // /**更改cellItem类型
  273. // * @param cellItemType
  274. // */
  275. // changeCellItemType(cellItemType: number) {
  276. // let pos_x = this.curSelectCellItem.node.x + GamePlay.Inst.node_content.x;
  277. // let pos_y = this.curSelectCellItem.node.y + GamePlay.Inst.node_content.y;
  278. // let node_change = PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.Change);
  279. // node_change.setPosition(pos_x, pos_y);
  280. // GamePlay.Inst.node_effectUI.addChild(node_change);
  281. // this.curSelectCellItem.setType(cellItemType)
  282. // mk.audio.playEffect("ef_change");
  283. // this.curSelectCellItem = null;
  284. // }
  285. //找到红包的那个水果
  286. /**
  287. * 获取红包cellItem
  288. */
  289. public getStartRedPacketCellItem() {
  290. let totalCellItemArr: CellItem[] = this.cellItemArr.concat();
  291. let largeCellItemVec: cc.Vec2[] = [];
  292. for (var i = 0; i < totalCellItemArr.length; i++) {
  293. let cellItem = totalCellItemArr[i];
  294. if (!!cellItem) {
  295. GameLogic.getCouldCleanVecList(cellItem.x, cellItem.y, cellItem.type, true);
  296. // console.log("this.couldCleanVecArr", this.couldCleanVecArr);
  297. console.log("largeCellItemVec.length", largeCellItemVec.length)
  298. if (largeCellItemVec.length < this.couldCleanVecArr.length) {
  299. largeCellItemVec = this.couldCleanVecArr;
  300. }
  301. this.couldCleanVecArr.forEach(element => {
  302. let index = GameConst.col_num * element.x + (GameConst.row_num - 1 - element.y);
  303. totalCellItemArr[index] = null;
  304. this.cellItemDic[element.x][element.y].ifRemoved = false;
  305. });
  306. this.couldCleanVecArr = [];
  307. }
  308. }
  309. console.log("FC------------------------------------------------------------");
  310. let random_index = mk.math.random(0, largeCellItemVec.length - 1);
  311. let vec = largeCellItemVec[random_index];
  312. let redPcaketCellItem: CellItem = this.cellItemDic[vec.x][vec.y];
  313. redPcaketCellItem.showRedPacket();
  314. return redPcaketCellItem;
  315. }
  316. //其他显示或逻辑项-------------------------------------------------------------------
  317. /**根据vecList清除cellItem */
  318. public cleanCellItemByVecList() {
  319. //没有可清清除
  320. if (GamePlay.Inst.cleanedVecArr.length <= 0) {
  321. //FC:+ 是否可以点击
  322. this.ifCouldClick = true;
  323. EffectMgr.Inst.addTip("点击两个或以上消除哦");
  324. return;
  325. }
  326. //区分消除音效
  327. if (GamePlay.Inst.cleanedVecArr.length >= 4) {
  328. mk.audio.playEffect("ef_eliminate_bonus");
  329. }
  330. else {
  331. mk.audio.playEffect("ef_eliminate");
  332. }
  333. mk.audio.playEffect("ef_fly");
  334. //同时消除
  335. for (var i = 0; i < GamePlay.Inst.cleanedVecArr.length; i++) {
  336. let vec = GamePlay.Inst.cleanedVecArr[i];
  337. //最后一个判定
  338. if (i == GamePlay.Inst.cleanedVecArr.length - 1) {
  339. this.checkBonusNum(GamePlay.Inst.cleanedVecArr.length);
  340. GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle(false, true);
  341. }
  342. else {
  343. GamePlay.Inst.cellItemDic[vec.x][vec.y].recycle();
  344. }
  345. if (this.cleanXIndexArr.indexOf(vec.x) == -1) {
  346. this.cleanXIndexArr.push(vec.x);
  347. }
  348. }
  349. this.cleanXIndexArr.sort();
  350. //计算下全部移除的
  351. this.allCleanedXArr = GameLogic.getAllCleanXIndex(this.cleanXIndexArr);
  352. //FC:移除完,检测下落
  353. this.scheduleOnce(() => {
  354. //检测下落
  355. this.checkMoveDownCellItem();
  356. }, 0.2)
  357. }
  358. /**检测向下移动的cellItem */
  359. checkMoveDownCellItem() {
  360. mk.console.log("this.cleanXIndexArr", this.cleanXIndexArr);
  361. for (var i = 0; i < this.cleanXIndexArr.length; i++) {
  362. let xIndex = this.cleanXIndexArr[i];
  363. this.moveYCellItem(xIndex);
  364. }
  365. }
  366. /**移动
  367. * @param xIndex 移除的纵列
  368. * @param removedYIndex 移除的横向index
  369. */
  370. public moveYCellItem(xIndex: number) {
  371. /**移动的次序(第几个移动的用来控制延迟移动的时间) */
  372. let movedIndex: number = 0;
  373. //移动位置间隔(比如前面两个空位就移动两格)
  374. let intervalNum: number = 0;
  375. /**是否是全部清理的x */
  376. let ifAllCleanedX: boolean = this.allCleanedXArr.indexOf(xIndex) != -1;
  377. /**是否是最后清理的x(全部清理完才开始左移) */
  378. let ifLastCleanX: boolean = (xIndex == this.cleanXIndexArr[this.cleanXIndexArr.length - 1]);
  379. let cellItemDic = GamePlay.Inst.cellItemDic[xIndex];
  380. //计算y方向移动的最后一位(这样只计算一次不用循环)
  381. let lastMoveCellItemY: number = null;
  382. let leftLastCellItemY: number = null;
  383. if (ifLastCleanX) {
  384. let lastCellItemArrSort = this.cleanedVecArr.filter((vec) => vec.x == xIndex).sort();
  385. lastMoveCellItemY = lastCellItemArrSort[0].y;
  386. // LogUtil.log("lastCellItemY", xIndex, lastMoveCellItemY, lastCellItemArrSort);
  387. for (var i = 0; i < GameConst.row_num; i++) {
  388. if (cellItemDic) {
  389. let cellItem = cellItemDic[i];
  390. if (cellItem) {
  391. leftLastCellItemY = cellItem.y;
  392. // LogUtil.log("leftLastCellItemY", leftLastCellItemY);
  393. break;
  394. }
  395. }
  396. }
  397. // let leftCellItemArrSort = this.cl
  398. }
  399. //如果最后一行 并且 是被全部清除的x
  400. if (ifLastCleanX && ifAllCleanedX) {
  401. // LogUtil.log("【checkMoveLeftCellItem】检测消除 全部消除的一列就是消除xIndex中最后一列");
  402. this.checkMoveLeftCellItem();
  403. return;
  404. }
  405. //y方向从下至上循环排查
  406. for (var i = GameConst.row_num - 1; i >= 0; i--) {
  407. if (cellItemDic) {
  408. let cellItem = cellItemDic[i];
  409. //该xIndex纵列没有全部移除
  410. if (cellItem) {
  411. if (ifLastCleanX && i == leftLastCellItemY) {
  412. // LogUtil.log("【checkMoveLeftCellItem】检测消除 移除了最后一个");
  413. cellItem.moveDown(xIndex, i + intervalNum, movedIndex, true);
  414. }
  415. else {
  416. cellItem.moveDown(xIndex, i + intervalNum, movedIndex);
  417. }
  418. movedIndex++;
  419. }
  420. else {
  421. intervalNum += 1;
  422. }
  423. }
  424. else {
  425. continue;
  426. }
  427. }
  428. }
  429. /**检测向左移动的cellItem */
  430. checkMoveLeftCellItem() {
  431. //计算消除的纵列中,有没有被全部移除
  432. //let allCleanedXArr = GameUtil.getAllCleanXIndex(this.cleanXIndexArr);
  433. // LogUtil.log("[Game] checkMoveLeftCellItem allCleanXArr ---------------------", this.allCleanedXArr);
  434. //如果没有全部移除得就return
  435. if (this.allCleanedXArr.length <= 0) {
  436. //LogUtil.log("【checkMoveLeftCellItem】检测是否能消除 没有全部移除的");
  437. GamePlay.Inst.ifCouldClick = true;
  438. GamePlay.Inst.checkIfEliminate();
  439. return;
  440. }
  441. //剩余一列未移除的xIndex
  442. let leftXIndexArr: number[] = GameLogic.getLeftXIndexArr();
  443. let leftMaxXIndex: number = leftXIndexArr[leftXIndexArr.length - 1];
  444. if (leftXIndexArr.length <= 0) {
  445. //检测是否移除
  446. this.checkIfEliminate();
  447. }
  448. else {
  449. mk.console.log("leftXIndexArr", leftXIndexArr);
  450. let intervalNum: number = 0;
  451. for (var i = 0; i < GameConst.col_num; i++) {
  452. let cellItemArr = GamePlay.Inst.cellItemDic[i];
  453. if (this.allCleanedXArr.indexOf(i) == -1) {
  454. //剩余存在的cellItem
  455. let leftCellItemArr = cellItemArr.filter((cellItem) => cellItem != null);
  456. if (intervalNum > 0) {
  457. for (var j = 0; j < cellItemArr.length; j++) {
  458. let cellItem = cellItemArr[j];
  459. if (cellItem) {
  460. if (i == leftMaxXIndex && j == (leftCellItemArr[0].y)) {
  461. mk.console.log("i,j,intervalNum", i, j, intervalNum);
  462. cellItem.moveLeft(i - intervalNum, j, true);
  463. }
  464. else {
  465. cellItem.moveLeft(i - intervalNum, j);
  466. }
  467. }
  468. }
  469. }
  470. else {
  471. //对应 1 2 3 列 中 3全部消除
  472. if (i == leftMaxXIndex) {
  473. GamePlay.Inst.ifCouldClick = true;
  474. GamePlay.Inst.checkIfEliminate();
  475. }
  476. }
  477. }
  478. else {
  479. intervalNum += 1;
  480. }
  481. }
  482. }
  483. }
  484. public timeout_pass: number = null;
  485. /**检测是否能移除 */
  486. checkIfEliminate() {
  487. mk.console.log("开始检测是否还能够消除!!!!!!!!!!!!!!!!!!!!!");
  488. //FC:替换
  489. GameLogic.getCouldCleanVec();
  490. if (this.couldCleanVecArr.length <= 0 && !this.ifPass) {
  491. EffectMgr.Inst.addSpriteTip(TIP_SPRITEITEM_TYPE.NormalPass);
  492. let timeOut = setTimeout(() => {
  493. this.pass();
  494. clearTimeout(timeOut);
  495. }, 1500);
  496. }
  497. }
  498. getCouldCleanCellItem() {
  499. for (var i = 0; this.cellItemArr.length; i++) {
  500. let cellItem = this.cellItemArr[i];
  501. let aroundSameType = GameLogic.getAroundSameType(cellItem.x, cellItem.y, cellItem.type, false);
  502. if (aroundSameType.length > 0) {
  503. return;
  504. }
  505. }
  506. //this.nextLevel();
  507. this.pass();
  508. //this.recycleAllCellItem();
  509. }
  510. /**restart
  511. * @param 是否扣除体力
  512. */
  513. restart() {
  514. mk.console.log("restart!!!!!!!!!!!!!!!")
  515. this.refreshGame();
  516. }
  517. /**下一关 */
  518. nextLevel() {
  519. mk.console.log("nextLevel!!!!!!!!!!!!!!!")
  520. this.targetScore = 0;//下一关才重置目标分数
  521. GamePlay.Inst.curProgressScore = 0;
  522. GamePlay.Inst.curGetScore = 0;
  523. GamePlay.Inst.finalGetScore = 0;
  524. GamePlay.Inst.initScore();
  525. this.refreshGame();
  526. let level = gData.gameData.getProp(GameProp.levelNum);
  527. // if (level % 5 == 0) {
  528. // mk.ad.showInterAd(1);
  529. // }
  530. mk.data.sendDataEvent('TapChapter', `${level}`);
  531. }
  532. /**刷新关卡 */
  533. refreshGame() {
  534. this.recycleAllCellItem();
  535. this.ifPass = false;
  536. this.ifGetPass = false;
  537. this.ifCouldClick = true;
  538. this.initLevel();
  539. this.initTotalScore();
  540. //FC:改成累分制而不是每关重置
  541. // this.curProgressScore = 0;
  542. // this.curGetScore = 0;
  543. // this.finalGetScore = 0;
  544. this.initScore();
  545. let level = gData.gameData.getProp(GameProp.levelNum);
  546. mk.data.setTAEventUser(0, 'level', level + 1);
  547. }
  548. /**回收所有的 */
  549. recycleAllCellItem() {
  550. for (var i = 0; i < GameConst.col_num; i++) {
  551. for (var j = 0; j < GameConst.row_num; j++) {
  552. let cellItem = this.cellItemDic[i][j];
  553. if (cellItem) {
  554. // mk.console.log("回收把>>>>>>>>>>>>>>>>>>>>>>");
  555. cellItem.recycle(true, false, false);
  556. }
  557. }
  558. }
  559. this.cellItemArr = [];
  560. this.cellItemDic = {};
  561. this.curXIndex = 0;
  562. this.curYIndex = GameConst.row_num - 1;
  563. this.initCell();
  564. }
  565. /**通关 */
  566. pass() {
  567. //这边会多次进入
  568. if (GamePlay.Inst.node.active == false || this.ifPass) {
  569. return;
  570. }
  571. this.ifPass = true;
  572. GamePlay.Inst.ifGetPass = false;
  573. let levelNum = gData.gameData.getProp(GameProp.levelNum);
  574. if (levelNum == 0) {
  575. mk.data.sendXYEvent("firstlevel", "完成第一关");
  576. }
  577. mk.console.log("[Game]pass passLevelNum", levelNum);
  578. GamePlay.Inst.ifGetPass = true;
  579. gData.gameData.setProp(GameProp.levelNum, ++levelNum);
  580. //游戏结算
  581. this.gameCount();
  582. // if (!this.ifOpenLevelRedBag) {
  583. // if (gData.gameData.funOpenData['6'] == '1') {
  584. // let node_rewardLuck = mk.ui.getCurOnPanel("rewardLuck");
  585. // if (node_rewardLuck || this.finalGetScore >= this.targetScore) {
  586. // return;
  587. // }
  588. // else {
  589. // //游戏结算
  590. // this.gameCount();
  591. // console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
  592. // }
  593. // }
  594. // else {
  595. // //游戏结算
  596. // this.gameCount();
  597. // console.log("gData.gameData.getProp(GameProp.levelNum)", gData.gameData.getProp(GameProp.levelNum));
  598. // }
  599. // }
  600. // else {
  601. // //游戏结算
  602. // this.gameCount();
  603. // }
  604. }
  605. /**游戏结算 */
  606. gameCount() {
  607. this.gameOver();
  608. }
  609. /**游戏结束 */
  610. gameOver() {
  611. mk.data.setTAEventUser(1, 'video_play_time', 1);
  612. if (mk.ui.getCurOnPanel('newOpenRedBag')) {
  613. console.log('没有弹通关红包');
  614. this.nextLevel();
  615. }
  616. else {
  617. mk.ad.videoAdType = VideoAdType.video_init_23;
  618. gData.adData.curRedBagAdFun = AdFun.settlement;
  619. mk.ui.openPanel('module/newOpenRedBag/newOpenRedBag');
  620. }
  621. }
  622. async checkBonusNum(cleanCellItemNum: number) {
  623. if (cleanCellItemNum >= 4) {
  624. let node_bonusTip = await PoolMgr.Inst.getPoolPrefab(NODEPOOLPREFABTYPE.BonusTip);
  625. let bonusTip = node_bonusTip.getComponent(BonusTip);
  626. //LogUtil.log("bonusTip",bonusTip);
  627. if (cleanCellItemNum == 4) {
  628. bonusTip.init(4);
  629. mk.audio.playEffect("ef_bonus4");
  630. }
  631. else if (cleanCellItemNum == 5) {
  632. bonusTip.init(5);
  633. mk.audio.playEffect("ef_bonus5");
  634. }
  635. else if (cleanCellItemNum == 6) {
  636. bonusTip.init(6);
  637. mk.audio.playEffect("ef_bonus6");
  638. }
  639. else if (cleanCellItemNum == 7) {
  640. bonusTip.init(7);
  641. mk.audio.playEffect("ef_bonus7");
  642. }
  643. else if (cleanCellItemNum == 8) {
  644. bonusTip.init(8);
  645. mk.audio.playEffect("ef_bonus8");
  646. }
  647. else {
  648. bonusTip.init(8);
  649. mk.audio.playEffect("ef_bonus8");
  650. }
  651. this.node_effectUI.addChild(node_bonusTip);
  652. }
  653. }
  654. public interval_ShowGuide: number = null;
  655. //间隔显示
  656. intervalShowGuide() {
  657. this.cancelShowCouldCleanCellItem();
  658. this.interval_ShowGuide = setInterval(() => {
  659. this.showCouldCleanCellItem();
  660. }, 10000);
  661. }
  662. /**显示 */
  663. showCouldCleanCellItem() {
  664. if (mk.ui.getCurOnPanel("RedPacketUI") || mk.ui.getCurOnPanel("GameOverUI") || !this.couldCleanVecArr || !this.cellItemDic) {
  665. return;
  666. }
  667. if (this.couldCleanVecArr.length <= 0) {
  668. GameLogic.getCouldCleanVec();
  669. }
  670. if (this.couldCleanVecArr.length > 0) {
  671. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  672. let vec = this.couldCleanVecArr[i];
  673. if (this.cellItemDic[vec.x]) {
  674. let cellItem = this.cellItemDic[vec.x][vec.y];
  675. if (cellItem) {
  676. cellItem.shake();
  677. }
  678. }
  679. else {
  680. }
  681. }
  682. }
  683. }
  684. /**取消显示 */
  685. cancelShowCouldCleanCellItem() {
  686. if (this.interval_ShowGuide) {
  687. clearInterval(this.interval_ShowGuide);
  688. this.interval_ShowGuide = null;
  689. if (this.couldCleanVecArr.length > 0) {
  690. for (var i = 0; i < this.couldCleanVecArr.length; i++) {
  691. let vec = this.couldCleanVecArr[i];
  692. let cellItem = this.cellItemDic[vec.x][vec.y];
  693. if (cellItem) {
  694. cellItem.normal();
  695. }
  696. }
  697. }
  698. this.couldCleanVecArr = [];
  699. }
  700. }
  701. }