完善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

@@ -128,6 +128,14 @@ export class DOStage {
this.data.note_open = note_open
StorageManager.getInstance().onChanged()
}
public get_hint(): number {
return this.data.hint
}
public set_hint(hint: number): void {//提示
this.data.hint = hint
StorageManager.getInstance().onChanged()
}
//====================================持久化数据
public get_blocks(): Array<DOBlock> {

View File

@@ -35,7 +35,7 @@ export class StorageManager {
this.stageMap.set(stageID, dataStage)
}
else {
dataStage = {mistake: 0, difficulty: config.DIFFICULTY_TYPE.Easy, duration: 0, note_open: false, blocks: new Array(), candys: new Array()}
dataStage = {mistake: 0, difficulty: config.DIFFICULTY_TYPE.Easy, duration: 0, note_open: false, hint: 2, blocks: new Array(), candys: new Array()}
this.stageMap.set(stageID, dataStage)
}
}

View File

@@ -21,6 +21,7 @@ export interface DataStage {
difficulty: number,
duration: number,
note_open: boolean,
hint: number
blocks: Array<DataBlock>,
candys: Array<DataCandy>,
}

View File

@@ -11,8 +11,8 @@ export class Home extends Laya.Script {
@property(Laya.Box)
public btn_start: Laya.Box;
@property(Laya.Button)
public btn_clean: Laya.Button;
@property(Laya.Box)
public btn_clean: Laya.Box;
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {

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) {