diff --git a/assets/resources/Home.lh b/assets/resources/Home.lh index 9465b72..4d9b17b 100644 --- a/assets/resources/Home.lh +++ b/assets/resources/Home.lh @@ -18,7 +18,7 @@ "_$ref": "6irhm6t7" }, "btn_clean": { - "_$ref": "m2dc2r9d" + "_$ref": "mdqfz48j" } } ], @@ -89,23 +89,33 @@ ] }, { - "_$id": "m2dc2r9d", - "_$type": "Button", + "_$id": "mdqfz48j", + "_$type": "Box", "name": "btn_clean", "x": 440, "y": 1820, "width": 200, "height": 100, - "_mouseState": 2, "bottom": 0, "centerX": 0, - "skin": "res://7eeb7e11-21ca-41ca-b7c2-dd2afa0c3ba7", - "label": "清理", - "labelSize": 60, - "labelColors": "#ffffff,#32cc6b,#ff0000", - "labelAlign": "center", - "labelVAlign": "middle", - "labelStrokeColor": "rgba(216, 208, 208, 1)" + "_$child": [ + { + "_$id": "yfgx8fq9", + "_$type": "Label", + "name": "Label", + "width": 200, + "height": 100, + "centerX": 0, + "centerY": 0, + "text": "Clean", + "fontSize": 80, + "color": "rgba(89, 109, 152, 1)", + "bold": true, + "align": "center", + "valign": "middle", + "padding": "0,0,0,0" + } + ] } ] } \ No newline at end of file diff --git a/src/models/DOStage.ts b/src/models/DOStage.ts index 9ca2229..1d5009b 100644 --- a/src/models/DOStage.ts +++ b/src/models/DOStage.ts @@ -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 { diff --git a/src/models/StorageManager.ts b/src/models/StorageManager.ts index 5c485ad..1990c92 100644 --- a/src/models/StorageManager.ts +++ b/src/models/StorageManager.ts @@ -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) } } diff --git a/src/types/global.ts b/src/types/global.ts index 65e2940..93f0ffb 100644 --- a/src/types/global.ts +++ b/src/types/global.ts @@ -21,6 +21,7 @@ export interface DataStage { difficulty: number, duration: number, note_open: boolean, + hint: number blocks: Array, candys: Array, } diff --git a/src/views/Home.ts b/src/views/Home.ts index e64c1dc..3343734 100644 --- a/src/views/Home.ts +++ b/src/views/Home.ts @@ -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 { diff --git a/src/views/Stage.ts b/src/views/Stage.ts index fae3f81..e9dfc8a 100644 --- a/src/views/Stage.ts +++ b/src/views/Stage.ts @@ -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 = new Array() - for (var i=0; i 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 = new Array() + for (var i=0; i 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) {