完善hint功能
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
"_$ref": "6irhm6t7"
|
"_$ref": "6irhm6t7"
|
||||||
},
|
},
|
||||||
"btn_clean": {
|
"btn_clean": {
|
||||||
"_$ref": "m2dc2r9d"
|
"_$ref": "mdqfz48j"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -89,23 +89,33 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_$id": "m2dc2r9d",
|
"_$id": "mdqfz48j",
|
||||||
"_$type": "Button",
|
"_$type": "Box",
|
||||||
"name": "btn_clean",
|
"name": "btn_clean",
|
||||||
"x": 440,
|
"x": 440,
|
||||||
"y": 1820,
|
"y": 1820,
|
||||||
"width": 200,
|
"width": 200,
|
||||||
"height": 100,
|
"height": 100,
|
||||||
"_mouseState": 2,
|
|
||||||
"bottom": 0,
|
"bottom": 0,
|
||||||
"centerX": 0,
|
"centerX": 0,
|
||||||
"skin": "res://7eeb7e11-21ca-41ca-b7c2-dd2afa0c3ba7",
|
"_$child": [
|
||||||
"label": "清理",
|
{
|
||||||
"labelSize": 60,
|
"_$id": "yfgx8fq9",
|
||||||
"labelColors": "#ffffff,#32cc6b,#ff0000",
|
"_$type": "Label",
|
||||||
"labelAlign": "center",
|
"name": "Label",
|
||||||
"labelVAlign": "middle",
|
"width": 200,
|
||||||
"labelStrokeColor": "rgba(216, 208, 208, 1)"
|
"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"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -128,6 +128,14 @@ export class DOStage {
|
|||||||
this.data.note_open = note_open
|
this.data.note_open = note_open
|
||||||
StorageManager.getInstance().onChanged()
|
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> {
|
public get_blocks(): Array<DOBlock> {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export class StorageManager {
|
|||||||
this.stageMap.set(stageID, dataStage)
|
this.stageMap.set(stageID, dataStage)
|
||||||
}
|
}
|
||||||
else {
|
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)
|
this.stageMap.set(stageID, dataStage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export interface DataStage {
|
|||||||
difficulty: number,
|
difficulty: number,
|
||||||
duration: number,
|
duration: number,
|
||||||
note_open: boolean,
|
note_open: boolean,
|
||||||
|
hint: number
|
||||||
blocks: Array<DataBlock>,
|
blocks: Array<DataBlock>,
|
||||||
candys: Array<DataCandy>,
|
candys: Array<DataCandy>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ export class Home extends Laya.Script {
|
|||||||
@property(Laya.Box)
|
@property(Laya.Box)
|
||||||
public btn_start: Laya.Box;
|
public btn_start: Laya.Box;
|
||||||
|
|
||||||
@property(Laya.Button)
|
@property(Laya.Box)
|
||||||
public btn_clean: Laya.Button;
|
public btn_clean: Laya.Box;
|
||||||
|
|
||||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||||
onAwake(): void {
|
onAwake(): void {
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ export class Stage extends Laya.Script {
|
|||||||
public btn_hint: Laya.Box;
|
public btn_hint: Laya.Box;
|
||||||
private btn_hint_normal: Laya.Box
|
private btn_hint_normal: Laya.Box
|
||||||
private btn_hint_ad: Laya.Box
|
private btn_hint_ad: Laya.Box
|
||||||
|
private btn_hint_label: Laya.Label
|
||||||
|
|
||||||
private selectedBlock: Block;
|
private selectedBlock: Block;
|
||||||
private data: DOStage;
|
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_normal = this.btn_note.getChildByName("normal") as Laya.Box
|
||||||
this.btn_note_checked = this.btn_note.getChildByName("checked") 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.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;
|
this.selectedBlock = null;
|
||||||
}
|
}
|
||||||
@@ -128,6 +132,7 @@ export class Stage extends Laya.Script {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.onClickNote(null)
|
this.onClickNote(null)
|
||||||
|
this.onUpdateHintStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
onUpdateScore(): void {
|
onUpdateScore(): void {
|
||||||
@@ -229,31 +234,49 @@ export class Stage extends Laya.Script {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onClickHint(evt: Laya.Event): void {
|
onClickHint(evt: Laya.Event): void {
|
||||||
if (this.selectedBlock && this.selectedBlock.getData().get_checked() == false) {//当前选中的格子没有完成
|
var hint = this.data.get_hint()
|
||||||
var correct = this.selectedBlock.getData().get_correct()
|
if (hint > 0) {
|
||||||
var candy = this.candys[correct-1]
|
if (this.selectedBlock && this.selectedBlock.getData().get_checked() == false) {//当前选中的格子没有完成
|
||||||
this.onApplyCandy(candy)
|
var correct = this.selectedBlock.getData().get_correct()
|
||||||
}
|
|
||||||
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]
|
var candy = this.candys[correct-1]
|
||||||
this.onApplyCandy(candy)
|
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 {
|
public onApplyCandy(candy: Candy): void {
|
||||||
if (this.selectedBlock && this.selectedBlock.getData().get_checked() == false) {
|
if (this.selectedBlock && this.selectedBlock.getData().get_checked() == false) {
|
||||||
|
|||||||
Reference in New Issue
Block a user