游戏结束

This commit is contained in:
2025-05-14 12:17:47 +08:00
parent 2cc01c5570
commit 830bf2bb29
27 changed files with 405 additions and 113 deletions

View File

@@ -18,69 +18,5 @@
"_$type": "cd70cd5e-b4cd-4277-ac0a-2224cfbe89ac",
"scriptPath": "../src/models/UIManager.ts"
}
],
"_$child": [
{
"_$id": "w805s9t9",
"_$type": "Box",
"name": "Box",
"width": 1080,
"height": 1920,
"left": 0,
"right": 0,
"top": 0,
"bottom": 0,
"_$child": [
{
"_$id": "c5b9d1x1",
"_$type": "Image",
"name": "bg",
"x": 118,
"y": 420,
"width": 844,
"height": 1080,
"centerX": 0,
"centerY": 0,
"skin": "res://6ad19646-ed7a-431c-a50e-65c2bcb40751",
"color": "#ffffff"
},
{
"_$id": "md4ipd8a",
"_$type": "Image",
"name": "score",
"x": 300,
"y": 449,
"width": 240,
"height": 181,
"scaleX": 2,
"scaleY": 2,
"centerX": 0,
"centerY": -330,
"skin": "res://9e3eb0ac-c410-40a7-b8c3-ae1316d04cfb",
"useSourceSize": true,
"color": "#ffffff",
"_$child": [
{
"_$id": "fkjymlk3",
"_$type": "Label",
"name": "Label",
"x": 20,
"y": 61,
"width": 200,
"height": 60,
"centerX": 0,
"centerY": 0,
"text": "99",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 60,
"color": "#FFFFFF",
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
}
]
}
]
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

@@ -1,13 +1,6 @@
{
"uuid": "6ad19646-ed7a-431c-a50e-65c2bcb40751",
"importer": {
"textureType": 2,
"sizeGrid": [
20,
40,
31,
40,
0
]
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "a75b43fb-bcf6-47d1-a1ef-e5261122a4e2",
"importer": {
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 743 B

View File

@@ -0,0 +1,6 @@
{
"uuid": "2e8c9585-e650-4494-a329-807fd2d2a532",
"importer": {
"textureType": 2
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

View File

@@ -1,6 +0,0 @@
{
"uuid": "9e3eb0ac-c410-40a7-b8c3-ae1316d04cfb",
"importer": {
"textureType": 2
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

View File

@@ -0,0 +1,6 @@
{
"uuid": "120856c0-7081-4fde-8dca-ae0a78d684e2",
"importer": {
"textureType": 2
}
}

View File

@@ -0,0 +1,116 @@
{
"_$ver": 1,
"_$id": "9yemrkim",
"_$type": "Box",
"name": "GameDone",
"width": 1080,
"height": 1920,
"_mouseState": 2,
"drawCallOptimize": true,
"left": 0,
"right": 0,
"top": 0,
"bottom": 0,
"_$comp": [
{
"_$type": "13e020d1-5ab8-4082-80ca-c0d208342103",
"scriptPath": "../src/views/GameDone.ts",
"btn_new": {
"_$ref": "ljwrbqm7"
}
}
],
"_$child": [
{
"_$id": "ocyocuk7",
"_$type": "Image",
"name": "bg",
"x": 90,
"y": 482,
"width": 900,
"height": 956,
"_mouseState": 2,
"centerX": 0,
"centerY": 0,
"skin": "res://6ad19646-ed7a-431c-a50e-65c2bcb40751",
"sizeGrid": "40,60,50,60,0",
"color": "#ffffff",
"_$child": [
{
"_$id": "52u6rl70",
"_$type": "Image",
"name": "Image",
"x": 322,
"y": 54,
"width": 128,
"height": 128,
"scaleX": 2,
"scaleY": 2,
"centerX": 0,
"centerY": -296,
"skin": "res://120856c0-7081-4fde-8dca-ae0a78d684e2",
"useSourceSize": true,
"color": "#ffffff"
}
]
},
{
"_$id": "ljwrbqm7",
"_$type": "Button",
"name": "btn_new",
"x": 172,
"y": 1182,
"width": 736,
"height": 152,
"_mouseState": 2,
"centerX": 0,
"centerY": 298,
"stateNum": 1,
"skin": "res://2e8c9585-e650-4494-a329-807fd2d2a532",
"sizeGrid": "24,40,24,40,0",
"label": "新游戏",
"labelFont": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"labelSize": 60,
"labelBold": true,
"labelColors": "#1d5cdc,#1d5cdc,#1d5cdc",
"labelAlign": "center",
"labelVAlign": "middle"
},
{
"_$id": "t0v4lr20",
"_$type": "Label",
"name": "Label",
"x": 172,
"y": 795,
"width": 736,
"height": 100,
"centerX": 0,
"centerY": -115,
"text": "Well done",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 80,
"color": "rgba(0, 0, 0, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0",
"_$child": [
{
"_$id": "kx4e9y8p",
"_$type": "Text",
"name": "Text",
"y": 120,
"width": 736,
"height": 200,
"text": "[color=#7b818c]你击败了[color=#f1bf44]80%[/color]的玩家[/color]",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 60,
"color": "#FFFFFF",
"ubb": true,
"align": "center",
"leading": 2
}
]
}
]
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "2cc92bb3-cd88-4188-8660-2bef0a53883f"
}

View File

@@ -0,0 +1,125 @@
{
"_$ver": 1,
"_$id": "w805s9t9",
"_$type": "Box",
"name": "GameOver",
"width": 1080,
"height": 1920,
"_mouseState": 2,
"drawCallOptimize": true,
"left": 0,
"right": 0,
"top": 0,
"bottom": 0,
"_$child": [
{
"_$id": "li6t446m",
"_$type": "Image",
"name": "bg",
"x": 90,
"y": 404,
"width": 900,
"height": 1112,
"_mouseState": 2,
"centerX": 0,
"centerY": 0,
"skin": "res://6ad19646-ed7a-431c-a50e-65c2bcb40751",
"sizeGrid": "40,60,50,60,0",
"color": "#ffffff"
},
{
"_$id": "sco68sr2",
"_$type": "Button",
"name": "btn_restart",
"x": 172,
"y": 1032,
"width": 736,
"height": 152,
"_mouseState": 2,
"centerX": 0,
"centerY": 148,
"stateNum": 1,
"skin": "res://2e8c9585-e650-4494-a329-807fd2d2a532",
"sizeGrid": "24,40,24,40,0",
"label": "重新开始",
"labelFont": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"labelSize": 60,
"labelBold": true,
"labelColors": "#1d5cdc,#1d5cdc,#1d5cdc",
"labelAlign": "center",
"labelVAlign": "middle"
},
{
"_$id": "p8wk9udp",
"_$type": "Button",
"name": "btn_new",
"x": 172,
"y": 1234,
"width": 736,
"height": 152,
"_mouseState": 2,
"centerX": 0,
"centerY": 350,
"stateNum": 1,
"skin": "res://2e8c9585-e650-4494-a329-807fd2d2a532",
"sizeGrid": "24,40,24,40,0",
"label": "新游戏",
"labelFont": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"labelSize": 60,
"labelBold": true,
"labelColors": "#1d5cdc,#1d5cdc,#1d5cdc",
"labelAlign": "center",
"labelVAlign": "middle"
},
{
"_$id": "jkqju6ok",
"_$type": "Label",
"name": "Label",
"x": 172,
"y": 510,
"width": 736,
"height": 100,
"centerX": 0,
"centerY": -400,
"text": "游戏结束",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 80,
"color": "rgba(0, 0, 0, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "39t7ygbe",
"_$type": "Label",
"name": "Label(1)",
"x": 172,
"y": 667,
"width": 736,
"height": 300,
"centerX": 0,
"centerY": -143,
"text": "你犯了3个错误所以你输掉了游戏",
"font": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"fontSize": 60,
"color": "rgba(123, 129, 140, 1)",
"align": "center",
"valign": "top",
"wordWrap": true,
"padding": "0,0,0,0"
}
],
"_$comp": [
{
"_$type": "72a5ccd3-8177-451c-b2ce-cf1b42f7e6d4",
"scriptPath": "../src/views/GameOver.ts",
"btn_restart": {
"_$ref": "sco68sr2"
},
"btn_new": {
"_$ref": "p8wk9udp"
}
}
]
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "c14a4460-1569-45a3-9ce7-f268a939cc66"
}

View File

@@ -1,6 +1,6 @@
{
"_$ver": 1,
"_$id": "dzyyfm4n",
"_$id": "5uv9hvq0",
"_$type": "Box",
"name": "Home",
"width": 1080,
@@ -15,16 +15,16 @@
"_$type": "f2970e4d-7a09-4a9b-aef3-45d330c86f4f",
"scriptPath": "../src/views/Home.ts",
"btn_start": {
"_$ref": "vfxym76v"
"_$ref": "6ystn7m8"
},
"btn_clean": {
"_$ref": "ttvxhmrp"
"_$ref": "m2dc2r9d"
}
}
],
"_$child": [
{
"_$id": "x8wx2qo1",
"_$id": "g2ct7a01",
"_$type": "Image",
"name": "Mask",
"width": 1080,
@@ -37,13 +37,14 @@
"color": "#ffffff"
},
{
"_$id": "pd4fx8i2",
"_$id": "hxal67ur",
"_$type": "Button",
"name": "btn_continue",
"x": 440,
"y": 737,
"width": 200,
"height": 100,
"visible": false,
"_mouseState": 2,
"centerX": 0,
"centerY": -173,
@@ -56,27 +57,29 @@
"labelVAlign": "middle"
},
{
"_$id": "vfxym76v",
"_$id": "6ystn7m8",
"_$type": "Button",
"name": "btn_start",
"x": 440,
"y": 910,
"width": 200,
"height": 100,
"x": 172,
"y": 1182,
"width": 736,
"height": 152,
"_mouseState": 2,
"centerX": 0,
"centerY": 0,
"skin": "res://7eeb7e11-21ca-41ca-b7c2-dd2afa0c3ba7",
"label": "开始",
"centerY": 298,
"stateNum": 1,
"skin": "res://a75b43fb-bcf6-47d1-a1ef-e5261122a4e2",
"sizeGrid": "24,40,24,40,0",
"label": "新游戏",
"labelFont": "res://55f943ef-58d2-4b30-8498-271c4213cce4",
"labelSize": 60,
"labelColors": "#ffffff,#32cc6b,#ff0000",
"labelBold": true,
"labelColors": "#ffffff,#ffffff,#ffffff",
"labelAlign": "center",
"labelVAlign": "middle",
"labelStrokeColor": "rgba(216, 208, 208, 1)"
"labelVAlign": "middle"
},
{
"_$id": "ttvxhmrp",
"_$id": "m2dc2r9d",
"_$type": "Button",
"name": "btn_clean",
"x": 440,

View File

@@ -1,3 +1,3 @@
{
"uuid": "ed2f6a24-7574-4f6a-b76b-816fe2521be2"
"uuid": "f9d05a0a-e0b6-4980-99ad-e809399f6099"
}

View File

@@ -3,6 +3,8 @@
export const respath = {
home_ui_res: "resources/Home.lh",
stage_ui_res: "resources/Stage.lh",
gameover_ui_res: "resources/GameOver.lh",
gamedone_ui_res: "resources/GameDone.lh",
score_add_ui_res: "resources/ScoreAdd.lh",
}

View File

@@ -73,6 +73,16 @@ export class StorageManager {
return new DOStage(dataStage, levelStr)
}
public cleanStage(): void {
if (this.stageID && this.stageID.length > 0) {
if (this.stageMap.has(this.stageID)) {
this.stageMap.delete(this.stageID)
}
Laya.LocalStorage.removeItem(this.stageID)
this.stageID = ""
}
}
public saveStage(): void {
if (this.changed) {
this.changed = false

View File

@@ -22,6 +22,8 @@ export class UIManager extends Laya.Script {
return UIManager._instance
}
private stage: Stage
public loadHome(): void {
Laya.loader.load(respath.home_ui_res).then((go)=>{
var prefab = go.create()
@@ -29,11 +31,39 @@ export class UIManager extends Laya.Script {
})
}
public loadStage(): void {
public loadStage(stageID: string, clean: boolean=false): void {
if (clean) {
StorageManager.getInstance().cleanStage()
}
if (this.stage) {
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))
}
else {
Laya.loader.load(respath.stage_ui_res).then((go)=>{
var prefab = go.create()
var stage = this.owner.addChild(prefab).getComponent(Stage)
stage.onLoadStage(StorageManager.getInstance().loadStage("first"))
this.stage = this.owner.addChild(prefab).getComponent(Stage)
this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID))
})
}
}
public closeStage(): void {
if (this.stage) {
this.stage.owner.destroy()
this.stage = null
}
}
public loadGameOver(): void {
Laya.loader.load(respath.gameover_ui_res).then((go)=>{
var prefab = go.create()
this.owner.addChild(prefab)
})
}
public loadGameDone(): void {
Laya.loader.load(respath.gamedone_ui_res).then((go)=>{
var prefab = go.create()
this.owner.addChild(prefab)
})
}

View File

@@ -30,23 +30,22 @@ export class Candy extends Laya.Script {
this.updateCandy()
}
public getLeft(): number {
return this.data.get_left();
}
updateCandy(): void {
this.owner.active = this.getLeft() > 0
if (this.data.get_show() > 0) {
this.label_show.text = this.data.get_show().toString()
}
else {
this.label_show.text = ""
}
if (this.getLeft() > 0) {
this.label_left.text = this.getLeft().toString();
if (this.data.get_left() > 0) {
this.label_left.text = this.data.get_left().toString();
this.owner.visible = true
}
else {
this.label_left.text = ""
this.owner.visible = false
this.label_show.text = ""
}
}
}

22
src/views/GameDone.ts Normal file
View File

@@ -0,0 +1,22 @@
import { UIManager } from "../models/UIManager";
import { StorageManager } from "../models/StorageManager";
const { regClass, property } = Laya;
@regClass()
export class GameDone extends Laya.Script {
declare owner : Laya.Box;
@property(Laya.Button)
public btn_new: Laya.Button
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
this.btn_new.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
UIManager.getInstance().closeStage();
UIManager.getInstance().loadHome();
StorageManager.getInstance().cleanStage()
this.owner.destroy()
})
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "13e020d1-5ab8-4082-80ca-c0d208342103"
}

29
src/views/GameOver.ts Normal file
View File

@@ -0,0 +1,29 @@
import { UIManager } from "../models/UIManager";
const { regClass, property } = Laya;
@regClass()
export class GameOver extends Laya.Script {
declare owner : Laya.Box;
@property(Laya.Button)
public btn_restart: Laya.Button
@property(Laya.Button)
public btn_new: Laya.Button
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
UIManager.getInstance().loadStage("first", true);
this.owner.destroy()
})
this.btn_new.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
UIManager.getInstance().loadStage("first", true);
this.owner.destroy()
})
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "72a5ccd3-8177-451c-b2ce-cf1b42f7e6d4"
}

View File

@@ -16,7 +16,7 @@ export class Home extends Laya.Script {
onAwake(): void {
this.btn_start.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
console.log("btn_start=", evt);
UIManager.getInstance().loadStage();
UIManager.getInstance().loadStage("first");
this.owner.destroy()
})

View File

@@ -67,7 +67,7 @@ export class Stage extends Laya.Script {
onAwake(): void {
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
UIManager.getInstance().loadHome();
this.owner.destroy()
UIManager.getInstance().closeStage();
})
for (var i=0; i<this.obj_blocks.numChildren; i++) {
var hbox = this.obj_blocks.getChildAt(i);
@@ -131,6 +131,7 @@ export class Stage extends Laya.Script {
for (var i=0; i<blocks.length; i++) {
var doBlock = blocks[i]
var block = this.blocks[i]
block.setButtonSkin(this.img_block_normal.skin)
block.setBlock(doBlock)
}
var candys = doStage.get_candys()
@@ -231,10 +232,10 @@ export class Stage extends Laya.Script {
if (index >= list.length)
index = list.length -1
var block = list[index]
block.setShowNumber(block.getData().get_correct())
this.onUpdateScore()
this.onSetBlock(block)
this.selectedBlock = block
var correct = block.getData().get_correct()
var candy = this.candys[correct-1]
this.onApplyCandy(candy)
}
}
@@ -267,10 +268,11 @@ export class Stage extends Laya.Script {
this.onUpdateScore()
this.onSetBlock(this.selectedBlock)
if (b) {
var left = candy.getLeft();
var left = candy.getData().get_left();
candy.setLeft(left-1);
if (this.getIsComplete()) {
console.log("完成关卡")
UIManager.getInstance().loadGameDone()
}
}
else {//失败
@@ -278,6 +280,7 @@ export class Stage extends Laya.Script {
this.onUpdateMistake()
if (this.data.get_mistake() >= this.mistake_all) {
//关卡失败
UIManager.getInstance().loadGameOver()
}
}
}