77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
|
|
const { regClass, property } = Laya;
|
||
|
|
|
||
|
|
@regClass()
|
||
|
|
export class Block extends Laya.Script {
|
||
|
|
declare owner : Laya.Button;
|
||
|
|
|
||
|
|
@property(Number)
|
||
|
|
public XIndex: number = 0;
|
||
|
|
@property(Number)
|
||
|
|
public YIndex: number = 0;
|
||
|
|
@property(Number)
|
||
|
|
public XGroup: number = 0;
|
||
|
|
@property(Number)
|
||
|
|
public YGroup: number = 0;
|
||
|
|
|
||
|
|
private preset: boolean = false//预设格子
|
||
|
|
private checked: boolean = false//正确格子
|
||
|
|
private showNumber: number = 0;
|
||
|
|
private correctNumber: number = 0;
|
||
|
|
|
||
|
|
public onInit(XIndex: number, YIndex: number, XGroup: number, YGroup: number, handler: any, func: any): void {
|
||
|
|
this.XIndex = XIndex;
|
||
|
|
this.YIndex = YIndex;
|
||
|
|
this.XGroup = XGroup;
|
||
|
|
this.YGroup = YGroup;
|
||
|
|
this.owner.on(Laya.Event.CLICK, handler, func);
|
||
|
|
}
|
||
|
|
|
||
|
|
public setButtonSkin(skin: string): void {
|
||
|
|
this.owner.skin = skin
|
||
|
|
}
|
||
|
|
|
||
|
|
public setBlock(preset: boolean, showNumber: number, correctNumber: number): void {
|
||
|
|
this.preset = preset;
|
||
|
|
this.checked = preset;
|
||
|
|
this.showNumber = showNumber;
|
||
|
|
this.correctNumber = correctNumber;
|
||
|
|
this.updateBlock();
|
||
|
|
}
|
||
|
|
|
||
|
|
public getIsPreset(): boolean {
|
||
|
|
return this.preset;
|
||
|
|
}
|
||
|
|
|
||
|
|
public getIsChecked(): boolean {
|
||
|
|
return this.checked;
|
||
|
|
}
|
||
|
|
|
||
|
|
public getShowNumber(): number {
|
||
|
|
return this.showNumber;
|
||
|
|
}
|
||
|
|
|
||
|
|
public setShowNumber(showNumber: number): boolean {
|
||
|
|
console.log("setShowNumber >>>>>", showNumber, this.correctNumber, this.XIndex, this.YIndex)
|
||
|
|
if (this.checked == false) {
|
||
|
|
if (showNumber == this.correctNumber)
|
||
|
|
this.checked = true;
|
||
|
|
this.showNumber = showNumber;
|
||
|
|
this.updateBlock();
|
||
|
|
}
|
||
|
|
return this.checked
|
||
|
|
}
|
||
|
|
|
||
|
|
updateBlock(): void {
|
||
|
|
if (this.showNumber > 0) {
|
||
|
|
this.owner.label = this.showNumber.toString();
|
||
|
|
if (this.checked)
|
||
|
|
this.owner.labelColors = "#000000,#000000,#000000"
|
||
|
|
else
|
||
|
|
this.owner.labelColors = "#ff0000,#ff0000,#ff0000"
|
||
|
|
}
|
||
|
|
else {
|
||
|
|
this.owner.label = "";
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|