补充关卡功能

This commit is contained in:
2025-05-13 14:17:33 +08:00
parent 941dd170b5
commit dcb12db40d
16 changed files with 382 additions and 7 deletions

View File

@@ -3,5 +3,7 @@
export const respath = {
home_ui_res: "resources/Home.lh",
stage_ui_res: "resources/Stage.lh",
score_add_ui_res: "resources/ScoreAdd.lh",
}

View File

@@ -1,3 +1,5 @@
import { G_ShowScoreTips } from "../views/GUITips";
const { regClass, property } = Laya;
@regClass()
@@ -14,10 +16,12 @@ export class Block extends Laya.Script {
public YGroup: number = 0;
private selected: boolean = false
private newSelect: boolean = false
private preset: boolean = false//预设格子
private checked: boolean = false//正确格子
private showNumber: number = 0;
private correctNumber: number = 0;
private score: number = 0
private note_numbers: Array<number> = new Array()
private label_show: Laya.Label;
@@ -46,6 +50,8 @@ export class Block extends Laya.Script {
public setSelected(selected: boolean): void {
this.selected = selected
if (selected)
this.newSelect = true
this.updateBlock()
}
@@ -67,6 +73,7 @@ export class Block extends Laya.Script {
this.checked = preset;
this.showNumber = showNumber;
this.correctNumber = correctNumber;
this.score = 0
this.updateBlock();
}
@@ -82,22 +89,35 @@ export class Block extends Laya.Script {
return this.showNumber;
}
public getCorrectNumber(): number {
return this.correctNumber;
}
public setShowNumber(showNumber: number): boolean {
if (this.checked == false) {
if (showNumber == this.correctNumber)
this.checked = true;
this.showNumber = showNumber;
if (this.checked || showNumber == 0)//正确或者擦除
if (this.checked || showNumber == 0) {//正确或者擦除
this.note_numbers = new Array()
}
this.score = 0
if (this.newSelect) {
this.newSelect = false
if (this.checked) {
this.score = 150
G_ShowScoreTips(this.score.toString(), this.owner)
}
}
this.updateBlock();
}
return this.checked
}
public getCorrectNumber(): number {
return this.correctNumber;
}
public getScore(): number {
return this.score
}
public addNoteNumber(noteNumber: number): void {
if (this.note_numbers.indexOf(noteNumber) < 0) {
this.note_numbers.push(noteNumber)

19
src/views/AutoDestroy.ts Normal file
View File

@@ -0,0 +1,19 @@
const { regClass, property } = Laya;
@regClass()
export class AutoDestroy extends Laya.Script {
declare owner : Laya.Box;
@property(Number)
public lifeTime: number = 1;
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
if (this.lifeTime < 1) {
this.lifeTime = 1
}
Laya.timer.once(this.lifeTime*1000, this, ()=>{
this.owner.destroy()
})
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "bdb0e671-99fa-47a5-9101-7ec008b1d25d"
}

9
src/views/GUITips.ts Normal file
View File

@@ -0,0 +1,9 @@
import { respath } from "../constants/respath";
export function G_ShowScoreTips(text: string, parent: any): void {
Laya.loader.load(respath.score_add_ui_res).then((go)=>{
var prefab = go.create()
var label = parent.addChild(prefab).getChildByName("offset").getChildByName("Label") as Laya.Label
label.text = text
})
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "0a00337c-1c20-470f-930f-2b47f0294e23"
}

View File

@@ -11,6 +11,20 @@ export class Stage extends Laya.Script {
private letterToNumber: any;
private numberToLetter: any;
@property(Laya.Text)
public label_stage_name: Laya.Text;
@property(Laya.Label)
public label_score: Laya.Label;
@property(Laya.Label)
public label_mistake: Laya.Label;
private mistake_now = 0
private mistake_all = 3
@property(Laya.Label)
public label_diff: Laya.Label;
@property(Laya.Label)
public label_time: Laya.Label;
private stage_last: number
@property(Laya.Box)
public obj_blocks: Laya.Box;
@property(Laya.Box)
@@ -120,6 +134,7 @@ export class Stage extends Laya.Script {
public onLoadStage(levelStr: string): void {
this.mistake_now = 0
this.selectedBlock = null;
if (levelStr.length == 81 && this.blocks.length == 81) {
@@ -155,6 +170,35 @@ export class Stage extends Laya.Script {
else {
console.log("onLoadStage error", levelStr.length, this.blocks.length)
}
this.onUpdateScore()
this.onUpdateMistake()
this.stage_last = 0
var begin = Date.now()
Laya.timer.loop(1000, this, ()=>{
var now = Date.now()
this.stage_last += Math.floor((now-begin)/1000)
begin = now
var last = this.stage_last
var hour = Math.floor(last/3600)
last = last - hour * 3600
var minite = Math.floor(last/60)
last = last - minite * 60
var second = Math.floor(last)
this.label_time.text = `${hour>=10?hour:("0"+hour)}:${minite>=10?minite:("0"+minite)}:${second>10?second:("0"+second)}`
})
}
onUpdateScore(): void {
var score = 0
for (var i=0; i<this.blocks.length; i++) {
score += this.blocks[i].getScore()
}
this.label_score.text = `分数: ${score}`
}
onUpdateMistake(): void {
this.label_mistake.text = `${this.mistake_now}/${this.mistake_all}`
}
onSetBlock(block: Block): void {
@@ -206,6 +250,7 @@ export class Stage extends Laya.Script {
onClickErase(evt: Laya.Event): void {
if (this.selectedBlock && this.selectedBlock.getIsChecked() == false) {
this.selectedBlock.setShowNumber(0)
this.onUpdateScore()
this.onSetBlock(this.selectedBlock)
}
}
@@ -230,8 +275,9 @@ export class Stage extends Laya.Script {
index = list.length -1
var block = list[index]
block.setShowNumber(block.getCorrectNumber())
this.selectedBlock = block
this.onUpdateScore()
this.onSetBlock(block)
this.selectedBlock = block
}
}
@@ -261,6 +307,7 @@ export class Stage extends Laya.Script {
}
else {
var b = this.selectedBlock.setShowNumber(showNumber);
this.onUpdateScore()
this.onSetBlock(this.selectedBlock)
if (b) {
var left = candy.getLeft();
@@ -269,7 +316,12 @@ export class Stage extends Laya.Script {
console.log("完成关卡")
}
}
else {
else {//失败
this.mistake_now ++
this.onUpdateMistake()
if (this.mistake_now >= this.mistake_all) {
//关卡失败
}
}
}
}