| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  | import type { DOStage } from "../models/DOStage" | 
					
						
							|  |  |  | import { config } from "../constants/config" | 
					
						
							|  |  |  | import { G_getMonthInfo } from "../models/DCManager" | 
					
						
							|  |  |  | import { EVENT_TYPES, EventManager } from "../models/EventManager" | 
					
						
							|  |  |  | import { StorageManager } from "../models/StorageManager" | 
					
						
							|  |  |  | import { UIManager } from "../models/UIManager" | 
					
						
							|  |  |  | import { Utility_CalculateScore, Utility_ConvertSecondToString } from "../utils/utility" | 
					
						
							|  |  |  | import { Block } from "./Block" | 
					
						
							|  |  |  | import { Candy } from "./Candy" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const { regClass, property } = Laya | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  | @regClass() | 
					
						
							|  |  |  | export class Stage extends Laya.Script { | 
					
						
							|  |  |  |   declare owner: Laya.Box | 
					
						
							| 
									
										
										
										
											2025-05-17 17:54:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   @property(Laya.Box) | 
					
						
							|  |  |  |   public btn_back: Laya.Box | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   @property(Laya.Box) | 
					
						
							|  |  |  |   public btn_new: Laya.Box | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   @property(Laya.Button) | 
					
						
							|  |  |  |   public btn_pause: Laya.Button | 
					
						
							| 
									
										
										
										
											2025-05-26 19:57:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   @property(Laya.Label) | 
					
						
							|  |  |  |   public label_score: Laya.Label | 
					
						
							| 
									
										
										
										
											2025-05-26 19:57:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   private score_last: number | 
					
						
							|  |  |  |   private score_current: number | 
					
						
							|  |  |  |   private score_step: number | 
					
						
							|  |  |  |   private score_animation_wait_frame = 0 | 
					
						
							|  |  |  |   @property(Laya.Label) | 
					
						
							|  |  |  |   public label_mistake: Laya.Label | 
					
						
							| 
									
										
										
										
											2025-05-09 19:16:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   @property(Laya.Label) | 
					
						
							|  |  |  |   public label_name: Laya.Label | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property(Laya.Label) | 
					
						
							|  |  |  |   public label_time: Laya.Label | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property(Laya.Box) | 
					
						
							|  |  |  |   public obj_blocks: Laya.Box | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private blocks: Array<Block> = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property(Laya.Box) | 
					
						
							|  |  |  |   public obj_candys: Laya.Box | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property(Laya.Box) | 
					
						
							|  |  |  |   public obj_candy_labels: Laya.Box | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private candys: Array<Candy> = [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property(Laya.Button) | 
					
						
							|  |  |  |   public btn_undo: Laya.Button | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property(Laya.Button) | 
					
						
							|  |  |  |   public btn_erase: Laya.Button | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @property(Laya.Button) | 
					
						
							|  |  |  |   public btn_note: Laya.Button | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private btn_note_normal: Laya.Box | 
					
						
							|  |  |  |   private btn_note_checked: Laya.Box | 
					
						
							|  |  |  |   private label_note: Laya.Label | 
					
						
							|  |  |  |   @property(Laya.Button) | 
					
						
							|  |  |  |   public btn_hint: Laya.Button | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private btn_hint_normal: Laya.Box | 
					
						
							|  |  |  |   private btn_hint_ad: Laya.Box | 
					
						
							|  |  |  |   private btn_hint_label: Laya.Label | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private data: DOStage | 
					
						
							|  |  |  |   private selectedBlock: Block | 
					
						
							|  |  |  |   private paused: boolean | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private static _instance: Stage | 
					
						
							|  |  |  |   onAwake(): void { | 
					
						
							|  |  |  |     Stage._instance = this | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this.btn_back.on(Laya.Event.CLICK, this, () => { | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |       if (this.data.get_stageType() === config.STAGE_TYPE.MAIN) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         UIManager.getInstance().loadHomeUI() | 
					
						
							|  |  |  |         UIManager.getInstance().closeStageUI() | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         UIManager.getInstance().loadDCUI() | 
					
						
							|  |  |  |         UIManager.getInstance().closeStageUI() | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (this.btn_new) { | 
					
						
							|  |  |  |       this.btn_new.on(Laya.Event.CLICK, this, () => { | 
					
						
							|  |  |  |         const user = StorageManager.getInstance().getUser() | 
					
						
							|  |  |  |         user.update_progress(this.data.get_difficulty(), this.data.get_stageIndex() + 1)// 主线关卡更新难度进度
 | 
					
						
							|  |  |  |         StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, this.data.get_difficulty(), this.data.get_difficulty()) | 
					
						
							|  |  |  |         UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID) | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2025-05-19 20:58:15 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     this.btn_pause.on(Laya.Event.CLICK, this, () => { | 
					
						
							|  |  |  |       UIManager.getInstance().loadGamePauseUI(this.data) | 
					
						
							|  |  |  |     }) | 
					
						
							| 
									
										
										
										
											2025-05-29 15:37:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let XGroup = 0 | 
					
						
							|  |  |  |     let YGroup = 0 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |     for (let i = 0; i < this.obj_blocks.numChildren; i++) { | 
					
						
							| 
									
										
										
										
											2025-05-29 15:37:45 +08:00
										 |  |  |       YGroup = i | 
					
						
							|  |  |  |       const ibox = this.obj_blocks.getChildAt(i) | 
					
						
							|  |  |  |       for (let j = 0; j < ibox.numChildren; j++) { | 
					
						
							|  |  |  |         XGroup = j | 
					
						
							|  |  |  |         const jbox = ibox.getChildAt(j) | 
					
						
							|  |  |  |         const VBox = jbox.getChildByName("VBox") | 
					
						
							|  |  |  |         for (let k = 0; k < VBox.numChildren; k++) { | 
					
						
							|  |  |  |           const kbox = VBox.getChildAt(k) | 
					
						
							|  |  |  |           for (let l = 0; l < kbox.numChildren; l++) { | 
					
						
							|  |  |  |             const block = kbox.getChildAt(l).getComponent(Block) | 
					
						
							|  |  |  |             this.blocks.push(block) | 
					
						
							|  |  |  |             const XIndex = j * 3 + l | 
					
						
							|  |  |  |             const YIndex = i * 3 + k | 
					
						
							|  |  |  |             block.onInit(XIndex, YIndex, XGroup, YGroup, this, this.onClickBlock) | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-05-13 20:31:44 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |     for (let i = 0; i < this.obj_candys.numChildren; i++) { | 
					
						
							|  |  |  |       const hbox = this.obj_candys.getChildAt(i) | 
					
						
							|  |  |  |       const l_hbox = this.obj_candy_labels.getChildAt(i) | 
					
						
							|  |  |  |       for (let j = 0; j < hbox.numChildren; j++) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         const candy = hbox.getChildAt(j).getComponent(Candy) | 
					
						
							|  |  |  |         this.candys.push(candy) | 
					
						
							|  |  |  |         const box = l_hbox.getChildAt(j) as Laya.Box | 
					
						
							|  |  |  |         candy.onInit(box, this, this.onClickCandy) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-05-22 19:12:00 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-13 14:17:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     this.btn_undo.on(Laya.Event.CLICK, this, this.onClickUndo) | 
					
						
							|  |  |  |     this.btn_erase.on(Laya.Event.CLICK, this, this.onClickErase) | 
					
						
							|  |  |  |     this.btn_note.on(Laya.Event.CLICK, this, this.onClickNote) | 
					
						
							|  |  |  |     this.btn_note_normal = this.btn_note.getChildByName("normal") as Laya.Box | 
					
						
							|  |  |  |     this.btn_note_checked = this.btn_note.getChildByName("checked") as Laya.Box | 
					
						
							|  |  |  |     this.label_note = this.btn_note.getChildByName("label") as Laya.Label | 
					
						
							|  |  |  |     this.btn_hint.on(Laya.Event.CLICK, this, this.onClickHint) | 
					
						
							|  |  |  |     this.btn_hint_normal = this.btn_hint.getChildByName("Image").getChildByName("normal") as Laya.Box | 
					
						
							|  |  |  |     this.btn_hint_ad = this.btn_hint.getChildByName("Image").getChildByName("ad") as Laya.Box | 
					
						
							|  |  |  |     this.btn_hint_label = this.btn_hint.getChildByName("Image").getChildByName("normal").getChildByName("label") as Laya.Label | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     EventManager.getInstance().RegisterEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, Stage.EventUpdateMistake) | 
					
						
							|  |  |  |     EventManager.getInstance().RegisterEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, Stage.EventUpdatePause) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onDestroy(): void { | 
					
						
							|  |  |  |     EventManager.getInstance().UnregisterEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, Stage.EventUpdateMistake) | 
					
						
							|  |  |  |     EventManager.getInstance().UnregisterEvent(EVENT_TYPES.NOT_UPDATE_PAUSE, Stage.EventUpdatePause) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |   public static EventUpdateMistake(): void { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     if (Stage._instance) { | 
					
						
							|  |  |  |       Stage._instance.onUpdateMistake() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-05-21 11:24:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   public static EventUpdatePause(arg: any): void { | 
					
						
							|  |  |  |     if (Stage._instance) { | 
					
						
							|  |  |  |       Stage._instance.paused = arg | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-05-26 19:57:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   public onLoadStage(doStage: DOStage): void { | 
					
						
							|  |  |  |     this.data = doStage | 
					
						
							|  |  |  |     this.paused = false | 
					
						
							| 
									
										
										
										
											2025-05-16 21:10:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     if (config.H_SCREEN) { | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |       this.btn_back.visible = this.data.get_stageType() === config.STAGE_TYPE.DC | 
					
						
							|  |  |  |       this.btn_new.visible = this.data.get_stageType() === config.STAGE_TYPE.MAIN | 
					
						
							| 
									
										
										
										
											2025-05-13 14:17:33 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     this.score_last = 0 | 
					
						
							|  |  |  |     this.score_current = 0 | 
					
						
							|  |  |  |     this.onUpdateScore() | 
					
						
							|  |  |  |     this.score_last = this.score_current | 
					
						
							|  |  |  |     this.label_score.text = `Score: ${this.score_last}` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this.label_name.text = this.data.get_stageName() | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |     if (this.data.get_stageType() === config.STAGE_TYPE.MAIN && config.H_SCREEN) | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       this.label_name.text = "" | 
					
						
							|  |  |  |     this.onUpdateMistake() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this.label_time.text = Utility_ConvertSecondToString(this.data.get_duration()) | 
					
						
							|  |  |  |     Laya.timer.clearAll(this) | 
					
						
							|  |  |  |     Laya.timer.loop(1000, this, () => { | 
					
						
							|  |  |  |       if (this.paused) { | 
					
						
							|  |  |  |         return | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       let last = this.data.get_duration() | 
					
						
							|  |  |  |       last++ | 
					
						
							|  |  |  |       this.data.set_duration(last) | 
					
						
							|  |  |  |       this.label_time.text = Utility_ConvertSecondToString(last) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const blocks = doStage.get_blocks() | 
					
						
							|  |  |  |     for (let i = 0; i < blocks.length; i++) { | 
					
						
							|  |  |  |       const doBlock = blocks[i] | 
					
						
							|  |  |  |       const block = this.blocks[i] | 
					
						
							|  |  |  |       block.setBlockColor(config.BLOCK_COLOR.WHITE) | 
					
						
							|  |  |  |       block.setBlock(doBlock) | 
					
						
							|  |  |  |       block.setTipsBgColor(false) | 
					
						
							|  |  |  |       block.setSelected(false) | 
					
						
							| 
									
										
										
										
											2025-05-27 14:59:33 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     this.onUpdateCandys() | 
					
						
							|  |  |  |     this.onClickNote(null) | 
					
						
							|  |  |  |     this.onUpdateHintStatus() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     this.selectedBlock = this.blocks[this.data.get_select_index()] | 
					
						
							|  |  |  |     this.onApplyBlock(this.selectedBlock) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onUpdateScore(): void { | 
					
						
							|  |  |  |     let score = 0 | 
					
						
							|  |  |  |     const blocks = this.data.get_blocks() | 
					
						
							|  |  |  |     for (let i = 0; i < blocks.length; i++) { | 
					
						
							|  |  |  |       score += blocks[i].get_score() | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 20:12:56 +08:00
										 |  |  |     if (this.score_current !== score) { // 分数发生变化
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       this.score_current = score | 
					
						
							|  |  |  |       this.score_step = Math.ceil((this.score_current - this.score_last) / 24) | 
					
						
							|  |  |  |       if (this.score_current > this.score_last) | 
					
						
							|  |  |  |         this.score_animation_wait_frame = 54 | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         this.score_animation_wait_frame = 0 | 
					
						
							|  |  |  |       this.data.set_score(score) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onLateUpdate(): void { | 
					
						
							|  |  |  |     this.score_animation_wait_frame-- | 
					
						
							|  |  |  |     if (this.score_animation_wait_frame < 0) | 
					
						
							|  |  |  |       this.score_animation_wait_frame = 0 | 
					
						
							|  |  |  |     if (this.score_animation_wait_frame <= 0) { | 
					
						
							| 
									
										
										
										
											2025-05-28 20:12:56 +08:00
										 |  |  |       if (this.score_current !== this.score_last) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         if (this.score_current > this.score_last) { | 
					
						
							|  |  |  |           this.score_last += this.score_step | 
					
						
							|  |  |  |           if (this.score_last > this.score_current) | 
					
						
							|  |  |  |             this.score_last = this.score_current | 
					
						
							|  |  |  |           this.label_score.text = `Score: ${this.score_last}` | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           this.label_score.text = `Score: ${this.score_current}` | 
					
						
							|  |  |  |           this.score_last = this.score_current | 
					
						
							| 
									
										
										
										
											2025-05-27 14:59:33 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-05-13 14:17:33 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-05-13 14:17:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   onUpdateMistake(): void { | 
					
						
							| 
									
										
										
										
											2025-05-29 10:25:13 +08:00
										 |  |  |     this.label_mistake.text = `Mistakes: ${this.data.get_mistake()} / ${config.MISTAKE_MAX}` | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   onSetBlock(block: Block, animated: boolean = false): void { | 
					
						
							|  |  |  |     // 全部格子还原
 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |     for (let i = 0; i < this.blocks.length; i++) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       this.blocks[i].setBlockColor(config.BLOCK_COLOR.WHITE) | 
					
						
							|  |  |  |       this.blocks[i].setTipsBgColor(false) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // 相关格子置灰
 | 
					
						
							|  |  |  |     const relateds = this.findRelatedBlocks(block) | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |     for (let i = 0; i < relateds.length; i++) | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       relateds[i].setBlockColor(config.BLOCK_COLOR.GREY) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // 选中空白格子
 | 
					
						
							|  |  |  |     if (block.getData().get_show() <= 0) { | 
					
						
							|  |  |  |       block.setBlockColor(config.BLOCK_COLOR.BLUE) | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |       const sameNumbers = this.findSameNumberBlocks(block)// 相同数字的格子
 | 
					
						
							|  |  |  |       for (let i = 0; i < sameNumbers.length; i++) { | 
					
						
							|  |  |  |         sameNumbers[i].setBlockColor(config.BLOCK_COLOR.BLUE, 0.4) | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |       const sameNotes = this.findSameNoteBlocks(block)// 相同数字的铅笔格子
 | 
					
						
							|  |  |  |       for (let i = 0; i < sameNotes.length; i++) { | 
					
						
							|  |  |  |         sameNotes[i].setTipsBgColor(true, block.getData().get_show(), config.BLOCK_COLOR.BLUE, 0.4) | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |       // 正确
 | 
					
						
							|  |  |  |       if (block.getData().get_checked()) { | 
					
						
							|  |  |  |         block.setBlockColor(config.BLOCK_COLOR.BLUE) | 
					
						
							|  |  |  |       } else { // 错误
 | 
					
						
							|  |  |  |         if (animated) { // 填数状态播放闪动效果
 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |           for (let i = 0; i < relateds.length; i++) { // 相关且数字相同
 | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |             if (relateds[i].getData().get_show() === block.getData().get_show()) { // 播放变红动效
 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:12:56 +08:00
										 |  |  |               if (relateds[i].getData().get_index() !== block.getData().get_index()) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |                 // relateds[i].setBlockColor(config.BLOCK_COLOR.WHITE)
 | 
					
						
							|  |  |  |                 relateds[i].setBlockColor(config.BLOCK_COLOR.RED, 0.4, true, config.BLOCK_COLOR.GREY, 1) | 
					
						
							|  |  |  |               } | 
					
						
							| 
									
										
										
										
											2025-05-15 21:36:03 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |           } | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |           for (let i = 0; i < relateds.length; i++) { // 相关且数字相同
 | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |             if (relateds[i].getData().get_show() === block.getData().get_show()) { // 直接变红
 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:12:56 +08:00
										 |  |  |               if (relateds[i].getData().get_index() !== block.getData().get_index()) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |                 relateds[i].setBlockColor(config.BLOCK_COLOR.RED, 0.4) | 
					
						
							|  |  |  |               } | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         block.setBlockColor(config.BLOCK_COLOR.RED) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onApplyBlock(block: Block): void { | 
					
						
							|  |  |  |     this.selectedBlock.setSelected(false) | 
					
						
							|  |  |  |     this.selectedBlock = block | 
					
						
							|  |  |  |     this.selectedBlock.setSelected(true) | 
					
						
							|  |  |  |     this.onSetBlock(this.selectedBlock) | 
					
						
							|  |  |  |     this.data.set_select_index(this.selectedBlock.getData().get_index()) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onClickBlock(evt: Laya.Event): void { | 
					
						
							|  |  |  |     const block = evt.target.getComponent(Block) | 
					
						
							|  |  |  |     this.onApplyBlock(block) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |   onClickUndo(): void { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     const undo = this.data.pop_undo() | 
					
						
							|  |  |  |     if (undo) { | 
					
						
							|  |  |  |       console.log("onClickUndo>>>>", JSON.stringify(undo)) | 
					
						
							|  |  |  |       this.selectedBlock = this.blocks[undo.index] | 
					
						
							|  |  |  |       this.onApplyBlock(this.selectedBlock) | 
					
						
							|  |  |  |       if (undo.notes && undo.notes.length > 0) { | 
					
						
							|  |  |  |         this.selectedBlock.setNotes(undo.notes) | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         this.selectedBlock.setShowNumber(undo.show, 0) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |       this.onUpdateScore() | 
					
						
							|  |  |  |       const undos = this.data.get_undos() | 
					
						
							|  |  |  |       if (undos.length > 0) { | 
					
						
							|  |  |  |         const last = undos[undos.length - 1] | 
					
						
							|  |  |  |         this.selectedBlock = this.blocks[last.index] | 
					
						
							|  |  |  |         this.onApplyBlock(this.selectedBlock) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-05-29 18:01:54 +08:00
										 |  |  |       this.onSetBlock(this.selectedBlock) | 
					
						
							| 
									
										
										
										
											2025-05-16 21:10:37 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |   onClickErase(): void { | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |     if (this.selectedBlock.getData().get_checked() === false) { // 未完成且有数字或者笔记才可以使用橡皮
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       const show = this.selectedBlock.getData().get_show() | 
					
						
							|  |  |  |       const notes = this.selectedBlock.getData().get_notes() | 
					
						
							|  |  |  |       if (show > 0 || notes.length > 0) { | 
					
						
							|  |  |  |         this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes) | 
					
						
							|  |  |  |         this.selectedBlock.setShowNumber(0, 0) | 
					
						
							|  |  |  |         this.onUpdateScore() | 
					
						
							|  |  |  |         this.onSetBlock(this.selectedBlock) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   } | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   onClickNote(evt: Laya.Event): void { | 
					
						
							| 
									
										
										
										
											2025-05-28 20:12:56 +08:00
										 |  |  |     if (evt !== null) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       this.data.set_note_open(!this.data.get_note_open()) | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |     this.btn_note_normal.visible = this.data.get_note_open() === false | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     this.btn_note_checked.visible = this.data.get_note_open() | 
					
						
							|  |  |  |     this.label_note.color = this.data.get_note_open() ? "#1d5cdc" : "#545962" | 
					
						
							|  |  |  |     for (let i = 0; i < this.candys.length; i++) { | 
					
						
							|  |  |  |       this.candys[i].setNoteStatus(this.data.get_note_open()) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |   onClickHint(): void { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     const hint = this.data.get_hint() | 
					
						
							|  |  |  |     if (hint > 0) { | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |       if (this.selectedBlock.getData().get_checked() === false) { // 当前选中的格子没有完成
 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |         const correct = this.selectedBlock.getData().get_correct() | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         this.onApplyCandy(correct, true) | 
					
						
							|  |  |  |         this.data.set_hint(hint - 1) | 
					
						
							|  |  |  |         this.onUpdateHintStatus() | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         const list: Array<Block> = [] | 
					
						
							|  |  |  |         for (let i = 0; i < this.blocks.length; i++) { | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |           const block = this.blocks[i] | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |           if (block.getData().get_checked() === false) | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |             list.push(block) | 
					
						
							| 
									
										
										
										
											2025-05-12 21:18:27 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         if (list.length > 0) { | 
					
						
							|  |  |  |           const random = Math.random() | 
					
						
							|  |  |  |           let index = Math.round(random * list.length) | 
					
						
							|  |  |  |           if (index >= list.length) | 
					
						
							|  |  |  |             index = list.length - 1 | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |           const block = list[index] | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |           this.onApplyBlock(block) | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |           const correct = block.getData().get_correct() | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |           this.onApplyCandy(correct, true) | 
					
						
							|  |  |  |           this.data.set_hint(hint - 1) | 
					
						
							|  |  |  |           this.onUpdateHintStatus() | 
					
						
							| 
									
										
										
										
											2025-05-13 20:31:44 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       } | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       // 这里播放广告 现在每个广告每次点击+9
 | 
					
						
							|  |  |  |       this.data.set_hint(9) | 
					
						
							|  |  |  |       this.onUpdateHintStatus() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onUpdateHintStatus(): void { | 
					
						
							|  |  |  |     const hint = this.data.get_hint() | 
					
						
							|  |  |  |     this.btn_hint_normal.visible = hint > 0 | 
					
						
							|  |  |  |     this.btn_hint_ad.visible = hint <= 0 | 
					
						
							|  |  |  |     this.btn_hint_label.text = hint.toString() | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public onApplyCandy(showNumber: number, hint: boolean): void { | 
					
						
							|  |  |  |     const show = this.selectedBlock.getData().get_show() | 
					
						
							|  |  |  |     const notes = this.selectedBlock.getData().get_notes() | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |     if (this.selectedBlock.getData().get_checked() === false) { | 
					
						
							|  |  |  |       if (this.data.get_note_open() && hint === false) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         const relateds = this.findRelatedBlocks(this.selectedBlock) | 
					
						
							|  |  |  |         let find = false | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |         for (let i = 0; i < relateds.length; i++) { | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |           if (relateds[i].getData().get_show() === showNumber) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |             find = true | 
					
						
							|  |  |  |             break | 
					
						
							|  |  |  |           } | 
					
						
							| 
									
										
										
										
											2025-05-15 21:36:03 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |         if (find === false) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |           this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes) | 
					
						
							|  |  |  |           this.selectedBlock.addNoteNumber(showNumber) | 
					
						
							|  |  |  |           this.onSetBlock(this.selectedBlock) | 
					
						
							|  |  |  |         } else { | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |           for (let i = 0; i < relateds.length; i++) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |             const obj = relateds[i] | 
					
						
							| 
									
										
										
										
											2025-05-28 20:12:56 +08:00
										 |  |  |             if (obj.getData().get_show() === showNumber && obj.getData().get_index() !== this.selectedBlock.getData().get_index()) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |               obj.setFadeAnimation() | 
					
						
							| 
									
										
										
										
											2025-05-16 15:52:18 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2025-05-16 15:52:18 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       } else { | 
					
						
							|  |  |  |         this.data.add_undo(this.selectedBlock.getData().get_index(), show, notes) | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |         if (this.selectedBlock.getData().get_show() === showNumber) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |           this.selectedBlock.setShowNumber(0, 0) | 
					
						
							|  |  |  |           this.onSetBlock(this.selectedBlock) | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |           let blockScore = 0 | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |           if (hint === false) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |             const duration = this.data.get_duration() - this.data.get_last_hit_time() | 
					
						
							|  |  |  |             blockScore = Utility_CalculateScore(this.data.get_difficulty(), duration) | 
					
						
							|  |  |  |           } | 
					
						
							|  |  |  |           const b = this.selectedBlock.setShowNumber(showNumber, blockScore) | 
					
						
							|  |  |  |           this.onUpdateScore() | 
					
						
							|  |  |  |           this.onSetBlock(this.selectedBlock, true) | 
					
						
							|  |  |  |           if (b) { | 
					
						
							|  |  |  |             this.data.set_last_hit_time(this.data.get_duration()) | 
					
						
							|  |  |  |             const user = StorageManager.getInstance().getUser() | 
					
						
							|  |  |  |             let all = 0 | 
					
						
							|  |  |  |             let finished = 0 | 
					
						
							|  |  |  |             const blocks = this.data.get_blocks() | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |             for (let i = 0; i < blocks.length; i++) { | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |               if (blocks[i].get_preset() === false) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |                 all++ | 
					
						
							|  |  |  |                 if (blocks[i].get_checked()) { | 
					
						
							|  |  |  |                   finished++ | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |               } | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |             const progress = finished / all | 
					
						
							|  |  |  |             user.update_stage_done(this.data.get_stageID(), progress)// 更新关卡完成进度
 | 
					
						
							|  |  |  |             if (this.getIsComplete()) { | 
					
						
							|  |  |  |               console.log("完成关卡", finished, all, progress) | 
					
						
							|  |  |  |               this.paused = true | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |               if (this.data.get_stageType() === config.STAGE_TYPE.MAIN) { // 主线关卡更新难度进度
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |                 user.update_progress(this.data.get_difficulty(), this.data.get_stageIndex() + 1) | 
					
						
							|  |  |  |                 UIManager.getInstance().loadGameDoneUI(true, this.data) | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |               } else if (this.data.get_stageType() === config.STAGE_TYPE.DC) { // dc
 | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |                 if (progress >= 1) { // 完成每日挑战关卡检查是否或者当月奖杯
 | 
					
						
							|  |  |  |                   const now = new Date() | 
					
						
							|  |  |  |                   const nowYear = now.getFullYear() | 
					
						
							|  |  |  |                   const nowMonth = now.getMonth() + 1 | 
					
						
							|  |  |  |                   const doneCount = user.get_doneCountByDate(nowYear, nowMonth) | 
					
						
							|  |  |  |                   let dayCount = 0 | 
					
						
							|  |  |  |                   const info = G_getMonthInfo(nowYear, nowMonth) | 
					
						
							|  |  |  |                   if (info) | 
					
						
							|  |  |  |                     dayCount = info.dayCount | 
					
						
							|  |  |  |                   console.log("dc完成信息>>>>>>>>>>>>>>>", nowYear, nowMonth, doneCount, dayCount) | 
					
						
							|  |  |  |                   if (doneCount >= dayCount) { // 当月每日挑战全部完成
 | 
					
						
							|  |  |  |                     user.add_trophy_record(nowYear, nowMonth, now.getDate()) | 
					
						
							|  |  |  |                   } | 
					
						
							| 
									
										
										
										
											2025-05-12 21:18:27 +08:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |                 UIManager.getInstance().loadGameDoneUI(false, this.data) | 
					
						
							|  |  |  |               } | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           } else { // 失败
 | 
					
						
							|  |  |  |             this.data.set_mistake(this.data.get_mistake() + 1) | 
					
						
							|  |  |  |             this.onUpdateMistake() | 
					
						
							|  |  |  |             if (this.data.get_mistake() >= config.MISTAKE_MAX) { | 
					
						
							|  |  |  |               console.log("关卡失败") | 
					
						
							|  |  |  |               this.paused = true | 
					
						
							|  |  |  |               UIManager.getInstance().loadGameOverUI(this.data) | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |           } | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         this.onUpdateCandys() | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public onClickCandy(evt: Laya.Event): void { | 
					
						
							|  |  |  |     const candy = evt.target.getComponent(Candy) | 
					
						
							|  |  |  |     this.onApplyCandy(candy.get_show(), false) | 
					
						
							|  |  |  |     const sp = evt.target.getChildByName("Sprite") as Laya.Sprite | 
					
						
							|  |  |  |     Laya.Tween.to(sp, { scaleX: 0.9, scaleY: 0.9 }, 100, Laya.Ease.linearIn) | 
					
						
							|  |  |  |     Laya.Tween.to(sp, { scaleX: 1, scaleY: 1 }, 100, Laya.Ease.linearInOut, null, 100) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onKeyUp(evt: Laya.Event): void { | 
					
						
							|  |  |  |     const n = Number(evt.key) | 
					
						
							|  |  |  |     if (n && n > 0) { | 
					
						
							|  |  |  |       this.onApplyCandy(n, false) | 
					
						
							| 
									
										
										
										
											2025-05-12 21:18:27 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   onUpdateCandys(): void { | 
					
						
							|  |  |  |     const list: Map<number, number> = new Map() | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |     for (let i = 1; i <= 9; i++) | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       list.set(i, 0) | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |     for (let i = 0; i < this.blocks.length; i++) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       const block = this.blocks[i] | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |       if (block.getData().get_checked() === false) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         const correct = block.getData().get_correct() | 
					
						
							|  |  |  |         list.set(correct, list.get(correct) + 1) | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2025-05-16 21:10:37 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 20:29:24 +08:00
										 |  |  |     for (let i = 0; i < this.candys.length; i++) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |       const candy = this.candys[i] | 
					
						
							|  |  |  |       const show = i + 1 | 
					
						
							|  |  |  |       const left = list.get(show) | 
					
						
							|  |  |  |       candy.setCandy(show, left) | 
					
						
							| 
									
										
										
										
											2025-05-12 21:18:27 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   findRelatedBlocks(obj: Block): Array<Block> { | 
					
						
							|  |  |  |     const list: Array<Block> = [] | 
					
						
							|  |  |  |     for (let i = 0; i < this.blocks.length; i++) { | 
					
						
							|  |  |  |       const block = this.blocks[i] | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |       if (block.XIndex === obj.XIndex) | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         list.push(block) | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |       else if (block.YIndex === obj.YIndex) | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         list.push(block) | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |       else if (block.XGroup === obj.XGroup && block.YGroup === obj.YGroup) | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         list.push(block) | 
					
						
							| 
									
										
										
										
											2025-05-09 19:10:40 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |     return list | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   findSameNumberBlocks(obj: Block): Array<Block> { | 
					
						
							|  |  |  |     const list: Array<Block> = [] | 
					
						
							|  |  |  |     for (let i = 0; i < this.blocks.length; i++) { | 
					
						
							|  |  |  |       const block = this.blocks[i] | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |       if (block.getData().get_show() === obj.getData().get_show()) | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         list.push(block) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return list | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   findSameNoteBlocks(obj: Block): Array<Block> { | 
					
						
							|  |  |  |     const list: Array<Block> = [] | 
					
						
							|  |  |  |     for (let i = 0; i < this.blocks.length; i++) { | 
					
						
							|  |  |  |       const block = this.blocks[i] | 
					
						
							|  |  |  |       const note_numbers = block.getData().get_notes() | 
					
						
							| 
									
										
										
										
											2025-05-28 19:07:37 +08:00
										 |  |  |       const find = note_numbers.indexOf(obj.getData().get_show()) | 
					
						
							|  |  |  |       if (find >= 0) | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         list.push(block) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return list | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   getIsComplete(): boolean { | 
					
						
							|  |  |  |     let b = true | 
					
						
							|  |  |  |     for (let i = 1; i < this.blocks.length; i++) { | 
					
						
							|  |  |  |       const block = this.blocks[i] | 
					
						
							| 
									
										
										
										
											2025-05-28 19:15:32 +08:00
										 |  |  |       if (block.getData().get_checked() === false) { | 
					
						
							| 
									
										
										
										
											2025-05-28 18:47:51 +08:00
										 |  |  |         b = false | 
					
						
							|  |  |  |         break | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return b | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } |