diff --git a/assets/Scene.ls b/assets/Scene.ls index bde55f9..80dcc00 100644 --- a/assets/Scene.ls +++ b/assets/Scene.ls @@ -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" - } - ] - } - ] - } ] } \ No newline at end of file diff --git a/assets/atlas/comp/bg_common_white.png b/assets/atlas/comp/bg_common_white.png index 901f7c8..75a1482 100644 Binary files a/assets/atlas/comp/bg_common_white.png and b/assets/atlas/comp/bg_common_white.png differ diff --git a/assets/atlas/comp/bg_common_white.png.meta b/assets/atlas/comp/bg_common_white.png.meta index bd783d1..8cea496 100644 --- a/assets/atlas/comp/bg_common_white.png.meta +++ b/assets/atlas/comp/bg_common_white.png.meta @@ -1,13 +1,6 @@ { "uuid": "6ad19646-ed7a-431c-a50e-65c2bcb40751", "importer": { - "textureType": 2, - "sizeGrid": [ - 20, - 40, - 31, - 40, - 0 - ] + "textureType": 2 } } \ No newline at end of file diff --git a/assets/atlas/comp/btn_blue.png b/assets/atlas/comp/btn_blue.png new file mode 100644 index 0000000..13337bb Binary files /dev/null and b/assets/atlas/comp/btn_blue.png differ diff --git a/assets/atlas/comp/btn_blue.png.meta b/assets/atlas/comp/btn_blue.png.meta new file mode 100644 index 0000000..34643fc --- /dev/null +++ b/assets/atlas/comp/btn_blue.png.meta @@ -0,0 +1,6 @@ +{ + "uuid": "a75b43fb-bcf6-47d1-a1ef-e5261122a4e2", + "importer": { + "textureType": 2 + } +} \ No newline at end of file diff --git a/assets/atlas/comp/btn_blue_light.png b/assets/atlas/comp/btn_blue_light.png new file mode 100644 index 0000000..619191b Binary files /dev/null and b/assets/atlas/comp/btn_blue_light.png differ diff --git a/assets/atlas/comp/btn_blue_light.png.meta b/assets/atlas/comp/btn_blue_light.png.meta new file mode 100644 index 0000000..d49aee4 --- /dev/null +++ b/assets/atlas/comp/btn_blue_light.png.meta @@ -0,0 +1,6 @@ +{ + "uuid": "2e8c9585-e650-4494-a329-807fd2d2a532", + "importer": { + "textureType": 2 + } +} \ No newline at end of file diff --git a/assets/atlas/comp/icon_fail.png b/assets/atlas/comp/icon_fail.png deleted file mode 100644 index a12ddcb..0000000 Binary files a/assets/atlas/comp/icon_fail.png and /dev/null differ diff --git a/assets/atlas/comp/icon_fail.png.meta b/assets/atlas/comp/icon_fail.png.meta deleted file mode 100644 index c7a03f7..0000000 --- a/assets/atlas/comp/icon_fail.png.meta +++ /dev/null @@ -1,6 +0,0 @@ -{ - "uuid": "9e3eb0ac-c410-40a7-b8c3-ae1316d04cfb", - "importer": { - "textureType": 2 - } -} \ No newline at end of file diff --git a/assets/atlas/comp/welldone.png b/assets/atlas/comp/welldone.png new file mode 100644 index 0000000..2687f2d Binary files /dev/null and b/assets/atlas/comp/welldone.png differ diff --git a/assets/atlas/comp/welldone.png.meta b/assets/atlas/comp/welldone.png.meta new file mode 100644 index 0000000..c6467c4 --- /dev/null +++ b/assets/atlas/comp/welldone.png.meta @@ -0,0 +1,6 @@ +{ + "uuid": "120856c0-7081-4fde-8dca-ae0a78d684e2", + "importer": { + "textureType": 2 + } +} \ No newline at end of file diff --git a/assets/resources/GameDone.lh b/assets/resources/GameDone.lh new file mode 100644 index 0000000..31f5ea0 --- /dev/null +++ b/assets/resources/GameDone.lh @@ -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 + } + ] + } + ] +} \ No newline at end of file diff --git a/assets/resources/GameDone.lh.meta b/assets/resources/GameDone.lh.meta new file mode 100644 index 0000000..31e6e7b --- /dev/null +++ b/assets/resources/GameDone.lh.meta @@ -0,0 +1,3 @@ +{ + "uuid": "2cc92bb3-cd88-4188-8660-2bef0a53883f" +} \ No newline at end of file diff --git a/assets/resources/GameOver.lh b/assets/resources/GameOver.lh new file mode 100644 index 0000000..7914e99 --- /dev/null +++ b/assets/resources/GameOver.lh @@ -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" + } + } + ] +} \ No newline at end of file diff --git a/assets/resources/GameOver.lh.meta b/assets/resources/GameOver.lh.meta new file mode 100644 index 0000000..f0dff33 --- /dev/null +++ b/assets/resources/GameOver.lh.meta @@ -0,0 +1,3 @@ +{ + "uuid": "c14a4460-1569-45a3-9ce7-f268a939cc66" +} \ No newline at end of file diff --git a/assets/resources/Home.lh b/assets/resources/Home.lh index 81e6863..1d23fd0 100644 --- a/assets/resources/Home.lh +++ b/assets/resources/Home.lh @@ -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, diff --git a/assets/resources/Home.lh.meta b/assets/resources/Home.lh.meta index a94fd07..30e41a9 100644 --- a/assets/resources/Home.lh.meta +++ b/assets/resources/Home.lh.meta @@ -1,3 +1,3 @@ { - "uuid": "ed2f6a24-7574-4f6a-b76b-816fe2521be2" + "uuid": "f9d05a0a-e0b6-4980-99ad-e809399f6099" } \ No newline at end of file diff --git a/src/constants/respath.ts b/src/constants/respath.ts index 2d8fd43..3a319ed 100644 --- a/src/constants/respath.ts +++ b/src/constants/respath.ts @@ -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", } diff --git a/src/models/StorageManager.ts b/src/models/StorageManager.ts index 953d183..c892bc2 100644 --- a/src/models/StorageManager.ts +++ b/src/models/StorageManager.ts @@ -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 diff --git a/src/models/UIManager.ts b/src/models/UIManager.ts index 6a30791..bb07a03 100644 --- a/src/models/UIManager.ts +++ b/src/models/UIManager.ts @@ -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 { - Laya.loader.load(respath.stage_ui_res).then((go)=>{ + 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() + 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() - var stage = this.owner.addChild(prefab).getComponent(Stage) - stage.onLoadStage(StorageManager.getInstance().loadStage("first")) + this.owner.addChild(prefab) + }) + } + public loadGameDone(): void { + Laya.loader.load(respath.gamedone_ui_res).then((go)=>{ + var prefab = go.create() + this.owner.addChild(prefab) }) } diff --git a/src/types/Candy.ts b/src/types/Candy.ts index 13032c2..69a53c8 100644 --- a/src/types/Candy.ts +++ b/src/types/Candy.ts @@ -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 = "" } } } \ No newline at end of file diff --git a/src/views/GameDone.ts b/src/views/GameDone.ts new file mode 100644 index 0000000..3b0c885 --- /dev/null +++ b/src/views/GameDone.ts @@ -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() + }) + } +} \ No newline at end of file diff --git a/src/views/GameDone.ts.meta b/src/views/GameDone.ts.meta new file mode 100644 index 0000000..71c2e2f --- /dev/null +++ b/src/views/GameDone.ts.meta @@ -0,0 +1,3 @@ +{ + "uuid": "13e020d1-5ab8-4082-80ca-c0d208342103" +} \ No newline at end of file diff --git a/src/views/GameOver.ts b/src/views/GameOver.ts new file mode 100644 index 0000000..32678f8 --- /dev/null +++ b/src/views/GameOver.ts @@ -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() + }) + } + +} \ No newline at end of file diff --git a/src/views/GameOver.ts.meta b/src/views/GameOver.ts.meta new file mode 100644 index 0000000..ae3d5c8 --- /dev/null +++ b/src/views/GameOver.ts.meta @@ -0,0 +1,3 @@ +{ + "uuid": "72a5ccd3-8177-451c-b2ce-cf1b42f7e6d4" +} \ No newline at end of file diff --git a/src/views/Home.ts b/src/views/Home.ts index a5b33c8..4e82793 100644 --- a/src/views/Home.ts +++ b/src/views/Home.ts @@ -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() }) diff --git a/src/views/Stage.ts b/src/views/Stage.ts index f177a48..7613382 100644 --- a/src/views/Stage.ts +++ b/src/views/Stage.ts @@ -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= 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() } } }