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