diff --git a/assets/atlas/comp/icon_clock.png b/assets/atlas/comp/icon_clock.png new file mode 100644 index 0000000..4f6aa65 Binary files /dev/null and b/assets/atlas/comp/icon_clock.png differ diff --git a/assets/atlas/comp/icon_clock.png.meta b/assets/atlas/comp/icon_clock.png.meta new file mode 100644 index 0000000..3540771 --- /dev/null +++ b/assets/atlas/comp/icon_clock.png.meta @@ -0,0 +1,6 @@ +{ + "uuid": "2b4d26c7-ae87-47a3-8084-29a243441634", + "importer": { + "textureType": 2 + } +} \ No newline at end of file diff --git a/assets/resources/Difficulty.lh b/assets/resources/Difficulty.lh index ce5c20a..f9f59c6 100644 --- a/assets/resources/Difficulty.lh +++ b/assets/resources/Difficulty.lh @@ -20,17 +20,31 @@ } ], "_$child": [ + { + "_$id": "4udntov4", + "_$type": "Image", + "name": "mask", + "width": 1080, + "height": 1920, + "alpha": 0.4, + "left": 0, + "right": 0, + "top": 0, + "bottom": 0, + "skin": "res://a98f334e-ce04-4cd0-8fc5-bbdf9b048609", + "color": "#000000" + }, { "_$id": "jzxgx41i", "_$type": "Box", "name": "offset", - "y": 560, + "y": 3000, "width": 1080, "height": 1360, "_mouseState": 2, "left": 0, "right": 0, - "bottom": 0, + "bottom": -2440, "_$child": [ { "_$id": "bd1s5tvm", @@ -130,6 +144,14 @@ "x": 72, "width": 936, "height": 144, + "_$comp": [ + { + "_$type": "8857686b-9b2c-4e9c-af0f-0164c0994e46", + "scriptPath": "../src/views/CommonData.ts", + "intValue": 0, + "strValue": "" + } + ], "_$child": [ { "_$id": "590euu2q", @@ -137,6 +159,7 @@ "name": "Sprite", "width": 936, "height": 144, + "mouseThrough": true, "_gcmds": [ { "_$type": "DrawRoundRectCmd", @@ -179,6 +202,14 @@ "y": 194, "width": 936, "height": 144, + "_$comp": [ + { + "_$type": "8857686b-9b2c-4e9c-af0f-0164c0994e46", + "scriptPath": "../src/views/CommonData.ts", + "intValue": 0, + "strValue": "" + } + ], "_$child": [ { "_$id": "yjk1xq2a", @@ -186,6 +217,7 @@ "name": "Sprite", "width": 936, "height": 144, + "mouseThrough": true, "_gcmds": [ { "_$type": "DrawRoundRectCmd", @@ -228,6 +260,14 @@ "y": 388, "width": 936, "height": 144, + "_$comp": [ + { + "_$type": "8857686b-9b2c-4e9c-af0f-0164c0994e46", + "scriptPath": "../src/views/CommonData.ts", + "intValue": 0, + "strValue": "" + } + ], "_$child": [ { "_$id": "nfk6pjgd", @@ -235,6 +275,7 @@ "name": "Sprite", "width": 936, "height": 144, + "mouseThrough": true, "_gcmds": [ { "_$type": "DrawRoundRectCmd", @@ -277,6 +318,14 @@ "y": 582, "width": 936, "height": 144, + "_$comp": [ + { + "_$type": "8857686b-9b2c-4e9c-af0f-0164c0994e46", + "scriptPath": "../src/views/CommonData.ts", + "intValue": 0, + "strValue": "" + } + ], "_$child": [ { "_$id": "nogfpbyx", @@ -284,6 +333,7 @@ "name": "Sprite", "width": 936, "height": 144, + "mouseThrough": true, "_gcmds": [ { "_$type": "DrawRoundRectCmd", @@ -326,6 +376,14 @@ "y": 776, "width": 936, "height": 144, + "_$comp": [ + { + "_$type": "8857686b-9b2c-4e9c-af0f-0164c0994e46", + "scriptPath": "../src/views/CommonData.ts", + "intValue": 0, + "strValue": "" + } + ], "_$child": [ { "_$id": "2unm1bxx", @@ -333,6 +391,7 @@ "name": "Sprite", "width": 936, "height": 144, + "mouseThrough": true, "_gcmds": [ { "_$type": "DrawRoundRectCmd", diff --git a/assets/resources/Home.lh b/assets/resources/Home.lh index 4d9b17b..4873aab 100644 --- a/assets/resources/Home.lh +++ b/assets/resources/Home.lh @@ -14,9 +14,15 @@ { "_$type": "f2970e4d-7a09-4a9b-aef3-45d330c86f4f", "scriptPath": "../src/views/Home.ts", - "btn_start": { + "btn_new_blue": { "_$ref": "6irhm6t7" }, + "btn_continue": { + "_$ref": "9rcb0wtp" + }, + "btn_new_white": { + "_$ref": "n4ggvqc0" + }, "btn_clean": { "_$ref": "mdqfz48j" } @@ -36,16 +42,34 @@ "skin": "res://a98f334e-ce04-4cd0-8fc5-bbdf9b048609", "color": "#f5f7fb" }, + { + "_$id": "vxgd702p", + "_$type": "Label", + "name": "Label", + "x": 144, + "y": 760, + "width": 792, + "height": 400, + "centerX": 0, + "centerY": 0, + "text": "Classic\nSudoku", + "fontSize": 100, + "color": "rgba(123, 129, 140, 1)", + "bold": true, + "align": "center", + "valign": "middle", + "padding": "0,0,0,0" + }, { "_$id": "6irhm6t7", "_$type": "Box", - "name": "btn_start", + "name": "btn_new_blue", "x": 144, - "y": 1464, + "y": 1488, "width": 792, "height": 168, "centerX": 0, - "centerY": 588, + "centerY": 612, "_$child": [ { "_$id": "ry13plzy", @@ -88,6 +112,142 @@ } ] }, + { + "_$id": "9rcb0wtp", + "_$type": "Box", + "name": "btn_continue", + "x": 144, + "y": 1376, + "width": 792, + "height": 168, + "centerX": 0, + "centerY": 500, + "_$child": [ + { + "_$id": "vfod7fmk", + "_$type": "Sprite", + "name": "Sprite", + "width": 792, + "height": 168, + "_gcmds": [ + { + "_$type": "DrawRoundRectCmd", + "x": 0, + "y": 0, + "width": 1, + "height": 1, + "lt": 20, + "rt": 20, + "lb": 20, + "rb": 20, + "percent": true, + "lineWidth": 1, + "fillColor": "rgba(29, 92, 220, 1)" + } + ] + }, + { + "_$id": "f8ylua31", + "_$type": "Label", + "name": "Label", + "y": -32, + "width": 792, + "height": 168, + "centerX": 0, + "centerY": -32, + "text": "Continue", + "fontSize": 80, + "color": "#FFFFFF", + "bold": true, + "align": "center", + "valign": "middle", + "padding": "0,0,0,0" + }, + { + "_$id": "pr17wcli", + "_$type": "Image", + "name": "time", + "x": 227, + "y": 107, + "width": 35, + "height": 35, + "centerX": -152, + "centerY": 40, + "skin": "res://2b4d26c7-ae87-47a3-8084-29a243441634", + "useSourceSize": true, + "color": "#ffffff", + "_$child": [ + { + "_$id": "2l5pfddm", + "_$type": "Label", + "name": "label_time", + "x": 55, + "y": -2, + "width": 400, + "height": 35, + "text": "99:00:00-Hard", + "fontSize": 40, + "color": "rgba(255, 255, 255, 0.6078431372549019)", + "bold": true, + "valign": "middle", + "padding": "0,0,0,0" + } + ] + } + ] + }, + { + "_$id": "n4ggvqc0", + "_$type": "Box", + "name": "btn_new_white", + "x": 144, + "y": 1598, + "width": 792, + "height": 168, + "centerX": 0, + "centerY": 722, + "_$child": [ + { + "_$id": "sez4l9sx", + "_$type": "Sprite", + "name": "Sprite", + "width": 792, + "height": 168, + "_gcmds": [ + { + "_$type": "DrawRoundRectCmd", + "x": 0, + "y": 0, + "width": 1, + "height": 1, + "lt": 20, + "rt": 20, + "lb": 20, + "rb": 20, + "percent": true, + "lineWidth": 1, + "fillColor": "rgba(255, 255, 255, 1)" + } + ] + }, + { + "_$id": "ihe7vkr1", + "_$type": "Label", + "name": "Label", + "width": 792, + "height": 168, + "centerX": 0, + "centerY": 0, + "text": "New Game", + "fontSize": 100, + "color": "rgba(29, 92, 220, 1)", + "bold": true, + "align": "center", + "valign": "middle", + "padding": "0,0,0,0" + } + ] + }, { "_$id": "mdqfz48j", "_$type": "Box", diff --git a/src/Main.ts b/src/Main.ts index bc2356c..92dbfb0 100644 --- a/src/Main.ts +++ b/src/Main.ts @@ -1,9 +1,20 @@ + + +import { StorageManager } from "./models/StorageManager"; +import { LevelManager } from "./models/LevelManager"; const { regClass, property } = Laya; @regClass() export class Main extends Laya.Script { - onStart() { - console.log("Game start"); + onAwake() { + console.log("Game awake"); + + LevelManager.getInstance().init() + StorageManager.getInstance().init() + } + + onLateUpdate(): void { + StorageManager.getInstance().saveStage() } } \ No newline at end of file diff --git a/src/constants/config.ts b/src/constants/config.ts index 68c8884..f4d3473 100644 --- a/src/constants/config.ts +++ b/src/constants/config.ts @@ -4,17 +4,25 @@ export const config = { BREAK_POINT: 1, // 竖版和横版的分界宽度 - DEBUG: false, + DEBUG: true, OPEN_GUIDE: true, MISTAKE_MAX: 3,//最大错误数 + STAGE_TYPE: {//关卡类型 + MAIN: 1,//主线 + DC: 2,//每日挑战 + }, + + DEFAULT_STAGE_ID: "main",//主线关卡标识 + + DIFFICULTY_TYPE: {//难度 - Easy: 1, - Medium: 2, - Hard: 3, - Expert: 4, - Extreme: 5, + Easy: "Easy", + Medium: "Medium", + Hard: "Hard", + Expert: "Expert", + Extreme: "Extreme", }, BLOCK_COLOR: { diff --git a/src/constants/respath.ts b/src/constants/respath.ts index 3a319ed..e1b8c8a 100644 --- a/src/constants/respath.ts +++ b/src/constants/respath.ts @@ -7,5 +7,6 @@ export const respath = { gamedone_ui_res: "resources/GameDone.lh", score_add_ui_res: "resources/ScoreAdd.lh", + difficulty_ui_res: "resources/Difficulty.lh", } diff --git a/src/models/DOStage.ts b/src/models/DOStage.ts index cf2c6d8..da278ea 100644 --- a/src/models/DOStage.ts +++ b/src/models/DOStage.ts @@ -3,6 +3,7 @@ import { StorageManager } from "./StorageManager" import { DOBlock } from "./DOBlock" import { DataBlock, DataUndo, DataStage } from "../types/global" +import { LevelManager } from "./LevelManager" export class DOStage { @@ -13,7 +14,7 @@ export class DOStage { private letterToNumber: Map; private numberToLetter: Map; - constructor(dataStage: DataStage, levelStr: string) { + constructor(dataStage: DataStage) { this.data = dataStage this.letterToNumber = new Map(); @@ -44,8 +45,9 @@ export class DOStage { blockMap.set(dataBlock.index, dataBlock) } - if (levelStr.length != 81) { - console.log("levelStr error", levelStr.length) + var levelStr = LevelManager.getInstance().getLevelStr(this.data.difficulty, this.data.index) + if (!levelStr || levelStr.length != 81) { + console.log("levelStr error", this.data.difficulty, this.data.index, levelStr) } var list = new Map(); for (var i=0; i { + return this.data.dones + } + public add_done(stageID: string): void { + if (this.data.dones.indexOf(stageID) < 0) { + this.data.dones.push(stageID) + StorageManager.getInstance().saveUser() + } + } + + public get_progress(difficulty: string): number { + var find: DataProgress + for (var i=0; i> = new Map() + + public init(): void { + this.levelMap.set(config.DIFFICULTY_TYPE.Easy, Easy) + this.levelMap.set(config.DIFFICULTY_TYPE.Medium, Medium) + this.levelMap.set(config.DIFFICULTY_TYPE.Hard, Hard) + this.levelMap.set(config.DIFFICULTY_TYPE.Expert, Expert) + this.levelMap.set(config.DIFFICULTY_TYPE.Extreme, Extreme) + //检查关卡配置 + this.levelMap.forEach((list, key)=>{ + for (var i=0; i>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", key, i) + } + } + }) + } + + public getLevelStr(difficulty: string, index: number): string { + var list = this.levelMap.get(difficulty) + if (list) { + return list[index] + } + return "" + } +} diff --git a/src/models/LevelManager.ts.meta b/src/models/LevelManager.ts.meta new file mode 100644 index 0000000..4154f04 --- /dev/null +++ b/src/models/LevelManager.ts.meta @@ -0,0 +1,3 @@ +{ + "uuid": "4b2967ad-786a-4ad1-8b1d-22b093d62575" +} \ No newline at end of file diff --git a/src/models/StorageManager.ts b/src/models/StorageManager.ts index d7207f9..5d15185 100644 --- a/src/models/StorageManager.ts +++ b/src/models/StorageManager.ts @@ -1,6 +1,8 @@ -import { config } from "../constants/config" + + import { DataStage, createDataStage } from "../types/global" import { DOStage } from "./DOStage" +import { DOUser } from "./DOUser" export class StorageManager { @@ -13,58 +15,96 @@ export class StorageManager { return StorageManager.instance } - private changed = false + private user: DOUser; private stageID: string = ""; - private stageMap: Map = new Map(); + private stageChanged = false + private stageMap: Map = new Map(); + public init(): void { - this.changed = false + if (!this.user) { + var jsonStr = Laya.LocalStorage.getItem("user") + if (jsonStr) { + this.user = new DOUser(JSON.parse(jsonStr)) + } + else { + this.user = new DOUser({isCompletedMain: true, dones: new Array(), progresses: new Array()}) + } + } + this.stageID = "" + this.stageChanged = false } + + public getUser(): DOUser { + return this.user + } + public saveUser(): void { + if (this.user) { + var jsonStr = JSON.stringify(this.user.getData()) + Laya.LocalStorage.setItem("user", jsonStr) + } + } + + + public cleanStage(stageID: string): void { + if (this.stageMap.has(stageID)) { + this.stageMap.delete(stageID) + } + Laya.LocalStorage.removeItem(stageID) + this.stageID = "" + this.stageChanged = false + } + public newStage(stageID: string, type: number, name: string, difficulty: string, index: number): DOStage { + this.stageID = stageID + this.stageChanged = false + var dataStage: DataStage = createDataStage(stageID, type, name, difficulty, index) + var doStage: DOStage = new DOStage(dataStage) + this.stageMap.set(stageID, doStage) + return doStage + } public loadStage(stageID: string): DOStage { this.stageID = stageID - var dataStage: DataStage + this.stageChanged = false if (this.stageMap.has(stageID)) { - dataStage = this.stageMap.get(stageID) + var doStage: DOStage = this.stageMap.get(stageID) + return doStage } else { var jsonStr = Laya.LocalStorage.getItem(stageID) if (jsonStr) { - dataStage = JSON.parse(jsonStr) - this.stageMap.set(stageID, dataStage) - } - else { - dataStage = createDataStage("first", "", config.DIFFICULTY_TYPE.Easy) - this.stageMap.set(stageID, dataStage) + var dataStage: DataStage = JSON.parse(jsonStr) + var doStage: DOStage = new DOStage(dataStage) + this.stageMap.set(stageID, doStage) + return doStage } } - var levelStr = "aBCeIGFhdEDFcAHBGIhigBdfecAgHDiFBCaeBEAGHCIdffcIdEAHbgcABfGEdiHIFHaCDGEBDGEHbiaFC" - return new DOStage(dataStage, levelStr) + return null } - - 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 + if (this.stageChanged) { + this.stageChanged = false if (this.stageMap.has(this.stageID)) { - var dataStage = this.stageMap.get(this.stageID) - var jsonStr = JSON.stringify(dataStage) + var doStage = this.stageMap.get(this.stageID) + var jsonStr = JSON.stringify(doStage.getData()) Laya.LocalStorage.setItem(this.stageID, jsonStr) } } } - public onChanged(): void { - this.changed = true + this.stageChanged = true } + + + public cleanAll(): void { + this.user = new DOUser({isCompletedMain: true, dones: new Array(), progresses: new Array()}) + + this.stageID = "" + this.stageChanged = false + this.stageMap.clear() + + Laya.LocalStorage.clear() + } + } \ No newline at end of file diff --git a/src/models/UIManager.ts b/src/models/UIManager.ts index bb07a03..c39cbf4 100644 --- a/src/models/UIManager.ts +++ b/src/models/UIManager.ts @@ -12,10 +12,10 @@ export class UIManager extends Laya.Script { private static _instance: UIManager onAwake(): void { UIManager._instance = this + } - StorageManager.getInstance().init() - - this.loadHome() + onStart(): void { + this.loadHomeUI() } public static getInstance(): UIManager { @@ -24,51 +24,49 @@ export class UIManager extends Laya.Script { private stage: Stage - public loadHome(): void { + + public getUIRoot(): Laya.Node { + return this.owner + } + + public loadHomeUI(): void { Laya.loader.load(respath.home_ui_res).then((go)=>{ var prefab = go.create() - this.owner.addChild(prefab) + this.getUIRoot().addChild(prefab) }) } - public loadStage(stageID: string, clean: boolean=false): void { - if (clean) { - StorageManager.getInstance().cleanStage() - } + public loadStageUI(stageID: string): void { 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 = this.getUIRoot().addChild(prefab).getComponent(Stage) this.stage.onLoadStage(StorageManager.getInstance().loadStage(stageID)) }) } } - public closeStage(): void { + public closeStageUI(): void { if (this.stage) { this.stage.owner.destroy() this.stage = null } } - public loadGameOver(): void { + public loadGameOverUI(): void { Laya.loader.load(respath.gameover_ui_res).then((go)=>{ var prefab = go.create() - this.owner.addChild(prefab) + this.getUIRoot().addChild(prefab) }) } - public loadGameDone(): void { + public loadGameDoneUI(): void { Laya.loader.load(respath.gamedone_ui_res).then((go)=>{ var prefab = go.create() - this.owner.addChild(prefab) + this.getUIRoot().addChild(prefab) }) } - onLateUpdate(): void { - StorageManager.getInstance().saveStage() - } - } diff --git a/src/types/global.ts b/src/types/global.ts index dded862..6057fb0 100644 --- a/src/types/global.ts +++ b/src/types/global.ts @@ -18,8 +18,10 @@ export interface DataUndo { //关卡数据 export interface DataStage { id: string, + type: number, name: string, - difficulty: number, + difficulty: string, + index: number, mistake?: number, duration?: number, note_open?: boolean, @@ -28,8 +30,8 @@ export interface DataStage { blocks?: Array, undos?: Array, } -export function createDataStage(id: string, name: string, difficulty: number): DataStage { - var data: DataStage = {id: id, name: name, difficulty: difficulty} +export function createDataStage(id: string, type: number, name: string, difficulty: string, index: number): DataStage { + var data: DataStage = {id: id, type: type, name: name, difficulty: difficulty, index: index} data.mistake = 0 data.duration = 0 data.note_open = false @@ -38,4 +40,15 @@ export function createDataStage(id: string, name: string, difficulty: number): D data.blocks = new Array() data.undos = new Array() return data +} + + +export interface DataProgress { + difficulty: string, + index: number, +} +export interface DataUser { + isCompletedMain: boolean,//当前主线是否已完成 默认true + dones: Array,//已完成关卡 + progresses: Array,//已经完成的进度 } \ No newline at end of file diff --git a/src/utils/utility.ts b/src/utils/utility.ts new file mode 100644 index 0000000..75beba8 --- /dev/null +++ b/src/utils/utility.ts @@ -0,0 +1,15 @@ + + + +export function Utility_ConvertSecondToString(second: number) { + var last = second + 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) + function format(value: number) { + return value>=10?value.toString():("0"+value) + } + return `${format(hour)}:${format(minite)}:${format(second)}` +} \ No newline at end of file diff --git a/src/utils/utility.ts.meta b/src/utils/utility.ts.meta new file mode 100644 index 0000000..8e69aed --- /dev/null +++ b/src/utils/utility.ts.meta @@ -0,0 +1,3 @@ +{ + "uuid": "d17f1a58-98e1-4a84-8bd0-8612a1662cea" +} \ No newline at end of file diff --git a/src/views/CommonData.ts b/src/views/CommonData.ts new file mode 100644 index 0000000..b2ba271 --- /dev/null +++ b/src/views/CommonData.ts @@ -0,0 +1,13 @@ +const { regClass, property } = Laya; + +@regClass() +export class CommonData extends Laya.Script { + declare owner : Laya.Box; + + @property(Number) + public intValue: number = 0; + + @property(String) + public strValue: string = ""; + +} \ No newline at end of file diff --git a/src/views/CommonData.ts.meta b/src/views/CommonData.ts.meta new file mode 100644 index 0000000..bce328e --- /dev/null +++ b/src/views/CommonData.ts.meta @@ -0,0 +1,3 @@ +{ + "uuid": "8857686b-9b2c-4e9c-af0f-0164c0994e46" +} \ No newline at end of file diff --git a/src/views/Difficulty.ts b/src/views/Difficulty.ts index e1e841a..6b6c354 100644 --- a/src/views/Difficulty.ts +++ b/src/views/Difficulty.ts @@ -1,3 +1,6 @@ +import { config } from "../constants/config"; +import { CommonData } from "./CommonData"; + const { regClass, property } = Laya; @regClass() @@ -7,29 +10,45 @@ export class Difficulty extends Laya.Script { @property(Laya.Box) public obj_items: Laya.Box; - private items: Array = new Array() + //组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次 - //onAwake(): void {} + onAwake(): void { + var offset = this.owner.getChildByName("offset") as Laya.Box + var bg = offset.getChildByName("bg") as Laya.Sprite + bg.graphics.clear() + bg.graphics.drawRoundRect(0, 0, offset.width, offset.height, 20, 20, 0, 0, "#f5f7fb") - //组件被启用后执行,例如节点被添加到舞台后 - //onEnable(): void {} + Laya.Tween.to(offset, {y: 560}, 500) - //组件被禁用时执行,例如从节点从舞台移除后 - //onDisable(): void {} + var mask = this.owner.getChildByName("mask") + mask.on(Laya.Event.CLICK, this, ()=>{ + Laya.Tween.to(offset, {y: 3000}, 500, null, Laya.Handler.create(this, () => { + this.owner.destroy() + })) + }) + } - //第一次执行update之前执行,只会执行一次 - //onStart(): void {} - - //手动调用节点销毁时执行 - //onDestroy(): void {} - - //每帧更新时执行,尽量不要在这里写大循环逻辑或者使用getComponent方法 - //onUpdate(): void {} - - //每帧更新时执行,在update之后执行,尽量不要在这里写大循环逻辑或者使用getComponent方法 - //onLateUpdate(): void {} - - //鼠标点击后执行。与交互相关的还有onMouseDown等十多个函数,具体请参阅文档。 - //onMouseClick(): void {} + public onInit(callback: any): void { + var list: Array = new Array() + list.push(config.DIFFICULTY_TYPE.Easy) + list.push(config.DIFFICULTY_TYPE.Medium) + list.push(config.DIFFICULTY_TYPE.Hard) + list.push(config.DIFFICULTY_TYPE.Expert) + list.push(config.DIFFICULTY_TYPE.Extreme) + for (var i=0; i{ + var data = evt.target.getComponent(CommonData) + if (callback) { + callback(data.strValue) + } + this.owner.destroy() + }) + } + } } \ No newline at end of file diff --git a/src/views/GameOver.ts b/src/views/GameOver.ts index 32678f8..c50682f 100644 --- a/src/views/GameOver.ts +++ b/src/views/GameOver.ts @@ -1,4 +1,9 @@ +import { respath } from "../constants/respath"; +import { config } from "../constants/config"; import { UIManager } from "../models/UIManager"; +import { StorageManager } from "../models/StorageManager"; +import { LevelManager } from "../models/LevelManager"; +import { Difficulty } from "./Difficulty"; const { regClass, property } = Laya; @@ -16,13 +21,35 @@ export class GameOver extends Laya.Script { //组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次 onAwake(): void { this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => { - UIManager.getInstance().loadStage("first", true); - this.owner.destroy() + var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID) + var difficulty = doStage.get_difficulty() + StorageManager.getInstance().cleanStage(config.DEFAULT_STAGE_ID) + var user = StorageManager.getInstance().getUser() + user.set_isCompletedMain(false) + StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, difficulty, difficulty, user.get_progress(difficulty)) + UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID); + this.owner.destroy() }) this.btn_new.on(Laya.Event.CLICK, this, (evt: Laya.Event) => { - UIManager.getInstance().loadStage("first", true); - this.owner.destroy() + Laya.loader.load(respath.difficulty_ui_res).then((go)=>{ + var prefab = go.create() + var d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty) + d.onInit((value: string)=> { + console.log("选择难度", value) + StorageManager.getInstance().cleanStage(config.DEFAULT_STAGE_ID) + var user = StorageManager.getInstance().getUser() + user.set_isCompletedMain(false) + var index = user.get_progress(value) + var levelStr = LevelManager.getInstance().getLevelStr(value, index) + if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始 + user.update_progress(value, 0) + } + StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value, user.get_progress(value)) + UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID); + this.owner.destroy() + }) + }) }) } diff --git a/src/views/Home.ts b/src/views/Home.ts index 3343734..a7cf5cd 100644 --- a/src/views/Home.ts +++ b/src/views/Home.ts @@ -1,6 +1,11 @@ import { UIManager } from "../models/UIManager"; import { StorageManager } from "../models/StorageManager"; +import { respath } from "../constants/respath"; +import { Difficulty } from "./Difficulty"; +import { LevelManager } from "../models/LevelManager"; +import { config } from "../constants/config"; +import { Utility_ConvertSecondToString } from "../utils/utility"; const { regClass, property } = Laya @@ -9,23 +14,71 @@ export class Home extends Laya.Script { declare owner : Laya.Box; @property(Laya.Box) - public btn_start: Laya.Box; + public btn_new_blue: Laya.Box; + + @property(Laya.Box) + public btn_continue: Laya.Box; + @property(Laya.Box) + public btn_new_white: Laya.Box; @property(Laya.Box) public btn_clean: Laya.Box; //组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次 onAwake(): void { - this.btn_start.on(Laya.Event.CLICK, this, (evt: Laya.Event) => { - console.log("btn_start=", evt); - UIManager.getInstance().loadStage("first"); + this.btn_new_blue.on(Laya.Event.CLICK, this, this.onClickNew) + this.btn_new_white.on(Laya.Event.CLICK, this, this.onClickNew) + this.btn_continue.on(Laya.Event.CLICK, this, (evt: Laya.Event)=>{ + UIManager.getInstance().closeStageUI() + UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID); this.owner.destroy() }) + var user = StorageManager.getInstance().getUser() + this.btn_new_blue.visible = user.get_isCompletedMain() + this.btn_new_white.visible = user.get_isCompletedMain() == false + this.btn_continue.visible = user.get_isCompletedMain() == false + if (user.get_isCompletedMain() == false) { + var label_time = this.btn_continue.getChildByName("time").getChildByName("label_time") as Laya.Label + var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID) + var duration = doStage.get_duration() + var timeStr = Utility_ConvertSecondToString(duration) + label_time.text = `${timeStr} - ${doStage.get_difficulty()}` + } + + //测试逻辑 this.btn_clean.on(Laya.Event.CLICK, this, (evt: Laya.Event) => { console.log("btn_clean=", evt); - StorageManager.getInstance().cleanStage() - Laya.LocalStorage.clear() + StorageManager.getInstance().cleanAll() + user = StorageManager.getInstance().getUser() + this.btn_new_blue.visible = user.get_isCompletedMain() + this.btn_new_white.visible = user.get_isCompletedMain() == false + this.btn_continue.visible = user.get_isCompletedMain() == false + }) + this.btn_clean.visible = config.DEBUG + //====== + } + + public onClickNew(evt: Laya.Event): void { + Laya.loader.load(respath.difficulty_ui_res).then((go)=>{ + var prefab = go.create() + var d = UIManager.getInstance().getUIRoot().addChild(prefab).getComponent(Difficulty) + d.onInit((value: string)=> { + console.log("选择难度", value) + UIManager.getInstance().closeStageUI() + + StorageManager.getInstance().cleanStage(config.DEFAULT_STAGE_ID) + var user = StorageManager.getInstance().getUser() + user.set_isCompletedMain(false) + var index = user.get_progress(value) + var levelStr = LevelManager.getInstance().getLevelStr(value, index) + if (!levelStr || levelStr.length <= 0) {//说明当前难度已经打通了,所以给他从头开始 + user.update_progress(value, 0) + } + StorageManager.getInstance().newStage(config.DEFAULT_STAGE_ID, config.STAGE_TYPE.MAIN, value, value, user.get_progress(value)) + UIManager.getInstance().loadStageUI(config.DEFAULT_STAGE_ID); + this.owner.destroy() + }) }) } diff --git a/src/views/Stage.ts b/src/views/Stage.ts index f27e1d7..b46be9c 100644 --- a/src/views/Stage.ts +++ b/src/views/Stage.ts @@ -4,6 +4,8 @@ import { Block } from "./Block"; import { Candy } from "./Candy"; import { DOStage } from "../models/DOStage"; import { config } from "../constants/config"; +import { StorageManager } from "../models/StorageManager"; +import { Utility_ConvertSecondToString } from "../utils/utility"; const { regClass, property } = Laya; @@ -56,8 +58,8 @@ export class Stage extends Laya.Script { //组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次 onAwake(): void { this.btn_back.on(Laya.Event.CLICK, this, ()=>{ - UIManager.getInstance().loadHome(); - UIManager.getInstance().closeStage(); + UIManager.getInstance().loadHomeUI(); + UIManager.getInstance().closeStageUI(); }) for (var i=0; i{ @@ -108,12 +111,7 @@ export class Stage extends Laya.Script { this.data.set_duration(this.data.get_duration() + Math.floor((now-begin)/1000)) begin = now var last = this.data.get_duration() - 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)}` + this.label_time.text = Utility_ConvertSecondToString(last) }) var blocks = doStage.get_blocks() @@ -335,7 +333,16 @@ export class Stage extends Laya.Script { if (b) { if (this.getIsComplete()) { console.log("完成关卡") - UIManager.getInstance().loadGameDone() + StorageManager.getInstance().cleanStage(this.data.get_stageID())//完成关卡清除关卡数据 + var user = StorageManager.getInstance().getUser() + if (this.data.get_stageType() == config.STAGE_TYPE.MAIN) { + user.set_isCompletedMain(true) + user.update_progress(this.data.get_difficulty(), this.data.get_stageIndex()+1) + } + else if (this.data.get_stageType() == config.STAGE_TYPE.DC) { + user.add_done(this.data.get_stageID()) + } + UIManager.getInstance().loadGameDoneUI() } } else {//失败 @@ -343,7 +350,7 @@ export class Stage extends Laya.Script { this.onUpdateMistake() if (this.data.get_mistake() >= config.MISTAKE_MAX) { console.log("关卡失败") - // UIManager.getInstance().loadGameOver() + UIManager.getInstance().loadGameOverUI() } } }