完善hint功能

This commit is contained in:
2025-05-16 15:52:18 +08:00
parent 67c2201eaf
commit ed7f125c43
6 changed files with 76 additions and 34 deletions

View File

@@ -46,6 +46,7 @@ export class Stage extends Laya.Script {
public btn_hint: Laya.Box;
private btn_hint_normal: Laya.Box
private btn_hint_ad: Laya.Box
private btn_hint_label: Laya.Label
private selectedBlock: Block;
private data: DOStage;
@@ -89,6 +90,9 @@ export class Stage extends Laya.Script {
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.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
this.selectedBlock = null;
}
@@ -128,6 +132,7 @@ export class Stage extends Laya.Script {
}
this.onClickNote(null)
this.onUpdateHintStatus()
}
onUpdateScore(): void {
@@ -229,31 +234,49 @@ export class Stage extends Laya.Script {
}
onClickHint(evt: Laya.Event): void {
if (this.selectedBlock && this.selectedBlock.getData().get_checked() == false) {//当前选中的格子没有完成
var correct = this.selectedBlock.getData().get_correct()
var candy = this.candys[correct-1]
this.onApplyCandy(candy)
}
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]
this.selectedBlock = block
var correct = block.getData().get_correct()
var hint = this.data.get_hint()
if (hint > 0) {
if (this.selectedBlock && this.selectedBlock.getData().get_checked() == false) {//当前选中的格子没有完成
var correct = this.selectedBlock.getData().get_correct()
var candy = this.candys[correct-1]
this.onApplyCandy(candy)
this.data.set_hint(hint-1)
this.onUpdateHintStatus()
}
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]
this.selectedBlock = block
var correct = block.getData().get_correct()
var candy = this.candys[correct-1]
this.onApplyCandy(candy)
this.data.set_hint(hint-1)
this.onUpdateHintStatus()
}
}
}
else {
//这里播放广告 现在每个广告每次点击+9
this.data.set_hint(9)
this.onUpdateHintStatus()
}
}
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()
}
public onApplyCandy(candy: Candy): void {
if (this.selectedBlock && this.selectedBlock.getData().get_checked() == false) {