ZY_StarManager.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188
  1. /**
  2. * 游戏核心部分
  3. */
  4. let GameEvent = require('GameEvent');
  5. var ZYGameTool = require('GameTool');
  6. let Blast = require('Blast');
  7. cc.Class({
  8. extends: require("ZY_GameLayer"),
  9. properties: {
  10. touchLayer: cc.Node,//触摸Layer
  11. clipDraw: cc.Node,//棋盘绘制节点
  12. clipDrawTemp: cc.Node,//棋盘绘制节点
  13. propNode: {
  14. tooltip: '道具',
  15. type: cc.Node,
  16. default: [],
  17. },
  18. leveNumLabel: cc.Label,//当前关卡
  19. targetScoreLabel: cc.Label,//目标分数
  20. scoreLabel: cc.Label,//当前分数
  21. coinNumLabel: cc.Label,//当前分数
  22. propTipNode: cc.Node,
  23. pauseBtn: cc.Node,
  24. gameEndLayer: cc.Prefab,
  25. gamePauseLayer: cc.Prefab,
  26. labelTip: cc.Prefab,
  27. maskLayer: cc.Prefab,
  28. bombSpine: cc.Prefab,
  29. scoreNum: cc.Prefab,
  30. helpNode: cc.Prefab,
  31. BLAST_PREFAB: {
  32. tooltip: '爆炸特效预制体',
  33. type: cc.Prefab,
  34. default: null,
  35. },
  36. topBg: cc.Node,
  37. },
  38. onLoad() {
  39. this.node.getChildByName("chessBg").scale = 0;
  40. },
  41. start() {
  42. this.setGameState(GameState.STATE_STOP);
  43. zy.stopBgMusic();
  44. this.clipDraw.active = false;
  45. this.schedule(this.dataUpdate, 0.1);
  46. this.init();
  47. this.initChess();
  48. this.initData();
  49. this.initTouchLayer();
  50. // this.retainScoreMotion(8, 10, 3.0); //奖励多少分
  51. this.node.runAction(cc.sequence(new cc.delayTime(0.9), cc.callFunc(function () {
  52. this.starDrop();
  53. }.bind(this))));
  54. // this.gameFaild();
  55. //游戏顶部全面屏适配
  56. this.node.runAction(cc.sequence(cc.delayTime(0.01), cc.callFunc(function () {
  57. if (WINSIZE.width / WINSIZE.height < 0.53) {
  58. this.topBg.parent.y -= 60;
  59. this.node.getChildByName("btnNode").y -= 60;
  60. }
  61. }.bind(this))));
  62. cc.game.on(cc.game.EVENT_HIDE, function () {
  63. console.log("游戏进入后台");
  64. gameLocalData.save(this);
  65. // this.onHideGame();//处理游戏切到后台时的事件
  66. }, this);
  67. cc.game.on(cc.game.EVENT_SHOW, function () {
  68. console.log("重新返回游戏");
  69. // this.onShowGame();//处理游戏切回前台时的事件
  70. }, this);
  71. },
  72. /**
  73. * 更新Label数据
  74. */
  75. dataUpdate: function () {
  76. this.leveNumLabel.string = this.getLevel().toString();
  77. this.targetScoreLabel.string = this.getTarget().toString();
  78. this.scoreLabel.string = this.getScore().toString();
  79. this.coinNumLabel.string = ZYGameTool.getInstance().getCoin().toString();
  80. },
  81. init: function () {
  82. this.BANER_HEIGHT = 150;
  83. heightoffest = this.BANER_HEIGHT + 10;
  84. console.log("--coinNum--: ", coinNum);
  85. this.coinNumLabel.string = coinNum.toString();
  86. this._guide = ZYGameTool.getInstance().getIntegerForKey(localDataItem.gameGuide, 1);
  87. this._guide = this._guide === 1 ? true : false;
  88. this._guidenumber=-1;
  89. if (this._guide){
  90. this.showHelpLayer();
  91. }
  92. this.initBtn();
  93. //棋盘背景动画
  94. this.node.getChildByName("chessBg").scaleY = 1;
  95. this.node.getChildByName("chessBg").runAction(cc.sequence(cc.delayTime(0.3), cc.scaleTo(0.5, 1)));
  96. this.initProp();
  97. },
  98. showHelpLayer:function(){
  99. var helpNode = cc.instantiate(this.helpNode);
  100. helpNode.parent = this.node;
  101. helpNode.zIndex = 1000;
  102. ZYGameTool.getInstance().setIntegerForKey(localDataItem.gameGuide, 0);
  103. Module.GameHelpLayer.setParam(false);
  104. },
  105. initBtn: function () {
  106. //暂停按钮
  107. this.pauseBtn.on('click', function (event) {
  108. this.pauseClick();
  109. }.bind(this));
  110. },
  111. pauseClick: function () {
  112. var pauseLayer = cc.instantiate(this.gamePauseLayer);
  113. pauseLayer.parent = this.node;
  114. pauseLayer.zIndex = 1000;
  115. this.node.runAction(cc.sequence(cc.delayTime(0.1), cc.callFunc(function () {
  116. gameLocalData.save(this);
  117. }.bind(this))));
  118. Module.GamePauseLayer.call(function (name) {
  119. if (name === "backGameBtn") {
  120. } else if (name === "restGameBtn") {
  121. this.clearData();
  122. gameLocalData.clear();
  123. this.clipDraw.removeAllChildren();
  124. this.initData();
  125. this.node.runAction(cc.sequence(new cc.delayTime(0.3), cc.callFunc(function () {
  126. this.starDrop();
  127. }.bind(this))));
  128. } else if (name === "backHomeBtn") {
  129. cc.director.loadScene("homeScene");
  130. }
  131. }.bind(this));
  132. },
  133. initProp: function () {
  134. // this.propTipNode.active = true;
  135. for (var i = 0; i < 2; i++) {
  136. this._propNode[i] = this.propNode[i];
  137. this._propmotion[i] = this.propNode[i].getChildByName("effect");
  138. this._proptipsp[i] = this.propTipNode.getChildByName("propTip" + (i + 1));
  139. }
  140. },
  141. initChess: function () {
  142. this.node.getChildByName("chessBg").y += heightoffest - 10;
  143. this.clipDraw.active = true;
  144. },
  145. /**
  146. * 恢复上次存档
  147. */
  148. setLastData: function () {
  149. gameLocalData.getSaveData();
  150. var lastdata = gameLocalData;
  151. if (lastdata._issaved) {
  152. this._firstsavein = true;
  153. this.setLevel(lastdata._level);
  154. this.setScore(lastdata._score);
  155. this.setTarget(lastdata._target);
  156. this._lastLevelScore = lastdata._lastscore;
  157. var chessinfo = lastdata._chesspad;
  158. console.log("--chessinfo--: ", chessinfo);
  159. for (var i = 0; i < STAR_WIDTH; i++)
  160. for (var j = 0; j < STAR_HEIGHT; j++) {
  161. if (parseInt(chessinfo[i * STAR_HEIGHT + j]) > 0) {
  162. this._chessInfo[i * STAR_HEIGHT + j] = parseInt(chessinfo[i * STAR_HEIGHT + j]);
  163. }
  164. }
  165. this.node.runAction(cc.sequence(cc.delayTime(1.5) , cc.callFunc(function () {
  166. this.handleHandle();
  167. }.bind(this))));
  168. }
  169. },
  170. /**
  171. * 初始化数据信息
  172. */
  173. initData: function () {
  174. this._candealwith = true;
  175. this.setLevel(1);
  176. this.setScore(0);
  177. this.setTarget(this.getTargetScoreByRound(1));
  178. this._lastLevelScore = 0;
  179. for (var i = 0; i < STAR_WIDTH; i++)
  180. for (var j = 0; j < STAR_HEIGHT; j++)
  181. this._chessInfo[i * STAR_HEIGHT + j] = 0;
  182. this._selectbox = [];
  183. this._eliminateNum = 0;
  184. this._eliminatePos = [];
  185. this.setLastData();
  186. },
  187. /**
  188. * 分数算法
  189. * @param level
  190. * @returns {number}
  191. */
  192. getTargetScoreByRound: function (level) {
  193. var targetscore = 0;
  194. if (level == 1)
  195. targetscore = 1000;
  196. else
  197. targetscore = 10 * level * level + 1950 * level - 1440;
  198. return targetscore;
  199. },
  200. /**
  201. * 设置游戏状态
  202. * @param state
  203. */
  204. setGameState: function (state) {
  205. this._gamestate = state;
  206. },
  207. /**
  208. * 生成棋盘
  209. */
  210. starDrop: function () {
  211. this.setGameState(GameState.STATE_STOP);
  212. this._max = this.getTarget() - this.score;
  213. cc.game.emit(GameEvent.EventType.GAME_PROGRESS, 0);
  214. //加限时道具
  215. if (!this._firstsavein ) {
  216. for (var i = 0; i < STAR_WIDTH; i++)
  217. for (var j = 0; j < STAR_HEIGHT; j++) {
  218. var color = zy.randNum(1, 5);
  219. this._chessInfo[i * STAR_HEIGHT + j] = color;
  220. }
  221. }
  222. var time = this.chessAppear(6);//zy.randNum(1, 6)
  223. console.log("time: " , time);
  224. this.node.runAction(new cc.sequence(new cc.delayTime(time), new cc.callFunc(function () {
  225. console.log("--this.getGameState-1: ", this.getGameState());
  226. this.setGameState(GameState.STATE_RUN);
  227. }.bind(this))));
  228. },
  229. /**
  230. * 棋盘出现特效
  231. * @param val 特效类型
  232. * @returns {number}
  233. */
  234. chessAppear: function (val) {
  235. var time = [0.1 * STAR_HEIGHT + 0.3, 0.4, 0.4, 1.1, 0.2, 0.3, 0.6, 0.02 * STAR_HEIGHT * STAR_WIDTH + 0.25];
  236. for (var i = 0; i < STAR_WIDTH; i++)
  237. for (var j = 0; j < STAR_HEIGHT; j++) {
  238. var id = this._chessInfo[i * STAR_HEIGHT + j];
  239. if (id > 0) {
  240. var box = zy.getSprite("game/star/starchess" + (id) + ".png");
  241. box.setScale(STAR_CHESS_SCALE);
  242. // this.clipDraw.addChild(box,CHESSMAN_LEVEL,(i*STAR_HEIGHT+j)+"");
  243. this.clipDraw.addChild(box, CHESSMAN_LEVEL, this.getBoxTag((i * STAR_HEIGHT + j)));
  244. var pos = this.chessPos(i, j);
  245. box.setPosition(cc.v2(pos.x, pos.y + STAR_HEIGHT * STAR_SIZE_WIDTH));
  246. // if((i*STAR_HEIGHT+j)==this._limitproptag){
  247. // box.setTexture(url_xmtg+ "res/animation/starpng/block_"+id+"_lb.png");
  248. // }
  249. if (val == 0) {
  250. box.setPosition(cc.v2(pos.x, pos.y + STAR_HEIGHT * STAR_SIZE_WIDTH));
  251. box.runAction(cc.sequence(cc.delayTime(j * 0.1 + zy.randNum(0, 9) * 0.01), cc.moveBy(0.2, cc.v2(0, -STAR_SIZE_WIDTH * STAR_HEIGHT))));
  252. } else if (val == 1) {
  253. box.setPosition(cc.v2(pos.x - STAR_WIDTH * STAR_SIZE_WIDTH, pos.y));
  254. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
  255. } else if (val == 2) {
  256. box.setPosition(cc.v2(pos.x + STAR_WIDTH * STAR_SIZE_WIDTH, pos.y));
  257. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
  258. } else if (val == 3) {
  259. box.setPosition(pos);
  260. box.opacity = 0;
  261. box.runAction(cc.sequence(cc.delayTime(0), cc.fadeIn(1.0)));
  262. } else if (val == 4) {
  263. if (i < STAR_WIDTH / 2.0) {
  264. box.setPosition(cc.v2(pos.x - (STAR_WIDTH * STAR_SIZE_WIDTH / 2.0), pos.y));
  265. } else {
  266. box.setPosition(cc.v2(pos.x + (STAR_WIDTH * STAR_SIZE_WIDTH / 2.0), pos.y));
  267. }
  268. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
  269. } else if (val == 5) {
  270. if (j < STAR_HEIGHT / 2.0) {
  271. box.setPosition(cc.v2(pos.x, pos.y - (STAR_HEIGHT * STAR_SIZE_WIDTH / 2.0)));
  272. } else {
  273. box.setPosition(cc.v2(pos.x, pos.y + (STAR_HEIGHT * STAR_SIZE_WIDTH / 2.0)));
  274. }
  275. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.4, pos)));
  276. } else if (val == 6) {
  277. var k = 1;
  278. if ((j % 2) == 0)
  279. k = -1;
  280. box.setPosition(cc.v2(pos.x + k * STAR_WIDTH * STAR_SIZE_WIDTH, pos.y));
  281. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.5, pos)));
  282. }
  283. }
  284. }
  285. return time[val];
  286. },
  287. chessPos: function (i, j) {
  288. return cc.v2(WINSIZE.width / 2.0 + (i + 0.5 - STAR_WIDTH / 2.0) * STAR_SIZE_WIDTH, heightoffest + (j + 0.5) * STAR_SIZE_WIDTH);
  289. },
  290. /**
  291. * 获取游戏状态
  292. * @returns {number}
  293. */
  294. getGameState: function () {
  295. return this._gamestate;
  296. },
  297. /**
  298. * 初始化监听层
  299. */
  300. initTouchLayer: function () {
  301. this.touchLayer.on(cc.Node.EventType.TOUCH_START, this.onTouchBegan.bind(this), this);
  302. this.touchLayer.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchMoved.bind(this), this);
  303. this.touchLayer.on(cc.Node.EventType.TOUCH_END, this.onTouchEnded.bind(this), this);
  304. this.touchLayer.on(cc.Node.EventType.TOUCH_CANCEL, this.onTouchEnded.bind(this), this);
  305. },
  306. txtTip: function (str) {
  307. var labelTip = cc.instantiate(this.labelTip);
  308. labelTip.parent = this.node;
  309. labelTip.scale = 0.7;
  310. labelTip.setPosition(cc.v2(0, 0));
  311. labelTip.getComponent(cc.Label).string = str.toString();
  312. labelTip.runAction(cc.sequence(cc.moveBy(0.5, cc.v2(0, WINSIZE.height / 2 - 50)), cc.delayTime(1.2), cc.removeSelf(true)));
  313. return labelTip;
  314. },
  315. /**
  316. * 开始监听
  317. * @param event
  318. * @returns {boolean}
  319. */
  320. onTouchBegan: function (event) {
  321. cc.log("onTouchBegan");
  322. console.log("--this.getGameState-2: ", this.getGameState());
  323. var position = event.getLocation();
  324. var target = this;
  325. if (target.getGameState() != GameState.STATE_RUN) {
  326. return false;
  327. }
  328. target._firstsavein = false;
  329. var k = target.propTouch(position);
  330. if (k > 0 && target._eliminateNum == 0) {
  331. if (PROPPRICE[k - 1] > coinNum) {
  332. this._selectprop = 0;
  333. this.txtTip("金币不足");
  334. return false;
  335. }
  336. target.propMotion(k);
  337. return true;
  338. }
  339. if (position.x >= 0 && position.x < WINSIZE.width && position.y >= heightoffest && position.y <= (heightoffest + STAR_SIZE_WIDTH * STAR_HEIGHT)) {
  340. var pos = target.chessPt(position);
  341. if (target._chessInfo[pos.x * STAR_HEIGHT + pos.y] && ZYGameTool.getInstance().posIndexOf(target._eliminatePos, pos) == -1) {
  342. // if (target._selectprop == 2) target._selectprop =4 ;
  343. var temp = true;
  344. var vec = [];
  345. if (target._selectprop == 1 || target._selectprop == 2) {
  346. temp = target.propProcess(target._selectprop - 1, pos);
  347. // if(target._guide){
  348. // target.removeChildByTag(TIPFONTTAG);
  349. // target._guidenumber++;
  350. // }
  351. } else if (target._selectprop == 0) {
  352. target.boxTip(pos, vec);
  353. }
  354. var selectnumber = vec.length;
  355. if (selectnumber > 1 || (target._selectprop > 0 && temp)) {
  356. target.endTip();
  357. var ft = 0.0;
  358. if (target._selectprop > 0) {
  359. // ELSGameLogic.getInstance().gameCount("item","prop_"+target._selectprop);
  360. }
  361. if (target._selectprop == 0) {
  362. target._eliminateNum++;
  363. target.boxEliminate(vec);
  364. ft = boxremovesingletime * selectnumber + cleardelaytime;
  365. } else if (target._selectprop == 1) {
  366. ft = boxremovesingletime + 0.9;
  367. } else if (target._selectprop == 2) {
  368. ft = target._selectbox.length * 0.15;
  369. target.useProps4(pos);
  370. }
  371. if (target._selectprop == 1 || target._selectprop == 2) {
  372. target.setGameState(GameState.STATE_STOP);
  373. target.node.runAction(cc.sequence(cc.delayTime(ft), cc.callFunc(function () {
  374. target.touchHandle();
  375. }.bind(target))));
  376. target._selectprop = 0;
  377. target._selectbox = [];
  378. }
  379. }
  380. }
  381. return true;
  382. }
  383. return false;
  384. },
  385. //获取道具坐标
  386. propTouch: function (pos) {
  387. for (var i = 0; i < 2; i++) {
  388. if (this._propNode[i].getBoundingBoxToWorld().contains(pos)) return i + 1;
  389. }
  390. return 0;
  391. },
  392. //获取道具位置
  393. getPropPos: function (key) {
  394. if (key > 0 && key < 2) {
  395. return this._propNode[key - 1].parent.convertToWorldSpaceAR(this._propNode[key - 1].getPosition());
  396. }
  397. return cc.v2(0, 0);
  398. },
  399. useProps4: function (pos) {
  400. var maskLayer = cc.instantiate(this.maskLayer);
  401. maskLayer.zIndex = 99;
  402. maskLayer.parent = this.node;
  403. this.clipDrawTemp.zIndex = 100;
  404. var tempk = this._selectbox[0];
  405. for (var i in this._selectbox) {
  406. if (this._selectbox[i].x == pos.x && this._selectbox[i].y == pos.y) {
  407. this._selectbox[i].x = tempk.x;
  408. this._selectbox[i].y = tempk.y;
  409. this._selectbox[0].x = pos.x;
  410. this._selectbox[0].y = pos.y;
  411. break;
  412. }
  413. }
  414. var selectbox = this._selectbox.slice(1, this._selectbox.length);
  415. selectbox.sort(function (a, b) {
  416. return Math.random() > 0.5 ? -1 : 1;
  417. });
  418. selectbox.splice(0, 0, this._selectbox[0]);
  419. var actions = [];
  420. for (var i = 0; i < selectbox.length; i++) {
  421. var key1 = selectbox[i];
  422. var node = this.getClipItem(key1.x * STAR_HEIGHT + key1.y);
  423. node.index = 101;
  424. actions.push(cc.callFunc(function (target, key) {
  425. this.addParticle(key);
  426. this.removeBox(key);
  427. }.bind(this), this, key1));
  428. if (i == selectbox.length - 1) {
  429. break;
  430. }
  431. var key2 = selectbox[i + 1];
  432. var position1 = this.chessPos(key1.x, key1.y);
  433. var position2 = this.chessPos(key2.x, key2.y);
  434. actions.push(cc.callFunc(function (target, data) {
  435. // var line=new cc.Sprite(starpng[wb.randNum(14,18)]);
  436. var line = zy.getSprite("game/prop/starprope" + zy.randNum(1, 5));
  437. line.setAnchorPoint(cc.v2(0, 0.5));
  438. var length = Math.sqrt(Math.abs(data.pos1.x - data.pos2.x) * Math.abs(data.pos1.x - data.pos2.x) + Math.abs(data.pos1.y - data.pos2.y) * Math.abs(data.pos1.y - data.pos2.y));
  439. var wid = 70;
  440. var lengthscale = length * 1.0 / wid;
  441. line.scaleX = 0.06 * lengthscale;
  442. cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, 1); //消除个数
  443. line.runAction(cc.sequence(cc.scaleTo(0.1, 1.0 * lengthscale, 1.5), cc.scaleTo(0.25, 1.0 * lengthscale, 0.06 * 1.5), cc.callFunc(function () {
  444. line.removeFromParent();
  445. })));
  446. line.setPosition(data.pos1);
  447. var angle1 = Math.atan2(data.pos2.y - data.pos1.y, data.pos2.x - data.pos1.x);
  448. var angle = -1 * cc.misc.radiansToDegrees(angle1);
  449. line.setRotation(angle);
  450. this.clipDrawTemp.addChild(line, 102);
  451. var score = this.getScoreByNum(1);
  452. this.updateScore(score);
  453. }.bind(this), this, {pos1: position1, pos2: position2}));
  454. actions.push(cc.delayTime(0.15));
  455. }
  456. actions.push(cc.callFunc(function () {
  457. maskLayer.removeFromParent();
  458. this.clipDrawTemp.removeAllChildren(true);
  459. this.showPropTip(0);
  460. }.bind(this)));
  461. this.node.runAction(cc.sequence(actions));
  462. },
  463. //使用道具
  464. propProcess: function (id, pos, key) {
  465. if (!pos) {
  466. pos = cc.v2(0, 0);
  467. }
  468. if (!key) {
  469. key = 1;
  470. }
  471. if (this._selectprop > 0) {
  472. this.showPropMotion(this._selectprop, 0);
  473. }
  474. //
  475. if (key == 1) {
  476. console.log("id: ", id);
  477. if (PROPPRICE[id] > coinNum) {
  478. this._selectprop = 0;
  479. this.txtTip();
  480. return false;
  481. } else {
  482. this.txtTip("使用道具,扣除金币 -" + PROPPRICE[id]);
  483. ZYGameTool.getInstance().useCoin(-PROPPRICE[id]);
  484. }
  485. }
  486. if (id == 1) {
  487. var key = this.getChessInfo(pos);
  488. console.log("---key--: ", key);
  489. for (var i = 0; i < STAR_WIDTH; i++)
  490. for (var j = 0; j < STAR_HEIGHT; j++) {
  491. if (key == this.getChessInfo(cc.v2(i, j))) {
  492. this._selectbox.push(cc.v2(i, j));
  493. }
  494. }
  495. } else if (id == 0) {
  496. // if(id==0){
  497. var ssp = zy.getSprite("game/prop/prop1");
  498. this.clipDraw.addChild(ssp, 1000);
  499. console.log("--this.getPropPos(1)--: ", this.getPropPos(1));
  500. ssp.setPosition(this.getPropPos(1));
  501. var v1 = ssp.getPosition();
  502. var tempv = this.chessPos(pos.x, pos.y);
  503. var v2 = cc.v2(tempv.x + 10, tempv.y - 10);
  504. var v3 = cc.v2(0, 0);
  505. if (v2.x < WINSIZE.width / 2)
  506. v3 = cc.v2(v1.x + 200, v1.y - 100);
  507. else
  508. v3 = cc.v2(v1.x + 200, v1.y + 100);
  509. var bezierpath = [v1, v3, v2];
  510. var bezier = cc.bezierTo(0.7, bezierpath);
  511. var bombSpine = this.createBombSpine(tempv, this.clipDraw);
  512. bombSpine.active = false;
  513. var bombAction = cc.callFunc(function () {
  514. bombSpine.active = true;
  515. });
  516. cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, 6); //消除个数
  517. ssp.runAction(cc.sequence(bezier, bombAction, cc.delayTime(0.2), cc.callFunc(function (target, tempv) {
  518. bombSpine.removeFromParent();
  519. ssp.removeFromParent();
  520. }.bind(this), this, tempv)));
  521. ssp.runAction(cc.scaleTo(0.15, 1.5));
  522. this.node.runAction(cc.sequence(cc.delayTime(0.7), cc.callFunc(function (target, pos) {
  523. this.node.runAction(cc.sequence(cc.delayTime(0.0), cc.callFunc(function (target, pos) {
  524. var temp = 0;
  525. for (var i = pos.x - 1; i <= pos.x + 1; i++){
  526. for (var j = pos.y - 1; j <= pos.y + 1; j++) {
  527. if (i >= 0 && i < STAR_WIDTH && j >= 0 && j < STAR_HEIGHT && this.getChessInfo(cc.v2(i, j))) {
  528. this.addParticle(cc.v2(i, j));
  529. this.removeBox(cc.v2(i, j));
  530. ++temp;
  531. }
  532. }
  533. }
  534. var score = this.getScoreByNum(temp);
  535. this.updateScore(score);
  536. }.bind(this), this, pos)));
  537. this.showPropTip(0);
  538. }.bind(this), this, pos)));
  539. }
  540. return true;
  541. },
  542. createBombSpine: function (pos, node, index) {
  543. if (index == undefined) index = 10000;
  544. var bombSpine = cc.instantiate(this.bombSpine);
  545. bombSpine.parent = node;
  546. bombSpine.zIndex = index;
  547. bombSpine.setPosition(pos);
  548. return bombSpine;
  549. },
  550. propMotion: function (k) {
  551. if (this._selectprop > 0) {
  552. this.showPropMotion(this._selectprop, 0);
  553. }
  554. cc.log("match touch began2", k);
  555. if (this._selectprop == k) {
  556. this._selectprop = 0;
  557. this.showPropTip(0);
  558. } else {
  559. this._selectprop = k;
  560. this.showPropTip(k);
  561. this.showPropMotion(k, 1);
  562. }
  563. },
  564. showPropTip: function (k) {
  565. if (k == 0) {
  566. this.propTipNode.active = false;
  567. } else if (k > 0 && k < 3) {
  568. this.propTipNode.active = true;
  569. for (var i = 0; i < 2; i++) {
  570. if (i == (k - 1)) {
  571. console.log("--showPropTip--");
  572. this._proptipsp[i].active = true;
  573. } else {
  574. this._proptipsp[i].active = false;
  575. }
  576. }
  577. }
  578. },
  579. //道具点击动画
  580. showPropMotion: function (key, type) {
  581. if (type == 1) {
  582. this._propmotion[key - 1].active = true;
  583. this._propmotion[key - 1].runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.0, 1.0),
  584. cc.scaleTo(1.0, 1.5))));
  585. this._propmotion[key - 1].runAction(cc.repeatForever(cc.sequence(cc.fadeIn(0.0),
  586. cc.fadeOut(1.0))));
  587. } else if (type == 0) {
  588. this._propmotion[key - 1].active = false;
  589. this._propmotion[key - 1].stopAllActions();
  590. this._propmotion[key - 1].setScale(1.0);
  591. this._propmotion[key - 1].opacity = 255;
  592. }
  593. },
  594. getScoreByNum: function (num) {
  595. var k = 5;
  596. var t = 5;
  597. for (var i = 0; i < num; i++) {
  598. k += t;
  599. t += 10;
  600. }
  601. return k;
  602. },
  603. updateScore: function (score) {
  604. this.score += score;
  605. },
  606. scoreMotion: function (score, pt) {
  607. var scoreNum = cc.instantiate(this.scoreNum);
  608. scoreNum.parent = this.clipDraw;
  609. scoreNum.zIndex = 10000;
  610. scoreNum.getComponent(cc.Label).string = score.toString();
  611. scoreNum.setPosition(this.chessPos(pt.x, pt.y));
  612. scoreNum.runAction(cc.sequence(cc.moveBy(1.0, cc.v2(0, STAR_SIZE_WIDTH)), cc.callFunc(function () {
  613. scoreNum.removeFromParent();
  614. })));
  615. },
  616. /**
  617. * 连消提示
  618. * @param vec
  619. */
  620. boxEliminate: function (vec) {
  621. var score = this.getScoreByNum(vec.length);
  622. this.updateScore(score);
  623. console.log("--score--: ", score);
  624. this.scoreMotion(score, vec[0]);
  625. if (this.getScore() >= this.getTarget() && (this.getScore() - score) < this.getTarget()) {
  626. this.spriteShow(zy_gxpng[0]);
  627. } else {
  628. if (vec.length == 5) {
  629. this.spriteShow("game/main_tip/great");
  630. } else if (vec.length > 5) {
  631. this.spriteShow("game/main_tip/zan");
  632. }
  633. }
  634. this.levelupmusic = 0;
  635. this.boxSequence(vec, true);
  636. var arrayOfActions = [];
  637. for (var i in vec) {
  638. if (i != "0") {
  639. arrayOfActions.push(cc.delayTime(boxremovesingletime));
  640. }
  641. var key = vec[i];
  642. arrayOfActions.push(cc.callFunc(function (target, data) {
  643. this.addParticle(data);
  644. this.removeBox(data);
  645. }.bind(this), this, key));
  646. }
  647. arrayOfActions.push(cc.delayTime(cleardelaytime));
  648. arrayOfActions.push(cc.callFunc(function () {
  649. this._eliminateNum--;
  650. if (this._eliminateNum == 0) {
  651. this._eliminatePos = [];
  652. this.setGameState(GameState.STATE_STOP);
  653. this.touchHandle();
  654. }
  655. }.bind(this)));
  656. this.node.runAction(cc.sequence(arrayOfActions));
  657. },
  658. spriteShow: function (str) {
  659. if (str == zy_gxpng[0]) {
  660. console.log("---chaoyue");
  661. var endpos = cc.v2(0, WINSIZE.height * Hkey - 180);
  662. var spr = zy.getSprite(str);
  663. this.node.addChild(spr, 1000, "777");
  664. spr.setPosition(cc.v2(0, 0 + heightoffest / 2.0));
  665. spr.runAction(cc.sequence(cc.fadeOut(0.08), cc.fadeIn(0.08), cc.fadeOut(0.08), cc.fadeIn(0.08), cc.fadeOut(0.08), cc.fadeIn(0.08),
  666. cc.scaleTo(0.2, 0.8), cc.delayTime(0.52), cc.moveTo(0.5, endpos)));
  667. spr.runAction(cc.sequence(new cc.delayTime(1.2), cc.scaleTo(0.5, 0.25), cc.callFunc(function () {
  668. spr.removeFromParent();
  669. var sp = zy.getSprite(str);
  670. sp.setScale(0.25);
  671. // this.getParent().getBackLayer().getChildByName("node").addChild(sp,10,777);
  672. this.node.addChild(spr, 12, "777");
  673. sp.setPosition(cc.v2(-170, -175));
  674. }.bind(this))));
  675. } else {
  676. this.spriteShow2(str, cc.v2(0, 0));
  677. }
  678. },
  679. spriteShow2: function (res, pos) {
  680. var sp = zy.getSprite(res);
  681. this.node.addChild(sp, 1000);
  682. sp.setPosition(pos);
  683. sp.setScale(1.0);
  684. if (res == "game/main_tip/xsyd") {
  685. sp.runAction(sequence(cc.moveBy(0.5, cc.v2(0, 50)),
  686. cc.delayTime(0.2), cc.fadeOut(0.3), cc.callFunc(function () {
  687. sp.removeFromParent();
  688. })));
  689. } else {
  690. sp.runAction(cc.sequence(cc.fadeOut(0.08), cc.fadeIn(0.08), cc.fadeOut(0.08), cc.fadeIn(0.08), cc.fadeOut(0.08), cc.fadeIn(0.08),
  691. cc.scaleTo(0.2, 0.8), cc.delayTime(0.2), cc.fadeOut(0.3), cc.callFunc(function () {
  692. sp.removeFromParent();
  693. })));
  694. }
  695. },
  696. /**
  697. * 可以消除的元素放入_eliminatePos
  698. * @param pos
  699. * @param vect
  700. */
  701. boxTip: function (pos, vect) {
  702. var vec = this.boxGet(pos);
  703. if (vec.length > 1) {
  704. for (var i in vec) {
  705. vect.push(vec[i]);
  706. this._eliminatePos.push(vec[i]);
  707. var box = this.getClipItem(vec[i].x * STAR_HEIGHT + vec[i].y);
  708. this.setBoxMotion(box, true);
  709. }
  710. }
  711. cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, vect.length); //消除个数
  712. },
  713. getClipItem: function (tag) {
  714. return this.clipDraw.getChildByName(tag.toString());
  715. },
  716. //TAG值转换为String类型
  717. getBoxTag: function getBoxTag(v) {
  718. return v.toString();
  719. },
  720. /**
  721. * 消除结束
  722. */
  723. endTip: function () {
  724. this._clicktiptime = 0;
  725. for (var i in this._clicktipvec) {
  726. var key = this._clicktipvec[i];
  727. var box = this.getClipItem(key.x * STAR_HEIGHT + key.y);
  728. this.setBoxMotion(box, false);
  729. }
  730. this._clicktipvec = [];
  731. },
  732. /**
  733. * 获取可以消除的元素
  734. * @param pos
  735. * @returns {[]}
  736. */
  737. boxGet: function (pos) {
  738. var vec = [];
  739. this.boxAdd(pos, vec);
  740. return vec;
  741. },
  742. /**
  743. * 树状搜索消除元素
  744. * @param pos
  745. * @param vec
  746. */
  747. boxAdd: function (pos, vec) {
  748. vec.push(pos);
  749. //x-1
  750. if ((pos.x - 1) >= 0 && ZYGameTool.getInstance().posIndexOf(vec, cc.v2(pos.x - 1, pos.y)) == -1 && (this.getChessInfo(pos) == this.getChessInfo(cc.v2(pos.x - 1, pos.y)))) {
  751. this.boxAdd(cc.v2(pos.x - 1, pos.y), vec);
  752. }
  753. //x+1
  754. if ((pos.x + 1) < STAR_WIDTH && ZYGameTool.getInstance().posIndexOf(vec, cc.v2(pos.x + 1, pos.y)) == -1 && (this.getChessInfo(pos) == this.getChessInfo(cc.v2(pos.x + 1, pos.y)))) {
  755. this.boxAdd(cc.v2(pos.x + 1, pos.y), vec);
  756. }
  757. //y-1
  758. if ((pos.y - 1) >= 0 && ZYGameTool.getInstance().posIndexOf(vec, cc.v2(pos.x, pos.y - 1)) == -1 && (this.getChessInfo(pos) == this.getChessInfo(cc.v2(pos.x, pos.y - 1)))) {
  759. this.boxAdd(cc.v2(pos.x, pos.y - 1), vec);
  760. }
  761. //y+1
  762. if ((pos.y + 1) < STAR_HEIGHT && ZYGameTool.getInstance().posIndexOf(vec, cc.v2(pos.x, pos.y + 1)) == -1 && (this.getChessInfo(pos) == this.getChessInfo(cc.v2(pos.x, pos.y + 1)))) {
  763. this.boxAdd(cc.v2(pos.x, pos.y + 1), vec);
  764. }
  765. },
  766. /**
  767. * 星星消除给个动作
  768. * @param box
  769. * @param b
  770. */
  771. setBoxMotion: function (box, b) {
  772. if (box) {
  773. if (b) {
  774. box.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(1.0, 0.89), cc.scaleTo(1.0, 1.0))));
  775. } else {
  776. box.stopAllActions();
  777. box.setScale(1.0);
  778. }
  779. }
  780. },
  781. /**
  782. * 通过坐标找到目标对象
  783. * @param pos
  784. * @returns {cc.Vec2}
  785. */
  786. chessPt: function (pos) {
  787. var x = parseInt((pos.x - WINSIZE.width / 2.0) / STAR_SIZE_WIDTH + STAR_WIDTH / 2.0);
  788. var y = parseInt((pos.y - heightoffest) / STAR_SIZE_WIDTH);
  789. return cc.v2(x, y);
  790. },
  791. touchHandle: function () {
  792. var time = 0.0;
  793. if (this.chessMove()) {
  794. time += chessmovetime;
  795. }
  796. this.node.runAction(cc.sequence(cc.delayTime(time), cc.callFunc(function () {
  797. if (this._candealwith) {
  798. this.handleHandle();
  799. }
  800. }.bind(this))));
  801. },
  802. handleHandle: function () {
  803. if (this.chessCanEliminate()) {
  804. console.log("--handleHandle--: ");
  805. this.setGameState(GameState.STATE_RUN);
  806. } else {
  807. this.node.runAction(cc.sequence(cc.delayTime(0.5), new cc.callFunc(function () {
  808. this.chessClear();
  809. }.bind(this))))
  810. }
  811. },
  812. chessClear: function () {
  813. var eliminatebox = [];
  814. for (var i = 0; i < STAR_WIDTH; i++)
  815. for (var j = 0; j < STAR_HEIGHT; j++) {
  816. if (this.getChessInfo(cc.v2(i, j))) {
  817. eliminatebox.push(cc.v2(i, j));
  818. }
  819. }
  820. if (eliminatebox.length > 0) {
  821. eliminatebox.sort(function (a, b) {
  822. return Math.random() > 0.5 ? -1 : 1;
  823. })
  824. }
  825. this.levelupmusic = 0;
  826. this.boxSequence(eliminatebox, false);
  827. var num = this.getRetainScore(eliminatebox.length);
  828. this.updateScore(num);
  829. // ELSGameData.getInstance().setDayHighScore(this._score,num);
  830. this.scoreMotion(num, cc.v2(WINSIZE.width / 2, WINSIZE.height / 2));
  831. // ELSGameLogic.getInstance().showHyRank(this._score,false);
  832. var ftime = this.smallPeopleCollect(eliminatebox);
  833. this.retainScoreMotion(eliminatebox.length, num, 3.0); //奖励多少分
  834. var ft = Math.max(ftime, 3);
  835. if (this.getScore() > this.getTarget() && (this.getScore() - num) < this.getTarget()) {
  836. this.spriteShow(zy_gxpng[0]);
  837. }
  838. this.node.runAction(cc.sequence(cc.delayTime(ft), new cc.callFunc(function () {
  839. this.gameEnd();
  840. }.bind(this))));
  841. },
  842. retainScoreMotion: function (number, score, ft) {
  843. var fnt1 = cc.instantiate(this.labelTip);
  844. fnt1.zIndex = 100;
  845. fnt1.parent = this.node;
  846. fnt1.getComponent(cc.Label).string = "奖励" + score + "分";
  847. fnt1.x = -(WINSIZE.width / 2 + 100);
  848. fnt1.y = heightoffest * 0.5;
  849. fnt1.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.2, cc.v2(0, heightoffest * 0.5))));
  850. var fnt2 = cc.instantiate(this.labelTip);
  851. fnt2.zIndex = 100;
  852. fnt2.parent = this.node;
  853. fnt2.getComponent(cc.Label).string = "剩余" + number + "颗糖果";
  854. fnt2.x = -(WINSIZE.width / 2 + 100);
  855. fnt2.y = heightoffest * 0.5 - 100;
  856. fnt2.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.2, cc.v2(0, heightoffest * 0.5 - 100)), cc.delayTime(ft - 0.2), cc.callFunc(function () {
  857. fnt1.removeFromParent();
  858. fnt2.removeFromParent();
  859. })));
  860. },
  861. /**
  862. * 游戏结束
  863. */
  864. gameEnd: function () {
  865. cc.game.emit(GameEvent.EventType.GAME_PASS_STAGE); //消除个数
  866. //闯关失败
  867. if (this.getScore() < this.getTarget()) {
  868. this.clearData();
  869. gameLocalData.clear();
  870. cc.director.loadScene("homeScene");
  871. } else {
  872. //闯关成功
  873. // this.LevelUpMotion();
  874. if (this.getScore() >= this.getTarget()) {
  875. this.spriteShow(zy_gxpng[0]);
  876. }
  877. this.setLevel(this.getLevel() + 1);
  878. this.setTarget(this.getTargetScoreByRound(this.getLevel()));
  879. this._lastLevelScore = this.getScore();
  880. this.node.runAction(cc.sequence(cc.delayTime(0.8), cc.callFunc(function () {
  881. this._firstsavein = false;
  882. this.starDrop();
  883. }.bind(this))));
  884. }
  885. },
  886. clearData: function () {
  887. this.score = 0;
  888. this._lastLevelScore = 0;
  889. this.level = 1;
  890. this.target = 0;
  891. this.hang = 0;
  892. this.chessInfo = [];//记录棋盘元素的颜色类型
  893. this._selectbox = [];
  894. this._eliminatePos = [];//消除
  895. this._eliminateNum = 0;
  896. this._clicktipvec = [];
  897. this._candealwith = true;
  898. this._limitproptag = -1;
  899. this._clicktiptime = 0;
  900. this._selectprop = 0;
  901. this.propNode = [];
  902. this._propmotion = [];
  903. this._proptipsp = [];
  904. },
  905. gameFaild: function () {
  906. var gameFaildNode = cc.instantiate(this.gameEndLayer);
  907. gameFaildNode.zIndex = 100;
  908. gameFaildNode.parent = this.node;
  909. Module.GameFaildLayer.call(function (state) {
  910. }.bind(this));
  911. },
  912. smallPeopleCollect: function (vec) {
  913. var tt = cleardelaytime;
  914. var action = [];
  915. for (var i in vec) {
  916. var pos = vec[i];
  917. action.push(cc.callFunc(function (target, pos) {
  918. this.addParticle(pos, 2);
  919. this.removeBox(pos, 1);
  920. }.bind(this), this, pos));
  921. action.push(cc.delayTime(boxremovesingletime));
  922. tt += boxremovesingletime;
  923. }
  924. if (action.length > 0) {
  925. this.node.runAction(cc.sequence(action));
  926. }
  927. return tt;
  928. },
  929. addParticle: function (pos, key) {
  930. if (!key)
  931. key = 1;
  932. if (key == 1)
  933. this.addFkLizi(this.clipDraw, this.chessPos(pos.x, pos.y), this.getChessInfo(pos) - 1, 1.0, 2);
  934. else
  935. this.addFkLizi(this.clipDraw, this.chessPos(pos.x, pos.y), 5, 1.0, 2);
  936. },
  937. removeBox: function (pos, tag) {
  938. if (!tag) {
  939. tag = 2;
  940. }
  941. var node = this.getClipItem(pos.x * STAR_HEIGHT + pos.y);
  942. if (node && node.isValid) node.removeFromParent();
  943. this.setChessInfo(pos, 0);
  944. this.levelupmusic++;
  945. },
  946. /**
  947. * 星星粒子特效
  948. * @param node
  949. * @param pos
  950. * @param idx
  951. * @param scale
  952. * @param type
  953. */
  954. addFkLizi: function (node, pos, idx, scale, type) {
  955. if (!type)
  956. type = 1;
  957. if (!scale)
  958. scale = 1.0;
  959. // var spname=chesspng[idx];
  960. var spname = "";
  961. if (type == 2) {
  962. if (idx == 5)
  963. spname = "game/lizi/starpar2";
  964. else
  965. spname = "game/lizi/starpar" + (3 + idx);
  966. } else if (type == 3) {
  967. spname = "game/lizi/starpar1";
  968. }
  969. if (idx == 5) {
  970. this.blast(5, pos, zy.randNum(0, 4));
  971. cc.game.emit(GameEvent.EventType.GAME_CLEAR_COUNT, 1); //消除个数
  972. } else {
  973. this.blast(5, pos, idx);
  974. }
  975. },
  976. blast(score, pos, index) {
  977. let node = Blast.pool.get();
  978. if (!node) {
  979. node = cc.instantiate(this.BLAST_PREFAB);
  980. }
  981. node.position = pos;
  982. node.getComponent(this.BLAST_PREFAB.name).run(score, index);
  983. node.zIndex = 100;
  984. // node.scale = this.node.scale;
  985. node.parent = this.clipDraw;
  986. },
  987. getRetainScore: function (number) {
  988. var score = 1500;
  989. for (var i = 1; i <= number; i++) {
  990. score -= 30 * i - 15;
  991. }
  992. if (score < 0)
  993. score = 0;
  994. return score;
  995. },
  996. boxSequence: function (vec, sx) {
  997. var k = vec.length;
  998. if (k > 0) {
  999. for (var i = 0; i < k; i++) {
  1000. for (var j = k - 1; j > i; j--) {
  1001. if (sx) {
  1002. if (this.getnum(vec[j]) < this.getnum(vec[j - 1])) {
  1003. var temp = vec[j];
  1004. vec[j] = vec[j - 1];
  1005. vec[j - 1] = temp;
  1006. }
  1007. } else {
  1008. if (this.getrenum(vec[j]) < this.getrenum(vec[j - 1])) {
  1009. var temp = vec[j];
  1010. vec[j] = vec[j - 1];
  1011. vec[j - 1] = temp;
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. },
  1018. getnum: function (pos) {
  1019. return pos.x * STAR_HEIGHT + pos.y;
  1020. },
  1021. getrenum: function (pos) {
  1022. return pos.x * STAR_HEIGHT + (STAR_HEIGHT - pos.y);
  1023. },
  1024. chessCanEliminate: function () {
  1025. for (var i = 0; i < STAR_WIDTH; i++)
  1026. for (var j = 0; j < STAR_HEIGHT; j++) {
  1027. if (this.singelCanEliminate(cc.v2(i, j))) {
  1028. return true;
  1029. }
  1030. }
  1031. return false;
  1032. },
  1033. chessMove: function () {
  1034. var temp = false;
  1035. var downstep = [];
  1036. var step = 0;
  1037. for (var i = 0; i < STAR_WIDTH; i++) {
  1038. step = 0;
  1039. for (var j = 0; j < STAR_HEIGHT; j++) {
  1040. if (this.getChessInfo(cc.v2(i, j)) == 0) {
  1041. step++;
  1042. } else if (step > 0) {
  1043. temp = true;
  1044. var box = this.getClipItem(i * STAR_HEIGHT + j);
  1045. if (box) {
  1046. box.runAction(cc.sequence(cc.delayTime(0), cc.moveTo(0.15, this.chessPos(i, j - step))));
  1047. // box.setTag(i*STAR_HEIGHT+(j-step));
  1048. box.name = this.getBoxTag(i * STAR_HEIGHT + (j - step));
  1049. if (i * STAR_HEIGHT + j == this._limitproptag) {
  1050. this._limitproptag = i * STAR_HEIGHT + (j - step);
  1051. }
  1052. this.setChessInfo(cc.v2(i, j - step), this.getChessInfo(cc.v2(i, j)));
  1053. this.setChessInfo(cc.v2(i, j), 0);
  1054. }
  1055. }
  1056. }
  1057. }
  1058. step = 0;
  1059. for (var i = 0; i < STAR_WIDTH; i++) {
  1060. if (this.getChessInfo(cc.v2(i, 0)) == 0) {
  1061. step++;
  1062. } else if (step > 0) {
  1063. for (var j = 0; j < STAR_HEIGHT; j++) {
  1064. if (this.getChessInfo(cc.v2(i, j))) {
  1065. temp = true;
  1066. var box = this.getClipItem(i * STAR_HEIGHT + j);
  1067. if (box) {
  1068. box.runAction(cc.sequence(new cc.delayTime(0.1), new cc.moveBy(0.05, cc.v2(-step * STAR_SIZE_WIDTH, 0))));
  1069. // box.setTag((i-step)*STAR_HEIGHT+j);
  1070. box.name = this.getBoxTag((i - step) * STAR_HEIGHT + j);
  1071. this.setChessInfo(cc.v2(i - step, j), this.getChessInfo(cc.v2(i, j)));
  1072. this.setChessInfo(cc.v2(i, j), 0);
  1073. if (i * STAR_HEIGHT + j == this._limitproptag) {
  1074. this._limitproptag = (i - step) * STAR_HEIGHT + j;
  1075. }
  1076. }
  1077. }
  1078. }
  1079. }
  1080. }
  1081. return temp;
  1082. },
  1083. hessCanEliminate: function () {
  1084. for (var i = 0; i < STAR_WIDTH; i++)
  1085. for (var j = 0; j < STAR_HEIGHT; j++) {
  1086. if (this.singelCanEliminate(cc.v2(i, j))) {
  1087. return true;
  1088. }
  1089. }
  1090. return false;
  1091. },
  1092. singelCanEliminate: function (pos) {
  1093. var i = pos.x;
  1094. var j = pos.y;
  1095. var key = this.getChessInfo(pos);
  1096. if (key > 0) {
  1097. if ((i - 1) >= 0 && key == this.getChessInfo(cc.v2(i - 1, j))) {
  1098. return true;
  1099. }
  1100. if ((i + 1) < STAR_WIDTH && key == this.getChessInfo(cc.v2(i + 1, j))) {
  1101. return true;
  1102. }
  1103. if ((j - 1) >= 0 && key == this.getChessInfo(cc.v2(i, j - 1))) {
  1104. return true;
  1105. }
  1106. if ((j + 1) < STAR_HEIGHT && key == this.getChessInfo(cc.v2(i, j + 1))) {
  1107. return true;
  1108. }
  1109. }
  1110. return false;
  1111. },
  1112. setChessInfo: function (pos, key) {
  1113. this._chessInfo[pos.x * STAR_HEIGHT + pos.y] = key;
  1114. },
  1115. getChessInfo: function (pos) {
  1116. return this._chessInfo[pos.x * STAR_HEIGHT + pos.y];
  1117. },
  1118. onTouchMoved: function (event) {
  1119. cc.log("onTouchMoved");
  1120. },
  1121. onTouchEnded: function (event) {
  1122. cc.log("onTouchEnded");
  1123. },
  1124. // update (dt) {},
  1125. onDestroy() {
  1126. //关闭所有音乐、音效
  1127. cc.audioEngine.stopAll();
  1128. //移除所有事件监听
  1129. cc.game.targetOff(this);
  1130. }
  1131. });