EliminateViewComp.ts 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487
  1. /*
  2. * @Author: mojunshou 1637302775@qq.com
  3. * @Date: 2025-03-20 15:01:09
  4. * @LastEditors: mojunshou 1637302775@qq.com
  5. * @LastEditTime: 2025-04-27 15:21:12
  6. * @Description: 消除游戏主场景
  7. */
  8. import { _decorator, Button, Color, EventTouch, instantiate, JsonAsset, v3, Label, Node, Prefab, randomRangeInt, Sprite, tween, UITransform, Vec2, Vec3, Widget } from "cc";
  9. import { oops } from "db://oops-framework/core/Oops";
  10. import { DeviceUtil } from "db://oops-framework/core/utils/DeviceUtil";
  11. import { ecs } from "db://oops-framework/libs/ecs/ECS";
  12. import { LabelChange } from "db://oops-framework/libs/gui/label/LabelChange";
  13. import { CCComp } from "db://oops-framework/module/common/CCComp";
  14. import { GameEvent } from "../common/config/GameEvent";
  15. import { UIID } from "../common/config/GameUIConfig";
  16. import { ServerHandler } from "../common/manager/ServerHandler";
  17. import { smc } from "../common/SingletonModuleComp";
  18. import { Format } from "../utils/Format";
  19. import { DCHandler } from "../common/manager/DCHandler";
  20. import { Tween } from "cc";
  21. import { AD_TYPE } from "../common/config/GameDefine";
  22. import { ADHandler } from "../common/manager/ADHandler";
  23. import { director } from "cc";
  24. const { ccclass, property } = _decorator;
  25. // 游戏状态枚举
  26. enum GameState {
  27. READY, // 准备中
  28. PLAYING, // 游戏中
  29. PAUSED, // 暂停 --进其他界面,广告暂停
  30. GAME_OVER, // 游戏结束
  31. GAME_PASS
  32. }
  33. // 格子状态
  34. enum CellState {
  35. EMPTY, // 空格子
  36. FILLED, // 有方块
  37. HIGHLIGHTED // 高亮(可放置)
  38. }
  39. //网格数据接口
  40. interface GridData {
  41. name: string, // 名称
  42. status: CellState, // 状态
  43. gridNode: Node | null // 网格节点
  44. row: number, // 行
  45. col: number, // 列
  46. type: number, // 类型--gridColorKey
  47. }
  48. interface Grids {
  49. row: number,
  50. column: number,
  51. }
  52. interface EditingData {
  53. brickData: BrickData | null,
  54. gridList: GridData[],
  55. }
  56. //底部方块数据定义
  57. interface BrickData {
  58. index: number,
  59. brickKey: string | null,
  60. rotateFlag: boolean,
  61. gridConfig: Grids[],
  62. deg: number,
  63. brickNode: Node | null,
  64. brickInitPos: Vec3, // 方块初始位置
  65. type: number, // 方块类型--gridColorKey
  66. rotateNode: Node | null,
  67. }
  68. interface GridConfigData {
  69. row: number,
  70. column: number,
  71. }
  72. /** 视图层对象 */
  73. @ccclass('EliminateViewComp')
  74. @ecs.register('EliminateView', false)
  75. export class EliminateViewComp extends CCComp {
  76. @property({ type: LabelChange, displayName: "自动提现金额" })
  77. private lab_wxCoin: LabelChange = null!;
  78. @property({ type: LabelChange, displayName: "额外奖励" })
  79. private lab_hbCoin: LabelChange = null!;
  80. @property({ type: Node, displayName: "tween微信钱Node" })
  81. private tweenWechatNode: Node = null!;
  82. @property({ type: Node, displayName: "tween红包Node" })
  83. private tweenRedNode: Node = null!;
  84. @property({ type: Prefab, displayName: "金币预制体" })
  85. private coinPrefab: Prefab = null!
  86. @property({ type: Prefab, displayName: "红包预制体" })
  87. private redPacketPrefab: Prefab = null!;
  88. @property({ type: Label, displayName: "本局分数" })
  89. private lab_score: Label = null!;
  90. @property({ type: Label, displayName: "目标分数" })
  91. private lab_taget: Label = null!;
  92. @property({ type: Prefab, displayName: "item预制体列表" })
  93. private itemPrefabs: Prefab[] = [];
  94. @property({ type: Node, displayName: "网格Node" })
  95. private gridNode: Node = null!;
  96. @property({ type: Node, displayName: "移动Node" })
  97. private moveNode: Node = null!;
  98. @property({ type: Node, displayName: "旋转Node" })
  99. private rotateNode: Node = null!;
  100. @property({ type: Node, displayName: "方块Node" })
  101. private brickNode: Node = null!;
  102. @property({ type: Prefab, displayName: "旋转预制体" })
  103. private rotatePrefab: Node = null!;
  104. @property({ type: Label, displayName: "累计消除次数" })
  105. private lab_total: Label = null!;
  106. @property({ type: Label, displayName: "每次放置添加的分数" })
  107. private lab_addScore: Label = null!;
  108. @property({ type: Node, displayName: "自动按钮节点" })
  109. private autoBtnNode: Node = null!;
  110. //二倍速按钮
  111. @property({ type: Button, displayName: "二倍速按钮" })
  112. private doubleSpeedBtn: Button = null!;
  113. @property({ type: Label, displayName: "第几块金砖" })
  114. private lab_goldNum: Label = null!;
  115. @property({ type: Label, displayName: "二倍速时间" })
  116. private lab_doubleTime: Label = null!;
  117. @property({ type: Node, displayName: "引导层" })
  118. private guideNode: Node = null!;
  119. @property({ type: Node, displayName: "引导item1" })
  120. private guideItem1: Node = null!;
  121. @property({ type: Node, displayName: "引导item2" })
  122. private guideItem2: Node = null!;
  123. @property({ type: Node, displayName: "引导item3" })
  124. private guideItem3: Node = null!;
  125. //引导手指
  126. @property({ type: Node, displayName: "引导手指" })
  127. private guideFinger: Node = null!;
  128. @property({ type: Node, displayName: "ComboNode" })
  129. private comboNode: Node = null!;
  130. @property({ type: Node, displayName: "自动放置Node拦截事件" })
  131. private autoNode: Node = null!;
  132. //游戏配置行列
  133. private rows: number = 8; // 行数
  134. private cols: number = 8; // 列数
  135. private itemSize: number = 76.25; // 格子大小
  136. private brickNum: number = 3; // 砖块数量
  137. private yOffset = 100;
  138. private aniBrickRotate = 0
  139. private operateFlag: boolean = false //是否可以操作
  140. private touchStartPos = new Vec2()
  141. private gameState: GameState = GameState.READY;
  142. private score: number = 0; //本局分数
  143. private money: number = 0; //左边金钱
  144. private cash: number = 0; //右边红包钱数
  145. private targetScore: number = 0; //目标分数
  146. private isDoubleSpeed: boolean = false; //是否开启二倍速
  147. private doubleNum: number = 2; //除2就是开启了2倍速,除1就是关闭了2倍速
  148. private callback: Function | null = null; //回调函数
  149. //tween时间控制变量
  150. private autoMoveTime: number = 0.4; //自动移动时间
  151. //再次自动放置间隔时间
  152. private autoPlaceInterval: number = 0.4;
  153. //没使用颜色
  154. notUseColor = new Color(255, 255, 255, 255)
  155. //可用的颜色
  156. usableColor = new Color(0, 255, 0, 100)
  157. //不可用的颜色
  158. unavailableColor = new Color(255, 0, 0, 100)
  159. //旋转容错
  160. rotateFaultTolerant = 50;
  161. //游戏暂停状态
  162. private gamePause: boolean = false;
  163. isAutoMode: boolean = false;
  164. autoModeInterval: number = 1 // 自动模式的间隔时间(秒)
  165. autoModeTimer: number = 0 // 自动模式计时器
  166. adShowingFlag: boolean = false; // 广告展示标记
  167. //网格列表管理列表
  168. gridList: GridData[][] = [];
  169. //砖块列表
  170. bricksList: BrickData[] = [];
  171. //网格颜色列表
  172. gridColorList: GridData[] = [];
  173. brickConfig: { bricks?: any } = {} //方块配置
  174. editingData: EditingData = {
  175. brickData: null,
  176. gridList: [],
  177. }
  178. //消除区间数组,到时候去这两个中间值,然后消除次数到了就展示翻倍广告
  179. private eliminateInterval: number[] = [];
  180. // 添加新的属性来跟踪是否需要重置消除计数
  181. private shouldResetEliminateCount: boolean = true;
  182. private autoState: boolean = false; //自动状态
  183. private eliminateBaseScore: number = 10; //每行得多少分
  184. private extraGridScore: number = 1; //每个格子占用几分
  185. private placementBaseScore: number = 1; //每个格子占用几分
  186. private currentCombo: number = 0; // 当前连击次数 //这里要记录连击次数就是每次移动能消除就增加,如果不能就归零
  187. //消除总数
  188. private eliminateTotal: number = 0;
  189. //2倍速时间
  190. private doubleSpeedTime: number = 0;
  191. //新手引导
  192. private isGuideMode = false;
  193. private guideStep = 0;
  194. //福利弹窗
  195. private popupType: string = "";
  196. //新人引导提示语
  197. private guideTips: string[] = [
  198. "拖动方块,填满整行可以进行消除",
  199. "当行与列被砖块同时填满,砖块会被消除",
  200. "点击方块可以旋转90°,不限旋转次数哦",
  201. "放置&消除方块得分达成目标获得金砖"
  202. ];
  203. private randomList: number[] = [];
  204. private autoFunction: Function | null = null;
  205. /** 视图层逻辑代码分离演示 */
  206. async start() {
  207. // const entity = this.ent as ecs.Entity; // ecs.Entity 可转为当前模块的具体实体对象
  208. this.setButton();
  209. this.initButtonState(false);
  210. await this.loadConfig();
  211. this.initData();
  212. this.setData();
  213. this.addEventList();
  214. if (this.guideStep === 0 && smc.account.AccountModel.curLevel == 1) {
  215. this.startGuideMode()
  216. } else {
  217. this.guideNode.active = false;
  218. this.initGrid();
  219. }
  220. this.updateWelfarePoint();
  221. DCHandler.inst.reportData(3000005);
  222. oops.audio.playMusicLoop("common/audios/bgm");
  223. DCHandler.inst.reportData(3000504, smc.account.AccountModel.curLevel);
  224. }
  225. addEventList() {
  226. oops.message.on(GameEvent.RestartGame, this.restartGame, this);
  227. oops.message.on(GameEvent.DoubleSpeedOpenSuccess, this.doubleSpeedOpenSuccess, this);
  228. oops.message.on(GameEvent.openView, this.openView, this);
  229. oops.message.on(GameEvent.showCoinAnimation, this.showCoinAnimation, this);
  230. oops.message.on(GameEvent.updateHbAndWxCoin, this.updateCoin, this);
  231. oops.message.on(GameEvent.StartAutoGame, this.startAutoGame, this);
  232. oops.message.on(GameEvent.updateGameState, this.updateGameState, this);
  233. oops.message.on(GameEvent.pauseGame, this.pauseGame, this);
  234. oops.message.on(GameEvent.resumeGame, this.resumeGame, this);
  235. }
  236. updateGameState(event: string, args: string) {
  237. console.log("更新游戏状态", args);
  238. switch (args) {
  239. case "paused":
  240. this.gameState = GameState.PAUSED;
  241. break;
  242. case "playing":
  243. if (this.gameState == GameState.PAUSED || this.autoState && this.gameState == GameState.GAME_OVER || this.autoState && this.gameState == GameState.GAME_PASS) {
  244. this.gameState = GameState.PLAYING;
  245. }
  246. break;
  247. }
  248. }
  249. pauseGame() {
  250. this.gamePause = true;
  251. director.pause();
  252. }
  253. resumeGame() {
  254. this.gamePause = false;
  255. director.resume();
  256. }
  257. //初始化网格
  258. private initGrid() {
  259. // 清理现有网格
  260. this.clearExistingGrids();
  261. // 生成网格矩阵
  262. this.createGridMatrix();
  263. }
  264. //初始化按钮状态
  265. private initButtonState(state: boolean) {
  266. //自动按钮默认关闭
  267. if (this.autoBtnNode) {
  268. //关闭
  269. const on = this.autoBtnNode.getChildByName("on");
  270. on ? on.active = state : null;
  271. const off = this.autoBtnNode.getChildByName("off");
  272. off ? off.active = !state : null;
  273. }
  274. //第一关隐藏二倍速和自动放置按钮
  275. const curLevel = smc.account.AccountModel.curLevel;
  276. this.autoBtnNode.active = curLevel > 1;
  277. this.doubleSpeedBtn.node.active = curLevel > 1;
  278. }
  279. //初始化数据
  280. private initData() {
  281. // this.gameMode = GameMode.MANUAL;
  282. this.score = 0;
  283. this.targetScore = 0;
  284. this.money = 0;
  285. this.cash = 0;
  286. this.operateFlag = true
  287. this.shouldResetEliminateCount = true;
  288. this.currentCombo = 0;
  289. this.autoNode.active = false;
  290. }
  291. //设置数据
  292. setData() {
  293. if (DeviceUtil.isAndroid && DeviceUtil.isNative) {
  294. if (smc.game.GameModel.curLevelConfig.eliminateScope) {
  295. this.eliminateInterval = smc.game.GameModel.curLevelConfig.eliminateScope || [];
  296. }
  297. }
  298. this.gameState = GameState.PLAYING;
  299. this.score = smc.game.GameModel.curScore || 0;
  300. this.money = smc.account.AccountModel.wxCoin || 0;
  301. this.cash = smc.account.AccountModel.hbCoin || 0;
  302. this.targetScore = smc.game.GameModel.targetScore || 0;
  303. this.popupType = smc.game.GameModel.popupType;
  304. this.lab_score.string = this.score.toString();
  305. this.lab_wxCoin.string = Format.formatWxCoin(this.money);
  306. this.lab_hbCoin.string = Format.formatRedPacketCoin(this.cash);
  307. this.lab_taget.string = this.targetScore.toString();
  308. //金砖数量要加1
  309. const num = smc.account.AccountModel.goldCoin
  310. this.lab_goldNum.string = `${num + 1}`;
  311. this.randomList = this.getRandomUniqueInts();
  312. const curLevel = smc.account.AccountModel.curLevel;
  313. DCHandler.inst.reportData(3000500, curLevel);
  314. }
  315. updateCoin() {
  316. this.money = smc.account.AccountModel.wxCoin;
  317. this.cash = smc.account.AccountModel.hbCoin;
  318. this.lab_wxCoin.string = Format.formatWxCoin(this.money);
  319. this.lab_hbCoin.string = Format.formatRedPacketCoin(this.cash);
  320. }
  321. //开始自动游戏
  322. startAutoGame() {
  323. if (!this.autoState) {
  324. this.autoGame();
  325. }
  326. }
  327. openView(event: string, args: string) {
  328. switch (args) {
  329. case "openRedBagView":
  330. oops.gui.open(UIID.RedPacketWithdraw);
  331. break;
  332. case "openPassView":
  333. oops.gui.open(UIID.GamePass);
  334. break;
  335. case "openDoubleSurprise":
  336. oops.gui.open(UIID.DoubleRewards);
  337. break;
  338. case "openRebateView":
  339. oops.gui.open(UIID.CashRebate);
  340. break;
  341. case "openCashWithdrawalView":
  342. oops.gui.open(UIID.WithSussce); //提现成功
  343. break;
  344. case "openWechatWithdrawalView":
  345. oops.gui.open(UIID.WechatWithdraw); //微信提现页
  346. break;
  347. case "openDoubleSpeedView":
  348. oops.gui.open(UIID.DoubleSpeed);
  349. break;
  350. case "openRecordView":
  351. oops.gui.open(UIID.WithdrawRecord);
  352. break;
  353. }
  354. }
  355. startGuideMode() {
  356. this.isGuideMode = true
  357. this.guideStep = 1
  358. this.guideNode.active = true;
  359. for (let rowIndex = 0; rowIndex < this.rows; rowIndex++) {
  360. const currentRow: GridData[] = [];
  361. this.gridList.push(currentRow);
  362. for (let columnIndex = 0; columnIndex < this.cols; columnIndex++) {
  363. const gridData = this.createGridData(rowIndex, columnIndex);
  364. currentRow.push(gridData);
  365. this.createGridNode(gridData);
  366. }
  367. }
  368. // 初始化格子状态
  369. for (let rowIndex = 0; rowIndex < this.rows; rowIndex++) {
  370. for (let columnIndex = 0; columnIndex < this.cols; columnIndex++) {
  371. this.gridList[rowIndex][columnIndex].status = CellState.EMPTY
  372. this.generateGrid(this.gridList[rowIndex][columnIndex])
  373. }
  374. }
  375. // 清除旋转数据
  376. if (this.rotateNode) {
  377. this.rotateNode.destroyAllChildren();
  378. }
  379. this.touchStartPos.set(Vec2.ZERO)
  380. this.setupGuideStep(this.guideStep)
  381. }
  382. setupGuideStep(step: number) {
  383. this.gameState = GameState.PLAYING;
  384. this.operateFlag = true
  385. this.bricksList.length = 0
  386. this.brickNode.destroyAllChildren();
  387. this.clearAllGuideGrids()
  388. this.guideStep = step
  389. const tips_node = this.guideNode.getChildByPath("tips/lab_tips");
  390. if (tips_node) {
  391. const tips = tips_node.getComponent(Label);
  392. if (tips) {
  393. tips.string = this.guideTips[step - 1];
  394. }
  395. }
  396. if (step === 1) {
  397. this.guideStep1()
  398. }
  399. else if (step === 2) {
  400. this.guideStep2()
  401. }
  402. else if (step === 3) {
  403. this.guideStep3()
  404. }
  405. else if (step === 4) {
  406. this.guideStep4()
  407. }
  408. }
  409. clearAllGuideGrids() {
  410. for (let row = 0; row < this.rows; row++) {
  411. for (let col = 0; col < this.cols; col++) {
  412. const grid = this.gridList[row][col]
  413. grid.status = 0;
  414. grid.type = 0;
  415. this.generateGrid(grid)
  416. }
  417. }
  418. }
  419. // 引导砖块保持底部中间生成
  420. createGuideBrick(gridConfig: GridConfigData[], brickKey: string, colorIndex: number, index: number, rotateFlag = false) {
  421. const brickData = {
  422. index,
  423. brickKey: brickKey,
  424. rotateFlag,
  425. gridConfig,
  426. deg: 0,
  427. brickNode: new Node(),
  428. gridColorKey: "colorKey",
  429. brickInitPos: new Vec3(),
  430. type: colorIndex,
  431. rotateNode: new Node(),
  432. }
  433. const node = this.generateBrick(brickKey, colorIndex);
  434. this.brickNode.addChild(node);
  435. const transform = this.brickNode.getComponent(UITransform);
  436. if (transform) {
  437. const midX = transform.width / 2;
  438. node.setPosition(0, 0);
  439. brickData.brickNode = node
  440. brickData.brickNode.scale_x = 0.8;
  441. brickData.brickNode.scale_y = 0.8;
  442. brickData.brickInitPos = node.getWorldPosition()
  443. this.bricksList.push(brickData)
  444. this.brickAddEvent(brickData)
  445. }
  446. if (brickData.rotateFlag) {
  447. brickData.rotateNode = instantiate(this.rotatePrefab)
  448. this.rotateNode.addChild(brickData.rotateNode);
  449. //先隐藏
  450. brickData.rotateNode.active = false;
  451. brickData.rotateNode.setWorldPosition(this.brickNode.getWorldPosition())
  452. }
  453. }
  454. //引导步骤1
  455. private guideStep1() {
  456. // this.guideFinger.setPosition(v3(55, -461));
  457. const emptyIndex = Math.floor(this.cols / 2)
  458. for (let c = 0; c < this.cols; c++) {
  459. if (c !== emptyIndex) {
  460. const g = this.gridList[4][c]
  461. g.status = 1
  462. g.type = 1;
  463. this.generateGrid(g)
  464. }
  465. }
  466. this.createGuideBrick([
  467. { row: 0, column: 0 },
  468. ], "Brick1", 1, 1)
  469. //手指显示,方块显示
  470. this.guideFinger.active = true;
  471. this.guideItem1.active = true;
  472. //拿出this.guideFinger.x y
  473. tween(this.guideFinger)
  474. .delay(0.2)
  475. .by(1, { position: v3(45, 500, 0) })
  476. .delay(0.2)
  477. .to(0.01, { position: v3(60, -450, 0) }) //原点
  478. .union()
  479. .repeatForever()
  480. .start()
  481. //方块
  482. tween(this.guideItem1)
  483. .delay(0.2)
  484. .by(1, { position: v3(37, 515, 0) })
  485. .delay(0.2)
  486. .to(0.01, { position: v3(0, -410, 0) }) //原点
  487. .union()
  488. .repeatForever()
  489. .start()
  490. }
  491. //引导步骤2
  492. private guideStep2() {
  493. for (let r = 0; r < this.rows; r++) {
  494. if (r !== 4) {
  495. const g = this.gridList[r][4]
  496. g.status = 1
  497. g.type = 1;
  498. this.generateGrid(g)
  499. }
  500. }
  501. this.createGuideBrick([{ row: 0, column: 0 }], "Brick1", 1, 1)
  502. }
  503. //引导步骤3
  504. private guideStep3() {
  505. // 填满前两列,除去 [2][0] 这个位置,制造一个L型缺口
  506. for (let r = 0; r < this.rows; r++) {
  507. for (let c = 3; c < 5; c++) {
  508. if (r === 3 && c === 3) continue
  509. if (r === 4 && c === 3) continue
  510. if (r === 5 && c === 3) continue
  511. if (r === 3 && c === 4) continue
  512. if (r === 4 && c === 4) continue
  513. if (r === 5 && c === 4) continue
  514. const g = this.gridList[r][c]
  515. g.status = 1
  516. g.type = 1;
  517. this.generateGrid(g)
  518. }
  519. }
  520. // 创建一个L型方块,引导玩家旋转后放置
  521. this.createGuideBrick([
  522. { row: 0, column: 0 },
  523. { row: 0, column: 1 },
  524. { row: 0, column: 2 },
  525. { row: 1, column: 0 },
  526. { row: 1, column: 1 },
  527. { row: 1, column: 2 }
  528. ], "BrickII", 1, 1, true) //这要双II
  529. //引导三
  530. this.guideItem1.active = false;
  531. this.guideItem2.active = true;
  532. //停止之前的tween
  533. this.guideFinger.setPosition(v3(55, -461));
  534. Tween.stopAllByTarget(this.guideFinger);
  535. Tween.stopAllByTarget(this.guideItem1);
  536. tween(this.guideFinger)
  537. .delay(0.2)
  538. .by(1, { position: v3(0, 500, 0) })
  539. .delay(0.2)
  540. .to(0.01, { position: v3(55, -450, 0) }) //原点
  541. .union()
  542. .repeatForever()
  543. .start()
  544. //方块
  545. tween(this.guideItem2)
  546. .delay(0.2)
  547. .by(1, { position: v3(0, 515, 0) })
  548. .delay(0.2)
  549. .to(0.01, { position: v3(0, -410, 0) }) //原点
  550. .union()
  551. .repeatForever()
  552. .start()
  553. }
  554. //引导步骤4
  555. private guideStep4() {
  556. const centerRow = 3;
  557. const centerCol = 3;
  558. // 遍历整个网格
  559. for (let r = 0; r < this.rows; r++) {
  560. for (let c = 0; c < this.cols; c++) {
  561. const inCenter =
  562. r >= centerRow && r <= centerRow + 1 &&
  563. c >= centerCol && c <= centerCol + 1;
  564. const isCross =
  565. r === centerRow || r === centerRow + 1 || // 中间两行
  566. c === centerCol || c === centerCol + 1; // 中间两列
  567. if (isCross && !inCenter) {
  568. const g = this.gridList[r][c];
  569. g.status = 1;
  570. g.type = 1;
  571. this.generateGrid(g);
  572. }
  573. }
  574. }
  575. this.createGuideBrick([
  576. { row: 0, column: 0 },
  577. { row: 0, column: 1 },
  578. { row: 1, column: 0 },
  579. { row: 1, column: 1 }
  580. ], "BrickO", 1, 1)
  581. this.guideItem2.active = false;
  582. Tween.stopAllByTarget(this.guideFinger);
  583. Tween.stopAllByTarget(this.guideItem2);
  584. this.guideFinger.setPosition(v3(55, -461));
  585. this.guideItem3.active = true;
  586. tween(this.guideFinger)
  587. .delay(0.2)
  588. .by(1, { position: v3(0, 440, 0) })
  589. .delay(0.2)
  590. .to(0.01, { position: v3(55, -450, 0) }) //原点
  591. .union()
  592. .repeatForever()
  593. .start()
  594. //方块
  595. tween(this.guideItem3)
  596. .delay(0.2)
  597. .by(1, { position: v3(0, 440, 0) })
  598. .delay(0.2)
  599. .to(0.01, { position: v3(0, -410, 0) }) //原点
  600. .union()
  601. .repeatForever()
  602. .start()
  603. }
  604. //显示金币动画 --是否只计算红包
  605. showCoinAnimation(event: string, args: string) {
  606. //计算中间的坐标就好
  607. const lastPos = this.moveNode.getWorldPosition();
  608. const score = this.score;
  609. if (smc.game.GameModel.changeHbCoin > 0) {
  610. this.createCoinFlyAnimation(
  611. this.redPacketPrefab,
  612. lastPos,
  613. this.lab_hbCoin.node.getWorldPosition(),
  614. 2,
  615. () => {
  616. // 显示红包分数增加动画
  617. this.showRedPacketScoreAnimation();
  618. }
  619. );
  620. }
  621. if (smc.game.GameModel.changeWxCoin > 0) {
  622. // 添加回调函数,在金币动画完成后显示微信分数增加
  623. this.createCoinFlyAnimation(
  624. this.coinPrefab,
  625. lastPos,
  626. this.lab_wxCoin.node.getWorldPosition(),
  627. 2,
  628. () => {
  629. // 显示微信分数增加动画
  630. this.showWechatScoreAnimation();
  631. }
  632. );
  633. }
  634. }
  635. //初始化网格
  636. private async loadConfig() {
  637. let json_name: string = "gui/eliminate/config/GridConfig";
  638. return new Promise<void>((resolve, reject) => {
  639. oops.res.load(json_name, JsonAsset, (err: Error | null, res: any) => {
  640. if (res) {
  641. this.brickConfig = res.json;
  642. resolve();
  643. } else {
  644. console.log("JSON数据加载失,请检查文件");
  645. reject(err);
  646. }
  647. });
  648. });
  649. }
  650. /**
  651. * @description: 清理现有的网格数据
  652. * @return {*}
  653. */
  654. private clearExistingGrids(): void {
  655. this.gridList = [];
  656. if (this.gridNode) {
  657. this.gridNode.destroyAllChildren();
  658. }
  659. }
  660. /**
  661. * @description: 设置网格容器大小
  662. * @return {*}
  663. */
  664. private createGridMatrix(): void {
  665. for (let rowIndex = 0; rowIndex < this.rows; rowIndex++) {
  666. const currentRow: GridData[] = [];
  667. this.gridList.push(currentRow);
  668. for (let columnIndex = 0; columnIndex < this.cols; columnIndex++) {
  669. const gridData = this.createGridData(rowIndex, columnIndex);
  670. currentRow.push(gridData);
  671. this.createGridNode(gridData);
  672. }
  673. }
  674. // 初始化格子状态
  675. for (let rowIndex = 0; rowIndex < this.rows; rowIndex++) {
  676. for (let columnIndex = 0; columnIndex < this.cols; columnIndex++) {
  677. this.gridList[rowIndex][columnIndex].status = CellState.EMPTY
  678. this.generateGrid(this.gridList[rowIndex][columnIndex])
  679. }
  680. }
  681. // 初始化方块
  682. if (this.brickNode) {
  683. this.brickNode.destroyAllChildren();
  684. }
  685. this.bricksList.length = 0
  686. for (let i = 1; i <= this.brickNum; i++) {
  687. this.addBrick(i)
  688. }
  689. // 清除旋转数据
  690. if (this.rotateNode) {
  691. this.rotateNode.destroyAllChildren();
  692. }
  693. this.touchStartPos.set(Vec2.ZERO)
  694. }
  695. /**
  696. * @description: 创建格子数据
  697. * @param {number} row
  698. * @param {number} column
  699. * @return {*}
  700. */
  701. private createGridData(row: number, column: number): GridData {
  702. return {
  703. name: `Grid-${row}-${column}`,
  704. status: CellState.EMPTY,
  705. gridNode: null,
  706. row: row,
  707. col: column,
  708. type: 0
  709. };
  710. }
  711. /**
  712. * @description: 创建网格Node
  713. * @param {GridData} gridData
  714. * @return {*}
  715. */
  716. private createGridNode(gridData: GridData): void {
  717. const gridNode = new Node(gridData.name);
  718. if (this.gridNode) {
  719. this.gridNode.addChild(gridNode);
  720. }
  721. gridData.gridNode = gridNode;
  722. // 设置网格大小
  723. gridNode.addComponent(UITransform).setContentSize(this.itemSize, this.itemSize);
  724. }
  725. /**
  726. * 生成或更新网格
  727. * @param gridData 网格数据
  728. */
  729. private generateGrid(gridData: GridData) {
  730. if (!gridData || !gridData.gridNode) {
  731. console.warn('无效的网格数据');
  732. return;
  733. }
  734. // 清理现有子节点
  735. this.clearGridChildren(gridData.gridNode);
  736. // 获取对应的预制体
  737. const prefab = this.getGridPrefab(gridData);
  738. if (!prefab) {
  739. console.warn('无法获取网格预制体');
  740. return;
  741. }
  742. // 创建并配置新节点
  743. const node = this.createNewGridNode(prefab, gridData);
  744. // 设置节点属性
  745. this.setupGridNode(node, gridData);
  746. }
  747. /**
  748. * 获取对应状态的预制体
  749. */
  750. private getGridPrefab(gridData: GridData): Prefab {
  751. if (gridData.status === CellState.EMPTY) {
  752. if (this.itemPrefabs[0]) {
  753. return this.itemPrefabs[0];
  754. } else {
  755. throw new Error('Grid prefab is not loaded');
  756. }
  757. }
  758. if (gridData.status === CellState.FILLED && gridData.type) {
  759. const type = gridData.type;
  760. return this.itemPrefabs[type];
  761. }
  762. throw new Error('Invalid grid status or missing gridColorKey');
  763. }
  764. /**
  765. * 创建网格节点
  766. */
  767. private createNewGridNode(prefab: Prefab, gridData: GridData): Node {
  768. const node = instantiate(prefab);
  769. if (gridData && gridData.gridNode) {
  770. gridData.gridNode.addChild(node);
  771. return node;
  772. }
  773. return node
  774. }
  775. /**
  776. * 设置网格节点的属性
  777. */
  778. private setupGridNode(node: Node, gridData: GridData): void {
  779. // 设置未使用状态的颜色
  780. if (gridData.status === CellState.EMPTY) {
  781. const sprite = node.getComponent(Sprite);
  782. if (sprite) {
  783. sprite.color = this.notUseColor;
  784. }
  785. }
  786. // 设置节点大小
  787. const transform = node.getComponent(UITransform);
  788. if (transform) {
  789. transform.setContentSize(
  790. this.itemSize,
  791. this.itemSize
  792. );
  793. }
  794. // 设置位置
  795. node.setPosition(Vec3.ZERO);
  796. }
  797. addBrick(index: number) {
  798. if (this.isGuideMode) {
  799. return;
  800. }
  801. const brickKey = Object.keys(this.brickConfig['bricks'])[randomRangeInt(0, Object.keys(this.brickConfig['bricks']).length)];
  802. const brickConfig = this.brickConfig['bricks'][brickKey];
  803. const num = Math.floor(Math.random() * this.randomList.length);
  804. const randomIndex = this.randomList[num];
  805. // const randomIndex = this.randomList[0];
  806. // 生成方块
  807. const brickData: BrickData = {
  808. index,
  809. brickKey: brickKey,
  810. rotateFlag: brickConfig['rotateFlag'],
  811. gridConfig: brickConfig['gridConfig'],
  812. deg: 0,
  813. brickNode: null,
  814. brickInitPos: new Vec3(),
  815. type: randomIndex,
  816. rotateNode: null,
  817. }
  818. this.bricksList.push(brickData)
  819. // 生成方块
  820. const brickNode = this.generateBrick(brickKey, randomIndex);
  821. if (this.brickNode) {
  822. this.brickNode.addChild(brickNode)
  823. }
  824. brickData.brickNode = brickNode;
  825. let offset = 220
  826. if (this.brickNum % 2 === 1) {
  827. const middleNum = Math.floor(this.brickNum / 2) + 1
  828. if (index < middleNum) {
  829. offset = - offset
  830. }
  831. else if (index === middleNum) {
  832. offset = 0
  833. }
  834. }
  835. if (brickData && brickData.brickNode) {
  836. brickData.brickNode.setPosition(offset, 0)
  837. brickData.brickNode.scale_x = 0.6;
  838. brickData.brickNode.scale_y = 0.6;
  839. brickData.brickInitPos = brickData.brickNode.getWorldPosition()
  840. }
  841. if (brickData.rotateFlag) {
  842. brickData.rotateNode = instantiate(this.rotatePrefab)
  843. this.rotateNode.addChild(brickData.rotateNode);
  844. //先隐藏
  845. brickData.rotateNode.active = false;
  846. brickData.rotateNode.setWorldPosition(brickNode.getWorldPosition())
  847. }
  848. this.brickAddEvent(brickData);
  849. }
  850. // 每个item生成独立的方块节点
  851. generateBrick(brickKey: string, randomIndex: number) {
  852. const brickConfig = this.brickConfig['bricks'][brickKey]
  853. let rowMin = 0
  854. let rowMax = 0
  855. let columnMin = 0
  856. let columnMax = 0
  857. brickConfig['gridConfig'].forEach((gridConfigData: GridConfigData) => {
  858. if (gridConfigData.row < rowMin) {
  859. rowMin = gridConfigData.row
  860. }
  861. else if (gridConfigData.row > rowMax) {
  862. rowMax = gridConfigData.row
  863. }
  864. if (gridConfigData.column < columnMin) {
  865. columnMin = gridConfigData.column
  866. }
  867. else if (gridConfigData.column > columnMax) {
  868. columnMax = gridConfigData.column
  869. }
  870. })
  871. const rowNum = (rowMax - rowMin + 1)
  872. const columnNum = (columnMax - columnMin + 1)
  873. // 生成独立的方块节点
  874. const brickNode = new Node()
  875. brickNode.name = brickKey
  876. // 设置方块大小
  877. const transformCom: UITransform = brickNode.addComponent(UITransform)
  878. transformCom.setContentSize(
  879. this.itemSize * columnNum,
  880. this.itemSize * rowNum
  881. )
  882. transformCom.setAnchorPoint(0.5, 0.5)
  883. // 设置方块位置
  884. const gridPrefab = this.itemPrefabs[randomIndex]
  885. //生成对应的配置方块设置地址
  886. brickConfig['gridConfig'].forEach((gridConfigData: GridConfigData) => {
  887. const gridNode = new Node()
  888. gridNode.name = 'grid'
  889. brickNode.addChild(gridNode)
  890. gridNode.addComponent(UITransform).setContentSize(this.itemSize, this.itemSize)
  891. const gridWidget: Widget = gridNode.addComponent(Widget)
  892. gridWidget.isAlignLeft = true
  893. gridWidget.left = this.itemSize * gridConfigData.column - this.itemSize * columnMin
  894. gridWidget.isAlignBottom = true
  895. gridWidget.bottom = this.itemSize * gridConfigData.row - this.itemSize * rowMin
  896. const node = instantiate(gridPrefab)
  897. gridNode.addChild(node)
  898. const uiTransform = node.getComponent(UITransform);
  899. if (uiTransform) {
  900. uiTransform.setContentSize(
  901. this.itemSize,
  902. this.itemSize,
  903. )
  904. }
  905. node.setPosition(Vec3.ZERO)
  906. node.on(Node.EventType.TOUCH_START, (event: EventTouch) => {
  907. event.preventSwallow = true;
  908. }, this);
  909. node.on(Node.EventType.TOUCH_MOVE, (event: EventTouch) => {
  910. event.preventSwallow = true;
  911. }, this);
  912. node.on(Node.EventType.TOUCH_END, (event: EventTouch) => {
  913. event.preventSwallow = true;
  914. }, this);
  915. })
  916. return brickNode
  917. }
  918. brickAddEvent(brickData: BrickData) {
  919. const brickNode = brickData.brickNode
  920. if (!brickNode) {
  921. console.error("brickNode为空,无法添加事件");
  922. return
  923. }
  924. // 记录初始位置和状态
  925. let startPos = new Vec3();
  926. let originalParent: Node | null = null;
  927. // 触摸开始事件
  928. brickNode.on(Node.EventType.TOUCH_START, (event: EventTouch) => {
  929. // 如果正在编辑其他方块,则忽略
  930. if (!this.operateFlag) return;
  931. // 清空编辑中的数据
  932. this.editingData.brickData = null;
  933. this.editingData.gridList.length = 0;
  934. // 记录触摸开始位置和方块原始信息
  935. this.touchStartPos.set(event.getUILocation());
  936. originalParent = brickNode.parent;
  937. startPos = brickNode.getWorldPosition().clone();
  938. // 将方块移到移动层并放大
  939. brickNode.setParent(this.moveNode);
  940. brickNode.setWorldPosition(startPos);
  941. // 从方块列表中移除该方块
  942. const index = this.bricksList.findIndex(item => item === brickData);
  943. if (index > -1) {
  944. this.editingData.brickData = this.bricksList.splice(index, 1)[0];
  945. } else {
  946. //返回原位置
  947. console.error(">>this.bricksList>>>>>>", JSON.stringify(this.bricksList));
  948. console.error("未找到方块数据:", JSON.stringify(brickData));
  949. this.bricksList.push(brickData)
  950. if (brickData.brickNode) {
  951. tween(brickData.brickNode)
  952. .to(0.15, {
  953. worldPosition: brickData.brickInitPos,
  954. scale: new Vec3(0.8, 0.8, 0.8)
  955. })
  956. .call(() => {
  957. if (brickData.brickNode) {
  958. this.operateFlag = true
  959. this.brickNode.addChild(brickData.brickNode)
  960. brickData.brickNode.setWorldPosition(brickData.brickInitPos)
  961. }
  962. })
  963. .start()
  964. }
  965. }
  966. }, this);
  967. // 触摸移动事件
  968. brickNode.on(Node.EventType.TOUCH_MOVE, (event: EventTouch) => {
  969. if (!this.operateFlag) return;
  970. const movePos: Vec2 = event.getUILocation().subtract(this.touchStartPos)
  971. // 挪动很小时,不移动方块组合
  972. if (movePos.length() <= this.rotateFaultTolerant) {
  973. return
  974. }
  975. // 隐藏旋转节点
  976. if (this.editingData.brickData && this.editingData.brickData.rotateFlag) {
  977. if (this.editingData.brickData.rotateNode) {
  978. this.editingData.brickData.rotateNode.active = false
  979. }
  980. }
  981. // 恢复所有网格颜色
  982. this.gridColorRecovery();
  983. // 移动方块
  984. brickNode.setWorldPosition(event.getUILocation().toVec3().add3f(0, this.yOffset, 0))
  985. brickNode.scale_x = 1;
  986. brickNode.scale_y = 1;
  987. // 重置编辑中的网格数据
  988. this.editingData.gridList.length = 0;
  989. // 检查方块每个子网格是否与游戏网格重叠
  990. const tempGridList: GridData[] = [];
  991. let allEmptyGrids: boolean = true; // 标记是否所有网格都为空
  992. brickNode.children.forEach((childNode) => {
  993. const childWorldPos = childNode.getWorldPosition();
  994. // 查找与子网格重叠的游戏网格
  995. let matchedGrid: GridData | null = null;
  996. for (let row = 0; row < this.rows && !matchedGrid; row++) {
  997. for (let col = 0; col < this.cols && !matchedGrid; col++) {
  998. const grid = this.gridList[row][col];
  999. if (!grid || !grid.gridNode) continue;
  1000. const gridPos = grid.gridNode.getWorldPosition();
  1001. if (Vec3.distance(gridPos, childWorldPos) <= (this.itemSize / 2)) {
  1002. matchedGrid = grid;
  1003. }
  1004. }
  1005. }
  1006. if (matchedGrid) {
  1007. tempGridList.push(matchedGrid);
  1008. // 检查是否有非空网格
  1009. if (matchedGrid.status !== CellState.EMPTY) {
  1010. allEmptyGrids = false;
  1011. }
  1012. }
  1013. });
  1014. // 检查是否所有子网格都有对应的游戏网格,且都是空的
  1015. let canPlace = tempGridList.length === brickData.gridConfig.length && allEmptyGrids;
  1016. // 更新编辑中的网格列表
  1017. if (canPlace) {
  1018. this.editingData.gridList = [...tempGridList];
  1019. }
  1020. // 更新网格颜色提示 - 只改变空网格的颜色
  1021. tempGridList.forEach(grid => {
  1022. // 只处理空网格
  1023. if (grid.status === CellState.EMPTY) {
  1024. if (grid.gridNode && grid.gridNode.children[0]) {
  1025. const sprite = grid.gridNode.children[0].getComponent(Sprite);
  1026. if (sprite) {
  1027. sprite.color = canPlace ? this.usableColor : this.unavailableColor;
  1028. }
  1029. }
  1030. // 用于后续恢复颜色
  1031. this.gridColorList.push(grid);
  1032. }
  1033. });
  1034. }, this);
  1035. // 触摸结束或取消事件
  1036. const touchEndHandler = (event: EventTouch) => {
  1037. if (!this.operateFlag) return
  1038. this.operateFlag = false
  1039. // 单击旋转
  1040. if (!this.editingData.brickData) {
  1041. console.log("没有数据")
  1042. return
  1043. }
  1044. if (
  1045. this.editingData.brickData.rotateFlag &&
  1046. event.getUILocation().subtract(this.touchStartPos).length() <= this.rotateFaultTolerant
  1047. ) {
  1048. //旋转
  1049. const brickData = this.editingData.brickData
  1050. if (brickData && brickData.brickNode) {
  1051. this.bricksList.push(brickData)
  1052. this.brickNode.addChild(brickData.brickNode)
  1053. //显示旋转节点
  1054. if (brickData.rotateNode) {
  1055. brickData.rotateNode.active = true;
  1056. }
  1057. brickData.brickNode.setWorldPosition(brickData.brickInitPos)
  1058. // 旋转
  1059. this.brickGridRotate(brickData).then(() => {
  1060. this.operateFlag = true
  1061. })
  1062. // 隐藏旋转节点
  1063. this.scheduleOnce(() => {
  1064. if (brickData.rotateNode) {
  1065. brickData.rotateNode.active = false;
  1066. }
  1067. }, 0.4);
  1068. //打点
  1069. DCHandler.inst.reportData(3000600);
  1070. }
  1071. } else if (this.editingData.brickData && this.editingData.gridList.length > 0) {
  1072. if (this.isGuideMode && this.guideStep > 0) {
  1073. const brickData = this.editingData.brickData
  1074. const targetGrids = this.editingData.gridList
  1075. // 如果格子数量不足,直接视为无效放置
  1076. if (!brickData || !targetGrids || targetGrids.length !== brickData.gridConfig.length) {
  1077. this.bricksList.push(brickData)
  1078. if (brickData.brickNode) {
  1079. tween(brickData.brickNode)
  1080. .to(0.15, {
  1081. worldPosition: brickData.brickInitPos,
  1082. scale: new Vec3(0.8, 0.8, 0.8)
  1083. })
  1084. .call(() => {
  1085. if (brickData.brickNode) {
  1086. this.operateFlag = true
  1087. this.brickNode.addChild(brickData.brickNode)
  1088. brickData.brickNode.setWorldPosition(brickData.brickInitPos)
  1089. }
  1090. })
  1091. .start()
  1092. }
  1093. return
  1094. }
  1095. // 模拟砖块落下后的状态
  1096. const tempGridList = this.copyGridList()
  1097. for (let i = 0; i < targetGrids.length; i++) {
  1098. const g = targetGrids[i]
  1099. tempGridList[g.row][g.col].status = CellState.FILLED
  1100. }
  1101. const simulateResult = this.gridEliminateCheck(tempGridList)
  1102. const canEliminate = simulateResult.gridEliminateList.length > 0
  1103. //如果不能消除,则将方块返回原位置
  1104. if (!canEliminate) {
  1105. this.bricksList.push(brickData);
  1106. if (brickData.brickNode) {
  1107. tween(brickData.brickNode)
  1108. .to(0.15, {
  1109. worldPosition: brickData.brickInitPos,
  1110. scale: new Vec3(0.8, 0.8, 0.8)
  1111. })
  1112. .call(() => {
  1113. if (brickData.brickNode) {
  1114. this.operateFlag = true
  1115. this.brickNode.addChild(brickData.brickNode)
  1116. brickData.brickNode.setWorldPosition(brickData.brickInitPos)
  1117. }
  1118. })
  1119. .start()
  1120. }
  1121. return
  1122. }
  1123. }
  1124. // 显示放置得分动画(显示一次,包含总格子数)
  1125. this.showScoreAnimation();
  1126. // 放置方块到网格
  1127. this.editingData.gridList.forEach(grid => {
  1128. grid.status = CellState.FILLED;
  1129. grid.type = this.editingData.brickData!.type;
  1130. this.generateGrid(grid);
  1131. });
  1132. // 标记需要重置消除计数器
  1133. this.shouldResetEliminateCount = true;
  1134. brickNode.destroy();
  1135. this.addBrick(this.editingData.brickData.index);
  1136. // 检查消除
  1137. this.scheduleOnce(() => {
  1138. this.gridEliminate().then((hasElimination) => {
  1139. // 如果没有消除,确保下次消除会重置计数
  1140. if (!hasElimination) {
  1141. this.shouldResetEliminateCount = true;
  1142. }
  1143. this.operateFlag = true;
  1144. //新手引导
  1145. console.log("消除返回", this.isGuideMode);
  1146. console.log("新手引导", this.guideStep);
  1147. if (this.isGuideMode) {
  1148. this.scheduleOnce(() => {
  1149. if (this.guideStep < 4) {
  1150. console.log("新手引导", this.guideStep);
  1151. this.setupGuideStep(this.guideStep + 1)
  1152. } else {
  1153. console.log("新手引导结束");
  1154. this.isGuideMode = false;
  1155. this.guideNode.active = false;
  1156. Tween.stopAllByTarget(this.guideFinger);
  1157. Tween.stopAllByTarget(this.guideItem3);
  1158. this.initGrid();
  1159. }
  1160. }, 0.3)
  1161. } else {
  1162. // 检查游戏是否结束
  1163. this.prompt(false).then(canContinue => {
  1164. if (!canContinue) {
  1165. this.gameOver();
  1166. }
  1167. });
  1168. }
  1169. });
  1170. }, 0.1);
  1171. } else {
  1172. // 无法放置,将方块返回原位置
  1173. const brickData = this.editingData.brickData;
  1174. if (brickData) {
  1175. this.bricksList.push(brickData);
  1176. this.operateFlag = false
  1177. // 添加回弹动画
  1178. tween(brickNode)
  1179. .to(0.2, {
  1180. worldPosition: brickData.brickInitPos,
  1181. scale: new Vec3(0.6, 0.6, 0.6)
  1182. })
  1183. .call(() => {
  1184. if (originalParent) {
  1185. this.operateFlag = true
  1186. brickNode.setParent(originalParent);
  1187. brickNode.setWorldPosition(brickData.brickInitPos);
  1188. }
  1189. })
  1190. .start();
  1191. }
  1192. }
  1193. // 格子颜色恢复
  1194. this.gridColorRecovery()
  1195. };
  1196. brickNode.on(Node.EventType.TOUCH_END, touchEndHandler, this);
  1197. brickNode.on(Node.EventType.TOUCH_CANCEL, touchEndHandler, this);
  1198. }
  1199. //格子颜色恢复
  1200. gridColorRecovery() {
  1201. while (this.gridColorList.length > 0) {
  1202. const gridData = this.gridColorList.pop();
  1203. if (gridData) {
  1204. if (gridData.status === CellState.EMPTY) {
  1205. if (gridData.gridNode) {
  1206. gridData.gridNode.children[0].getComponent(Sprite)!.color = this.notUseColor;
  1207. }
  1208. }
  1209. }
  1210. }
  1211. }
  1212. brickGridRotate(brickData: BrickData) {
  1213. return new Promise((resolve, reject) => {
  1214. const next = this.nextGridRotate(brickData.gridConfig, brickData.deg)
  1215. brickData.deg = next.deg
  1216. brickData.gridConfig = next.gridConfig
  1217. if (brickData.brickNode) {
  1218. tween(brickData.brickNode).to(this.aniBrickRotate, { angle: next.deg }).call(() => {
  1219. resolve(true)
  1220. }).start()
  1221. }
  1222. })
  1223. }
  1224. //下一个旋转
  1225. nextGridRotate(gridConfig: GridConfigData[], deg: number) {
  1226. const newGridConfig: GridConfigData[] = []
  1227. // 顺时针旋转
  1228. let newDeg = deg - 90
  1229. gridConfig.forEach((gridConfigData) => {
  1230. // 例如(1,2) => (-2,1),可以画图分析
  1231. newGridConfig.push({
  1232. row: -gridConfigData.column,
  1233. column: gridConfigData.row
  1234. })
  1235. })
  1236. return { gridConfig: newGridConfig, deg: newDeg }
  1237. }
  1238. // 显示分数增加动画
  1239. showScoreAnimation() {
  1240. if (!this.lab_addScore) return;
  1241. // 计算放置的格子数量
  1242. const placedGridCount = this.editingData.gridList.length;
  1243. // 获取中心位置用于显示分数
  1244. let centerPos = new Vec3(0, 0, 0);
  1245. if (this.editingData.gridList.length > 0 && this.editingData.gridList[0].gridNode) {
  1246. centerPos = this.editingData.gridList[0].gridNode.getWorldPosition().clone();
  1247. if (this.editingData.gridList.length > 1) {
  1248. // 计算所有格子的平均位置作为中心点
  1249. for (let i = 1; i < this.editingData.gridList.length; i++) {
  1250. const gridNode = this.editingData.gridList[i].gridNode;
  1251. if (gridNode) {
  1252. centerPos.add(gridNode.getWorldPosition());
  1253. }
  1254. }
  1255. const validGridCount = this.editingData.gridList.filter(grid => grid.gridNode).length;
  1256. centerPos.x /= validGridCount;
  1257. centerPos.y /= validGridCount;
  1258. }
  1259. }
  1260. let score = placedGridCount;
  1261. let position = centerPos
  1262. // 计算得分(未消除时的得分)
  1263. const calculatedScore = score * this.placementBaseScore;
  1264. // 复制得分Label
  1265. const scoreLabel = instantiate(this.lab_addScore.node);
  1266. scoreLabel.active = true;
  1267. // 设置文本和位置
  1268. const label = scoreLabel.getComponent(Label);
  1269. if (label) {
  1270. label.string = `+${calculatedScore}`;
  1271. }
  1272. // 添加到场景中
  1273. this.node.addChild(scoreLabel);
  1274. scoreLabel.setWorldPosition(position);
  1275. const num = this.isDoubleSpeed ? this.doubleNum : 1;
  1276. // 创建动画效果
  1277. tween(scoreLabel)
  1278. .to(0.5 / num, {
  1279. position: new Vec3(scoreLabel.position.x, scoreLabel.position.y + 50, 0),
  1280. scale: new Vec3(1.2, 1.2, 1.2)
  1281. })
  1282. .to(0.3 / num, { opacity: 0 })
  1283. .call(() => {
  1284. scoreLabel.destroy();
  1285. })
  1286. .start();
  1287. // 更新总分
  1288. this.score += calculatedScore;
  1289. }
  1290. // 显示消除次数动画
  1291. showEliminateCountAnimation(yPosition: number, eliminationCount: number) {
  1292. if (!this.comboNode) return;
  1293. // 如果需要重置计数器,先将计数归零
  1294. if (this.shouldResetEliminateCount) {
  1295. this.currentCombo = 0;
  1296. this.shouldResetEliminateCount = false;
  1297. }
  1298. // 增加累计消除次数
  1299. this.currentCombo += eliminationCount;
  1300. // 复制总次数Label
  1301. const comboNode = instantiate(this.comboNode);
  1302. comboNode.active = true;
  1303. // 设置文本
  1304. const label = comboNode.getChildByName("lab_combo");
  1305. if (label) {
  1306. const labelComponent = label.getComponent(Label);
  1307. if (labelComponent) {
  1308. labelComponent.string = `${this.currentCombo}`;
  1309. }
  1310. }
  1311. // 添加到场景中
  1312. this.node.addChild(comboNode);
  1313. // 计算网格区域的X轴中心位置,Y轴使用传入的消除行位置
  1314. const centerPos = new Vec3();
  1315. if (this.gridNode) {
  1316. // 获取网格区域的X轴中心
  1317. const worldPos = this.gridNode.getWorldPosition();
  1318. centerPos.set(worldPos.x, yPosition, worldPos.z);
  1319. }
  1320. comboNode.setWorldPosition(centerPos);
  1321. // 创建动画效果
  1322. const num = this.isDoubleSpeed ? this.doubleNum : 1;
  1323. tween(comboNode)
  1324. .to(0.3 / num, {
  1325. scale: new Vec3(1.5, 1.5, 1.5),
  1326. opacity: 255
  1327. })
  1328. .delay(0.5 / num) // 停留更长时间
  1329. .to(0.4 / num, {
  1330. scale: new Vec3(1.2, 1.2, 1.2),
  1331. position: new Vec3(comboNode.position.x, comboNode.position.y + 50, 0),
  1332. opacity: 0
  1333. })
  1334. .call(() => {
  1335. comboNode.destroy();
  1336. })
  1337. .start();
  1338. }
  1339. //
  1340. gridEliminate() {
  1341. return new Promise<boolean>((resolve, reject) => {
  1342. const d = this.gridEliminateCheck(this.gridList)
  1343. const gridEliminateList = d.gridEliminateList
  1344. const eliminateRowNum = d.eliminateRowNum
  1345. const eliminateColumnNum = d.eliminateColumnNum
  1346. const totalEliminationsInThisRound = eliminateRowNum + eliminateColumnNum
  1347. this.eliminateTotal += totalEliminationsInThisRound;
  1348. console.log("消除总数", this.eliminateTotal)
  1349. if (gridEliminateList.length < 1) {
  1350. // 没有发生消除
  1351. this.updateGameScore();
  1352. this.shouldResetEliminateCount = true; // 下一次消除需要重置计数
  1353. resolve(false);
  1354. return;
  1355. }
  1356. // 如果有消除,计算消除行的平均Y轴位置
  1357. if (gridEliminateList.length > 0) {
  1358. // 计算所有被消除格子的平均Y轴位置
  1359. let totalY = 0;
  1360. let validGrids = 0;
  1361. for (const grid of gridEliminateList) {
  1362. if (grid.gridNode) {
  1363. totalY += grid.gridNode.getWorldPosition().y;
  1364. validGrids++;
  1365. }
  1366. }
  1367. // 计算平均Y位置
  1368. const avgY = validGrids > 0 ? totalY / validGrids : 0;
  1369. // 显示消除次数动画,传入Y轴位置和本次消除的行列总数
  1370. this.showEliminateCountAnimation(avgY, totalEliminationsInThisRound);
  1371. }
  1372. const num = this.isDoubleSpeed ? this.doubleNum : 1;
  1373. gridEliminateList.forEach((gridData) => {
  1374. if (gridData.gridNode?.children[0]) {
  1375. tween(gridData.gridNode.children[0])
  1376. .to(0.2 / num, { scale: new Vec3(0.5, 0.5) })
  1377. .call(() => {
  1378. gridData.status = CellState.EMPTY
  1379. this.generateGrid(gridData)
  1380. })
  1381. .start()
  1382. }
  1383. })
  1384. oops.audio.playEffect("common/audios/eliminate")
  1385. this.scheduleOnce(() => {
  1386. // 计算分数:每行/列的基础分 + 每个额外格子的分数
  1387. let score = 0;
  1388. // 行消除基础分
  1389. for (let i = 1; i <= eliminateRowNum; i++) {
  1390. score += this.eliminateBaseScore; // 每行基础分
  1391. score += (this.cols - 1) * this.extraGridScore; // 额外格子分
  1392. }
  1393. // 列消除基础分
  1394. for (let i = 1; i <= eliminateColumnNum; i++) {
  1395. score += this.eliminateBaseScore; // 每列基础分
  1396. score += (this.rows - 1) * this.extraGridScore; // 额外格子分
  1397. }
  1398. this.score += score;
  1399. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  1400. ServerHandler.inst.updateEliminationReward({
  1401. count: totalEliminationsInThisRound,
  1402. score: this.score,
  1403. level: smc.account.AccountModel.curLevel,
  1404. })
  1405. }
  1406. if (DeviceUtil.isAndroid && DeviceUtil.isNative) {
  1407. //需要欧知道是否通关了,当前通关了就不要弹了
  1408. if (this.score < this.targetScore) {
  1409. if (this.eliminateInterval.length > 0) {
  1410. const minNum = this.eliminateInterval[0]
  1411. const maxNum = this.eliminateInterval[1]
  1412. if (minNum && maxNum) {
  1413. const randomNum = randomRangeInt(minNum, maxNum + 1);
  1414. //这个数可以被总消除次数整除那就可以弹广告
  1415. if (this.eliminateTotal % randomNum === 0) {
  1416. //如果有自动就暂停自动
  1417. if (this.autoState) {
  1418. this.gameState = GameState.PAUSED;
  1419. }
  1420. if (smc.game.GameModel.skipAdConfig != -1) {
  1421. if (smc.game.GameModel.skipAdCount > 0 && smc.game.GameModel.skipAdCount % smc.game.GameModel.skipAdConfig == 0) {
  1422. console.log("skipAdCount>>>>>>>>>>>>>>>", smc.game.GameModel.skipAdCount);
  1423. console.log("skipAdConfig>>>>>>>>>>>>>>", smc.game.GameModel.skipAdConfig);
  1424. smc.game.GameModel.viewType = "double_reward";
  1425. ADHandler.inst.showAd(AD_TYPE.Double_Receive);
  1426. } else {
  1427. ServerHandler.inst.getDoubleSurprise();
  1428. }
  1429. } else {
  1430. ServerHandler.inst.getDoubleSurprise();
  1431. }
  1432. }
  1433. }
  1434. }
  1435. }
  1436. }
  1437. this.updateGameScore();
  1438. resolve(true)
  1439. }, 0.1)
  1440. })
  1441. }
  1442. //消除检查
  1443. gridEliminateCheck(gridList: GridData[][]) {
  1444. const gridEliminateList: GridData[] = []
  1445. let eliminateRowNum = 0
  1446. let eliminateColumnNum = 0
  1447. // 行检查
  1448. for (let rowIndex = 0; rowIndex < this.rows; rowIndex++) {
  1449. const rowData = gridList[rowIndex]
  1450. if (rowData.every(gridData => gridData.status === CellState.FILLED)) {
  1451. rowData.forEach(gridData => {
  1452. if (gridEliminateList.findIndex(data => data === gridData) < 0) {
  1453. gridEliminateList.push(gridData)
  1454. }
  1455. })
  1456. eliminateRowNum += 1
  1457. }
  1458. }
  1459. // 列检查
  1460. for (let columnIndex = 0; columnIndex < this.cols; columnIndex++) {
  1461. if (gridList.every(rowData => rowData[columnIndex].status === CellState.FILLED)) {
  1462. gridList.forEach(rowData => {
  1463. const gridData = rowData[columnIndex]
  1464. if (gridEliminateList.findIndex(data => data === gridData) < 0) {
  1465. gridEliminateList.push(gridData)
  1466. }
  1467. })
  1468. eliminateColumnNum += 1
  1469. }
  1470. }
  1471. return {
  1472. gridEliminateList,
  1473. eliminateRowNum,
  1474. eliminateColumnNum,
  1475. }
  1476. }
  1477. private createCoinFlyAnimation(prefab: Prefab, startPos: Vec3, endPos: Vec3, count: number, callback?: Function) {
  1478. if (!prefab) return;
  1479. let completedCount = 0;
  1480. const totalCoins = Math.min(count, 5); // 限制最大数量
  1481. const delayBetweenCoins = 0.1; // 每个金币之间的延迟时间
  1482. for (let i = 0; i < totalCoins; i++) {
  1483. const coin = instantiate(prefab);
  1484. this.node.addChild(coin);
  1485. //设置位置,取舞台中间位置世界坐标
  1486. coin.setWorldPosition(startPos);
  1487. // 创建曲线动画
  1488. const num = this.isDoubleSpeed ? this.doubleNum : 1;
  1489. // 添加延迟,使金币一个接一个飞出
  1490. tween(coin)
  1491. .delay(i * delayBetweenCoins / num) // 每个金币有不同的延迟
  1492. .to(0.2 / num, {
  1493. position: new Vec3(
  1494. coin.position.x,
  1495. coin.position.y,
  1496. 0
  1497. )
  1498. })
  1499. .to(0.5 / num, { worldPosition: endPos })
  1500. .call(() => {
  1501. coin.destroy();
  1502. completedCount++;
  1503. // 所有金币动画完成后执行回调
  1504. if (completedCount === totalCoins && callback) {
  1505. callback();
  1506. }
  1507. })
  1508. .start();
  1509. }
  1510. }
  1511. // 显示微信分数增加动画
  1512. private showWechatScoreAnimation() {
  1513. if (!this.tweenWechatNode) return;
  1514. // 生成随机小数(小于1,保留2位小数)
  1515. const changeNum = smc.game.GameModel.changeWxCoin;
  1516. this.money = smc.account.AccountModel.wxCoin;
  1517. const formattedValue = changeNum;
  1518. console.log("微信币增加数值>>>>>>>>>", changeNum);
  1519. // 获取并设置分数标签
  1520. const scoreLabel = this.tweenWechatNode.getChildByName("lab_num")?.getComponent(Label);
  1521. if (scoreLabel) {
  1522. scoreLabel.string = "+" + Format.formatWxCoinModify(formattedValue);
  1523. }
  1524. // 保存原始位置
  1525. const originalPosition = this.lab_wxCoin.node.worldPosition;
  1526. //设置原始位置
  1527. this.tweenWechatNode.setWorldPosition(originalPosition);
  1528. // 显示节点
  1529. this.tweenWechatNode.active = true;
  1530. // 创建向上移动的动画
  1531. tween(this.tweenWechatNode)
  1532. .to(0.8, {
  1533. worldPosition: new Vec3(
  1534. originalPosition.x,
  1535. originalPosition.y + 50,
  1536. originalPosition.z
  1537. ),
  1538. opacity: 255
  1539. })
  1540. .to(0.2, { opacity: 0 })
  1541. .call(() => {
  1542. //设置位置y-100
  1543. this.tweenWechatNode.setWorldPosition(new Vec3(
  1544. originalPosition.x,
  1545. originalPosition.y,
  1546. originalPosition.z
  1547. ))
  1548. this.tweenWechatNode.active = false;
  1549. // 更新总金额
  1550. if (this.lab_wxCoin) {
  1551. this.lab_wxCoin.string = Format.formatWxCoin(this.money);
  1552. }
  1553. })
  1554. .start();
  1555. }
  1556. // 显示红包分数增加动画
  1557. private showRedPacketScoreAnimation() {
  1558. if (!this.tweenRedNode) return;
  1559. //如果有值就是要那个,没有就是取随机
  1560. const changeNum = smc.game.GameModel.changeHbCoin;
  1561. console.log("红包分数增加动画", changeNum)
  1562. this.cash = smc.account.AccountModel.hbCoin;
  1563. if (!changeNum) return;
  1564. const formattedValue = changeNum;
  1565. // 获取并设置分数标签
  1566. const scoreLabel = this.tweenRedNode.getChildByName("lab_num")?.getComponent(Label);
  1567. if (scoreLabel) {
  1568. scoreLabel.string = "+" + Format.formatRedPacketCoin(formattedValue);
  1569. }
  1570. // 保存原始位置
  1571. const originalPosition = this.lab_hbCoin.node.worldPosition;
  1572. //设置原始位置
  1573. this.tweenRedNode.setWorldPosition(originalPosition);
  1574. // 显示节点
  1575. this.tweenRedNode.active = true;
  1576. // 创建向上移动的动画
  1577. const num = this.isDoubleSpeed ? this.doubleNum : 1;
  1578. tween(this.tweenRedNode)
  1579. .to(0.8 / num, {
  1580. worldPosition: new Vec3(
  1581. originalPosition.x,
  1582. originalPosition.y + 50,
  1583. originalPosition.z
  1584. ),
  1585. opacity: 255
  1586. })
  1587. .to(0.2 / num, { opacity: 0 })
  1588. .call(() => {
  1589. this.tweenRedNode.setWorldPosition(new Vec3(
  1590. originalPosition.x,
  1591. originalPosition.y,
  1592. originalPosition.z
  1593. ))
  1594. this.tweenRedNode.active = false;
  1595. // 更新总红包金额
  1596. if (this.lab_hbCoin) {
  1597. // this.lab_hbCoin.changeTo(0.5, newAmount, () => {
  1598. // })
  1599. this.lab_hbCoin.string = Format.formatRedPacketCoin(this.cash);
  1600. }
  1601. })
  1602. .start();
  1603. }
  1604. // 提示
  1605. prompt(tipFlag = true) {
  1606. return new Promise((resolve, reject) => {
  1607. const gridPromptList: GridData[] = []
  1608. let moveFlag = false
  1609. // 找方块可消除位置
  1610. for (let rowIndex = 0; rowIndex < this.rows && !moveFlag; rowIndex++) {
  1611. for (let columnIndex = 0; columnIndex < this.cols && !moveFlag; columnIndex++) {
  1612. const gridData = this.gridList[rowIndex][columnIndex]
  1613. if (gridData.status !== CellState.EMPTY) continue
  1614. // 方块不旋转检测是否能放
  1615. for (let brickI = 0; brickI < this.bricksList.length && !moveFlag; brickI++) {
  1616. const brickData = this.bricksList[brickI]
  1617. if (this.moveIf(rowIndex, columnIndex, brickData.gridConfig)) {
  1618. // 复制整体网格,以方块设置网格状态
  1619. const gridList = this.copyGridList()
  1620. brickData.gridConfig.forEach((gridConfigData) => {
  1621. gridList[gridConfigData.row + rowIndex][gridConfigData.column + columnIndex].status = CellState.FILLED
  1622. })
  1623. // 检查复制的整体网格是否有可消除
  1624. if (this.gridEliminateCheck(gridList).gridEliminateList.length > 0) {
  1625. moveFlag = true
  1626. brickData.gridConfig.forEach((gridConfigData) => {
  1627. gridPromptList.push(this.gridList[gridConfigData.row + rowIndex][gridConfigData.column + columnIndex])
  1628. })
  1629. }
  1630. }
  1631. }
  1632. // 方块旋转检测是否能放
  1633. for (let brickI = 0; brickI < this.bricksList.length && !moveFlag; brickI++) {
  1634. const brickData = this.bricksList[brickI]
  1635. if (!brickData.rotateFlag) continue
  1636. let gridConfig = brickData.gridConfig
  1637. let deg = brickData.deg
  1638. // 获得旋转的方块网格配置
  1639. for (let count = 1; count <= 3 && !moveFlag; count++) {
  1640. const next = this.nextGridRotate(gridConfig, deg)
  1641. if (this.moveIf(rowIndex, columnIndex, next.gridConfig)) {
  1642. // 复制整体网格,以方块设置网格状态
  1643. const gridList = this.copyGridList()
  1644. next.gridConfig.forEach((gridConfigData) => {
  1645. gridList[gridConfigData.row + rowIndex][gridConfigData.column + columnIndex].status = CellState.FILLED
  1646. })
  1647. // 检查复制的整体网格是否有可消除
  1648. if (this.gridEliminateCheck(gridList).gridEliminateList.length > 0) {
  1649. moveFlag = true
  1650. next.gridConfig.forEach((gridConfigData) => {
  1651. gridPromptList.push(this.gridList[gridConfigData.row + rowIndex][gridConfigData.column + columnIndex])
  1652. })
  1653. }
  1654. }
  1655. gridConfig = next.gridConfig
  1656. deg = next.deg
  1657. }
  1658. }
  1659. }
  1660. }
  1661. // 找方块可放置位置
  1662. for (let rowIndex = 0; rowIndex < this.rows && !moveFlag; rowIndex++) {
  1663. for (let columnIndex = 0; columnIndex < this.cols && !moveFlag; columnIndex++) {
  1664. const gridData = this.gridList[rowIndex][columnIndex]
  1665. if (gridData.status !== CellState.EMPTY) continue
  1666. // 方块不旋转检测是否能放
  1667. for (let brickI = 0; brickI < this.bricksList.length && !moveFlag; brickI++) {
  1668. const brickData = this.bricksList[brickI]
  1669. if (this.moveIf(rowIndex, columnIndex, brickData.gridConfig)) {
  1670. moveFlag = true
  1671. brickData.gridConfig.forEach((gridConfigData) => {
  1672. gridPromptList.push(this.gridList[gridConfigData.row + rowIndex][gridConfigData.column + columnIndex])
  1673. })
  1674. }
  1675. }
  1676. // 方块旋转检测是否能放
  1677. for (let brickI = 0; brickI < this.bricksList.length && !moveFlag; brickI++) {
  1678. const brickData = this.bricksList[brickI]
  1679. if (!brickData.rotateFlag) continue
  1680. let gridConfig = brickData.gridConfig
  1681. let deg = brickData.deg
  1682. for (let count = 1; count <= 3 && !moveFlag; count++) {
  1683. const next = this.nextGridRotate(gridConfig, deg)
  1684. if (this.moveIf(rowIndex, columnIndex, next.gridConfig)) {
  1685. moveFlag = true
  1686. next.gridConfig.forEach((gridConfigData) => {
  1687. gridPromptList.push(this.gridList[gridConfigData.row + rowIndex][gridConfigData.column + columnIndex])
  1688. })
  1689. }
  1690. gridConfig = next.gridConfig
  1691. deg = next.deg
  1692. }
  1693. }
  1694. }
  1695. }
  1696. if (gridPromptList.length < 1) {
  1697. resolve(false)
  1698. return
  1699. }
  1700. if (!tipFlag) {
  1701. resolve(true)
  1702. return
  1703. }
  1704. // 提示用户(网格变绿)
  1705. gridPromptList.forEach((gridData) => {
  1706. if (gridData.gridNode && gridData.gridNode.children[0]) {
  1707. const sprite = gridData.gridNode.children[0].getComponent(Sprite);
  1708. if (sprite) {
  1709. sprite.color = this.usableColor;
  1710. }
  1711. }
  1712. // 用于恢复格子
  1713. this.gridColorList.push(gridData)
  1714. })
  1715. resolve(true)
  1716. })
  1717. }
  1718. moveIf(row: number, column: number, gridConfig: GridConfigData[]) {
  1719. let moveFlag = true
  1720. for (let i = 0; i < gridConfig.length; i++) {
  1721. const gridConfigData = gridConfig[i]
  1722. const gridI = row + gridConfigData.row
  1723. const gridJ = column + gridConfigData.column
  1724. // 边界判断
  1725. if (
  1726. gridI < 0 ||
  1727. gridI > this.rows - 1 ||
  1728. gridJ < 0 ||
  1729. gridJ > this.cols - 1
  1730. ) {
  1731. moveFlag = false
  1732. break
  1733. }
  1734. // 已用
  1735. else if (this.gridList[gridI][gridJ].status === CellState.FILLED) {
  1736. moveFlag = false
  1737. break
  1738. }
  1739. }
  1740. return moveFlag
  1741. }
  1742. // 复制整体网格
  1743. copyGridList() {
  1744. const gridList: GridData[][] = []
  1745. for (let rowIndex = 0; rowIndex < this.rows; rowIndex++) {
  1746. gridList.push([])
  1747. for (let columnIndex = 0; columnIndex < this.cols; columnIndex++) {
  1748. const gridData = this.gridList[rowIndex][columnIndex]
  1749. gridList[rowIndex].push({
  1750. name: gridData.name,
  1751. status: gridData.status,
  1752. gridNode: null,
  1753. row: gridData.row,
  1754. col: gridData.col,
  1755. type: gridData.type,
  1756. })
  1757. }
  1758. }
  1759. return gridList
  1760. }
  1761. gameOver() {
  1762. this.gameState = GameState.GAME_OVER
  1763. smc.game.GameModel.curScore = this.score;
  1764. oops.gui.open(UIID.GameOver);
  1765. const curLevel = smc.account.AccountModel.curLevel;
  1766. DCHandler.inst.reportData(3000501, curLevel);
  1767. }
  1768. //更新游戏分数
  1769. updateGameScore() {
  1770. this.lab_score.string = this.score.toString();
  1771. smc.game.GameModel.curScore = this.score;
  1772. if (this.score >= this.targetScore) {
  1773. this.gameState = GameState.GAME_PASS;
  1774. //防止第一关的时候出问题
  1775. if (this.guideNode.active) {
  1776. this.guideNode.active = false;
  1777. }
  1778. //弹出通关奖励界面
  1779. DCHandler.inst.reportData(3000505, smc.account.AccountModel.curLevel);
  1780. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  1781. ServerHandler.inst.getGameAwardInfo();
  1782. //如果
  1783. } else {
  1784. oops.gui.open(UIID.GamePass);
  1785. }
  1786. }
  1787. }
  1788. /**
  1789. * 清理网格的子节点
  1790. */
  1791. private clearGridChildren(gridNode: Node): void {
  1792. const children = gridNode.children.slice(); // 创建副本避免遍历时修改问题
  1793. children.forEach(node => node.destroy());
  1794. }
  1795. //========================打开其他界面和按钮逻辑=======================
  1796. /** 视图对象通过 ecs.Entity.remove(eliminateViewComp) 删除组件是触发组件处理自定义释放逻辑 */
  1797. reset() {
  1798. this.node.destroy();
  1799. }
  1800. //设置按钮
  1801. private btn_setting() {
  1802. oops.gui.open(UIID.Setting);
  1803. this.gameState = GameState.PAUSED;
  1804. DCHandler.inst.reportData(3000011);
  1805. }
  1806. //左边微信按钮
  1807. private btn_withdraw() {
  1808. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  1809. this.gameState = GameState.PAUSED;
  1810. ServerHandler.inst.getWechatTxInfo();
  1811. DCHandler.inst.reportData(3000006);
  1812. } else {
  1813. oops.gui.open(UIID.WechatWithdraw);
  1814. }
  1815. }
  1816. //顶部红包按钮
  1817. private btn_award() {
  1818. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  1819. this.gameState = GameState.PAUSED;
  1820. ServerHandler.inst.getHbTxInfo();
  1821. DCHandler.inst.reportData(3000007);
  1822. } else {
  1823. oops.gui.open(UIID.RedPacketWithdraw);
  1824. }
  1825. }
  1826. //二倍速按钮继续
  1827. private btn_double() {
  1828. // oops.gui.open(UIID.DoubleSpeed);
  1829. if (DeviceUtil.isNative && DeviceUtil.isAndroid) {
  1830. this.gameState = GameState.PAUSED;
  1831. ServerHandler.inst.getDoubleSpeedTime();
  1832. DCHandler.inst.reportData(3000010);
  1833. } else {
  1834. oops.gui.open(UIID.DoubleSpeed);
  1835. }
  1836. }
  1837. //自动放置,不让点击方块
  1838. private btn_auto(event: EventTouch) {
  1839. //这要有一个tweeen 放大缩小效果
  1840. // if (this.autoBtnNode) {
  1841. // tween(this.autoBtnNode)
  1842. // .to(0.1, { scale: v3(1.2, 1.2) })
  1843. // .call(() => {
  1844. // this.autoBtnNode.scale_x = 1;
  1845. // this.autoBtnNode.scale_y = 1;
  1846. // })
  1847. // .start();
  1848. // }
  1849. this.autoGame();
  1850. }
  1851. private autoGame() {
  1852. this.autoState = !this.autoState;
  1853. this.initButtonState(this.autoState);
  1854. if (this.autoState) {
  1855. DCHandler.inst.reportData(3000008);
  1856. this.executeAutoPlace();
  1857. this.autoFunction = this.executeAutoPlace;
  1858. this.schedule(this.autoFunction, 1.5);
  1859. this.autoNode.active = true;
  1860. } else {
  1861. //关闭
  1862. if (this.autoFunction) {
  1863. DCHandler.inst.reportData(3000009);
  1864. this.operateFlag = true;
  1865. this.unschedule(this.autoFunction);
  1866. this.autoFunction = null;
  1867. this.initButtonState(false);
  1868. this.autoState = false;
  1869. this.autoNode.active = false;
  1870. }
  1871. }
  1872. }
  1873. // 执行自动放置
  1874. executeAutoPlace() {
  1875. console.log("自动放置状态", this.autoState);
  1876. console.log("当前游戏状态", this.gameState);
  1877. if (!this.autoState || this.gameState !== GameState.PLAYING) {
  1878. return
  1879. }
  1880. const bestPlacement = this.findBestPlacement()
  1881. if (!bestPlacement) {
  1882. // 所有方块都无法放置,游戏结束
  1883. this.gameState = GameState.GAME_OVER;
  1884. this.gameOver()
  1885. return
  1886. }
  1887. // 执行放置
  1888. this.operateFlag = false;
  1889. this.placeBrickAtPosition(bestPlacement)
  1890. }
  1891. //寻找最佳位置
  1892. findBestPlacement() {
  1893. const placements = []
  1894. // 对每个方块计算所有可能的放置位置和分数
  1895. for (let brickIndex = 0; brickIndex < this.bricksList.length; brickIndex++) {
  1896. const brickData = this.bricksList[brickIndex]
  1897. // 检查不同旋转状态
  1898. let gridConfigs = [brickData.gridConfig]
  1899. let degrees = [brickData.deg]
  1900. // 如果可旋转,计算所有旋转状态
  1901. if (brickData.rotateFlag) {
  1902. for (let i = 1; i <= 3; i++) {
  1903. const next = this.nextGridRotate(
  1904. i === 1 ? brickData.gridConfig : gridConfigs[i - 1],
  1905. i === 1 ? brickData.deg : degrees[i - 1]
  1906. )
  1907. gridConfigs.push(next.gridConfig)
  1908. degrees.push(next.deg)
  1909. }
  1910. }
  1911. // 遍历所有网格位置
  1912. for (let rowIndex = 0; rowIndex < this.rows; rowIndex++) {
  1913. for (let columnIndex = 0; columnIndex < this.cols; columnIndex++) {
  1914. // 对每个旋转状态检查
  1915. for (let rotateIndex = 0; rotateIndex < gridConfigs.length; rotateIndex++) {
  1916. const currentGridConfig = gridConfigs[rotateIndex]
  1917. const currentDeg = degrees[rotateIndex]
  1918. // 检查是否可以放置
  1919. if (this.moveIf(rowIndex, columnIndex, currentGridConfig)) {
  1920. // 复制网格并模拟放置
  1921. const gridList = this.copyGridList()
  1922. currentGridConfig.forEach((gridConfigData) => {
  1923. const r = gridConfigData.row + rowIndex
  1924. const c = gridConfigData.column + columnIndex
  1925. gridList[r][c].status = CellState.FILLED
  1926. gridList[r][c].type = brickData.type;
  1927. })
  1928. // 检查是否可以消除,计算分数
  1929. const elimination = this.gridEliminateCheck(gridList)
  1930. let score = 0
  1931. if (elimination.gridEliminateList.length > 0) {
  1932. // 计算消除得分
  1933. for (let i = 1; i <= elimination.eliminateRowNum; i++) {
  1934. score += this.cols * i
  1935. }
  1936. for (let i = 1; i <= elimination.eliminateColumnNum; i++) {
  1937. score += this.rows * i
  1938. }
  1939. }
  1940. // 记录此放置选项
  1941. placements.push({
  1942. brickIndex,
  1943. brickData,
  1944. rowIndex,
  1945. columnIndex,
  1946. gridConfig: currentGridConfig, //这里有问题,拿到的和显示的不对
  1947. deg: currentDeg,
  1948. score,
  1949. canEliminate: elimination.gridEliminateList.length > 0
  1950. })
  1951. }
  1952. }
  1953. }
  1954. }
  1955. }
  1956. // 按优先级排序:最高分 > 有分数 > 没有分数但可放置
  1957. placements.sort((a, b) => {
  1958. // 首先按分数排序
  1959. if (a.score !== b.score) {
  1960. return b.score - a.score
  1961. }
  1962. // 其次按是否可消除排序
  1963. if (a.canEliminate !== b.canEliminate) {
  1964. return a.canEliminate ? -1 : 1
  1965. }
  1966. // 最后按照方块优先级排序(底部的方块优先)
  1967. return a.brickIndex - b.brickIndex
  1968. })
  1969. return placements.length > 0 ? placements[0] : null
  1970. }
  1971. // ... existing code ...
  1972. placeBrickAtPosition(placement: any) {
  1973. const brickData = placement.brickData
  1974. const index = this.bricksList.findIndex(data => data === brickData)
  1975. if (index === -1) {
  1976. console.error("无法找到要放置的方块:", brickData)
  1977. return
  1978. }
  1979. this.editingData.brickData = this.bricksList.splice(index, 1)[0];
  1980. // 应用旋转
  1981. if (brickData.deg !== placement.deg) {
  1982. brickData.gridConfig = placement.gridConfig
  1983. brickData.deg = placement.deg
  1984. tween(brickData.brickNode).to(0.1, { angle: placement.deg }).start()
  1985. }
  1986. // 构建对应网格列表--这里就有问题了,这算位置,有问题
  1987. this.editingData.gridList = [];
  1988. placement.gridConfig.forEach((gridConfigData: GridConfigData) => {
  1989. const r = gridConfigData.row + placement.rowIndex
  1990. const c = gridConfigData.column + placement.columnIndex
  1991. this.editingData.gridList.push(this.gridList[r][c])
  1992. })
  1993. // 计算移动位置(中点)
  1994. let centerPos = new Vec3(0, 0, 0)
  1995. let count = 0
  1996. for (const grid of this.editingData.gridList) {
  1997. if (grid.gridNode) {
  1998. const pos = grid.gridNode.getWorldPosition()
  1999. centerPos.add(pos)
  2000. count++
  2001. }
  2002. }
  2003. if (count > 0) {
  2004. centerPos.x /= count
  2005. centerPos.y /= count
  2006. centerPos.z /= count
  2007. }
  2008. const originPos = brickData.brickNode.getWorldPosition()
  2009. brickData.brickNode.setParent(this.moveNode)
  2010. brickData.brickNode.setWorldPosition(originPos);
  2011. //显示增加分数
  2012. // 动画放置方块
  2013. tween(brickData.brickNode)
  2014. .to(this.autoMoveTime, { worldPosition: centerPos })
  2015. .call(() => {
  2016. // ✅ 更新格子状态(像手动放置那样)
  2017. this.showScoreAnimation();
  2018. this.editingData.gridList.forEach(gridData => {
  2019. gridData.status = CellState.FILLED
  2020. gridData.type = brickData.type;
  2021. this.generateGrid(gridData)
  2022. })
  2023. // ✅ 销毁方块节点
  2024. brickData.brickNode.destroy()
  2025. // ✅ 补充新的砖块
  2026. this.addBrick(brickData.index)
  2027. // ✅ 消除检查逻辑保持和手动一致
  2028. this.scheduleOnce(() => {
  2029. this.gridEliminate().then(() => {
  2030. this.prompt(false).then((promptFlag) => {
  2031. if (!promptFlag) {
  2032. this.gameOver()
  2033. }
  2034. })
  2035. })
  2036. })
  2037. })
  2038. .start()
  2039. }
  2040. doubleSpeedOpenSuccess() {
  2041. //2倍速广告展示,页面展示,都会暂停游戏,
  2042. if (this.gameState !== GameState.PLAYING) {
  2043. return
  2044. }
  2045. if (this.callback) {
  2046. this.unschedule(this.callback);
  2047. }
  2048. oops.gui.toast("二倍速时长已增加3分钟~")
  2049. this.isDoubleSpeed = true;
  2050. this.doubleNum = 2;
  2051. //改变按钮时间
  2052. // let time = smc.game.GameModel.doubleSpeedTime;
  2053. this.doubleSpeedTime = this.doubleSpeedTime + smc.game.GameModel.doubleSpeedTime;
  2054. // this.doubleSpeedTime = 60;
  2055. if (this.doubleSpeedTime <= 0) {
  2056. return
  2057. }
  2058. if (!this.autoState) {
  2059. this.autoGame();
  2060. //改按钮状态
  2061. this.autoState = true;
  2062. this.initButtonState(this.autoState);
  2063. }
  2064. this.callback = function () {
  2065. if (this.gameState === GameState.PLAYING && this.autoState) {
  2066. this.doubleSpeedTime--
  2067. this.autoMoveTime = 0.25;
  2068. //修改剩余时间,秒格式化成时分10:59
  2069. const minutes = Math.floor(this.doubleSpeedTime / 60);
  2070. const seconds = this.doubleSpeedTime % 60;
  2071. const formattedTime = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
  2072. this.lab_doubleTime.string = formattedTime;
  2073. //时间到了
  2074. if (this.doubleSpeedTime <= 0) {
  2075. this.autoMoveTime = 0.4;
  2076. this.lab_doubleTime.string = "二倍速";
  2077. this.isDoubleSpeed = false;
  2078. this.doubleNum = 1;
  2079. //再打开继续二倍速页面
  2080. this.gameState = GameState.PAUSED;
  2081. oops.gui.open(UIID.KeepSpeed);
  2082. this.unschedule(this.callback);
  2083. }
  2084. }
  2085. if (!this.autoState && this.doubleSpeedTime) {
  2086. this.lab_doubleTime.string = "二倍速";
  2087. }
  2088. }
  2089. this.schedule(this.callback, 1);
  2090. }
  2091. //重新开始
  2092. private restartGame() {
  2093. if (this.gameState === GameState.READY) return;
  2094. this.initData();
  2095. this.setData();
  2096. this.reopenGrid();
  2097. this.initButtonState(this.autoState);
  2098. this.updateWelfarePoint();
  2099. }
  2100. //重新清除网格
  2101. private reopenGrid() {
  2102. for (let rowIndex = 0; rowIndex < this.rows; rowIndex++) {
  2103. for (let columnIndex = 0; columnIndex < this.cols; columnIndex++) {
  2104. this.gridList[rowIndex][columnIndex].status = CellState.EMPTY
  2105. this.generateGrid(this.gridList[rowIndex][columnIndex])
  2106. }
  2107. }
  2108. // 初始化方块
  2109. if (this.brickNode) {
  2110. if (this.brickNode) {
  2111. this.brickNode.destroyAllChildren();
  2112. }
  2113. }
  2114. this.bricksList.length = 0
  2115. for (let i = 1; i <= this.brickNum; i++) {
  2116. this.addBrick(i)
  2117. }
  2118. // 清除旋转数据
  2119. if (this.rotateNode) {
  2120. this.rotateNode.destroyAllChildren();
  2121. }
  2122. }
  2123. //===============初始化检查是否要打开福利界面====
  2124. private updateWelfarePoint() {
  2125. const showState = smc.game.GameModel.popupShow
  2126. if (!showState) {
  2127. //展示这些的时候,游戏要暂停
  2128. if (this.popupType != "") {
  2129. this.gameState = GameState.PAUSED;
  2130. }
  2131. switch (this.popupType) {
  2132. case "weal_1":
  2133. oops.gui.open(UIID.WarmReminder);
  2134. ServerHandler.inst.getGuideInfo();
  2135. break;
  2136. case "weal_2":
  2137. //打开福利二
  2138. oops.gui.open(UIID.WelfareTwo);
  2139. ServerHandler.inst.getGuideInfo();
  2140. break;
  2141. case "weal_3":
  2142. //打开福利三
  2143. oops.gui.open(UIID.WelfareThree);
  2144. break;
  2145. case "sign":
  2146. //打开福利三
  2147. oops.gui.open(UIID.ReservePopup);
  2148. break;
  2149. case "handlingCharge":
  2150. oops.gui.open(UIID.WechaatTransfer);
  2151. break;
  2152. }
  2153. smc.game.GameModel.popupShow = true;
  2154. }
  2155. }
  2156. btn_text() {
  2157. // const param = {
  2158. // "showReward": [
  2159. // {
  2160. // "propId": "1004",
  2161. // "propNum": 500
  2162. // },
  2163. // {
  2164. // "propId": "1005",
  2165. // "propNum": 200
  2166. // },
  2167. // {
  2168. // "propId": "1006",
  2169. // "propNum": 1
  2170. // }
  2171. // ],
  2172. // "levelProgress": {
  2173. // "nextProgress": 1,
  2174. // "levelInfoList": [
  2175. // {
  2176. // "level": 1,
  2177. // "eventType": "WITHDRAW_POINT",
  2178. // "withdraw": true
  2179. // },
  2180. // {
  2181. // "level": 4,
  2182. // "eventType": "WITHDRAW_POINT",
  2183. // "withdraw": false
  2184. // },
  2185. // {
  2186. // "level": 6,
  2187. // "eventType": "WITHDRAW_POINT",
  2188. // "withdraw": false
  2189. // },
  2190. // {
  2191. // "level": 8,
  2192. // "eventType": "WITHDRAW_POINT",
  2193. // "withdraw": false
  2194. // },
  2195. // {
  2196. // "level": 12,
  2197. // "eventType": "SIGN_POINT",
  2198. // "withdraw": false
  2199. // }
  2200. // ]
  2201. // }
  2202. // }
  2203. // let str = JSON.stringify(param);
  2204. // ServerHandler.inst.onDoubleSurprise(str);
  2205. // ServerHandler.inst.GetGuideInfo();
  2206. }
  2207. getRandomUniqueInts(count: number = 3): number[] {
  2208. let min: number = 0;
  2209. let max: number = 0;
  2210. const curLevel = smc.account.AccountModel.curLevel || 1;
  2211. if (curLevel < 5) {
  2212. return [curLevel]
  2213. } else if (curLevel >= 5 && curLevel <= 7) {
  2214. //三种基础色
  2215. min = 1;
  2216. max = 5;
  2217. } else if (curLevel >= 8 && curLevel <= 11) {
  2218. min = 6;
  2219. max = 12;
  2220. } else {
  2221. min = 1;
  2222. max = 12;
  2223. }
  2224. if (max - min + 1 < count) {
  2225. throw new Error(`区间 [${min}, ${max}] 无法提供 ${count} 个不重复整数`);
  2226. }
  2227. const pool: number[] = [];
  2228. for (let i = min; i <= max; i++) {
  2229. pool.push(i);
  2230. }
  2231. this.shuffle(pool);
  2232. return pool.slice(0, count);
  2233. }
  2234. // 洗牌算法(Fisher-Yates)
  2235. shuffle(arr: number[]) {
  2236. for (let i = arr.length - 1; i > 0; i--) {
  2237. const j = Math.floor(Math.random() * (i + 1));
  2238. [arr[i], arr[j]] = [arr[j], arr[i]];
  2239. }
  2240. }
  2241. //用导演直接冻结游戏或者恢复游戏
  2242. updateGameStatus() {
  2243. }
  2244. }