添加广播逻辑

This commit is contained in:
2025-05-19 20:58:15 +08:00
parent ce53eda29c
commit b6c1e58f35
5 changed files with 342 additions and 83 deletions

View File

@@ -11,78 +11,272 @@
"right": 0,
"top": 0,
"bottom": 0,
"_$comp": [
{
"_$type": "72a5ccd3-8177-451c-b2ce-cf1b42f7e6d4",
"scriptPath": "../src/views/GameOver.ts",
"btn_second": {
"_$ref": "0w6x8zzw"
},
"btn_restart": {
"_$ref": "y7aniaui"
},
"btn_new": {
"_$ref": "eepsaznr"
}
}
],
"_$child": [
{
"_$id": "li6t446m",
"_$type": "Image",
"name": "bg",
"x": 90,
"y": 404,
"width": 900,
"height": 1112,
"_$id": "0a0ovv4z",
"_$type": "Box",
"name": "center",
"x": 96,
"y": 420,
"width": 888,
"height": 1080,
"_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": "",
"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": "",
"labelSize": 60,
"labelBold": true,
"labelColors": "#1d5cdc,#1d5cdc,#1d5cdc",
"labelAlign": "center",
"labelVAlign": "middle"
"_$child": [
{
"_$id": "xs71kk61",
"_$type": "Sprite",
"name": "Sprite",
"width": 888,
"height": 1080,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 20,
"rt": 20,
"lb": 20,
"rb": 20,
"percent": true,
"lineWidth": 1,
"fillColor": "#FFFFFF"
}
]
},
{
"_$id": "xz2d429f",
"_$type": "VBox",
"name": "buttons",
"x": 72,
"y": 420,
"width": 744,
"height": 600,
"centerX": 0,
"centerY": 180,
"space": 48,
"align": "center",
"_$child": [
{
"_$id": "0w6x8zzw",
"_$type": "Sprite",
"name": "btn_second",
"width": 744,
"height": 156,
"_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)"
}
],
"_$child": [
{
"_$id": "23po992p",
"_$type": "Sprite",
"name": "Sprite",
"x": 68,
"y": 51,
"width": 60,
"height": 54,
"_gcmds": [
{
"_$type": "DrawRoundRectCmd",
"x": 0,
"y": 0,
"width": 1,
"height": 1,
"lt": 10,
"rt": 10,
"lb": 10,
"rb": 10,
"percent": true,
"lineWidth": 1,
"fillColor": "#FFFFFF"
}
],
"_$child": [
{
"_$id": "7i8eqgi1",
"_$type": "Sprite",
"name": "Sprite",
"x": 16,
"y": 12,
"width": 32,
"height": 32,
"_gcmds": [
{
"_$type": "DrawPolyCmd",
"x": 0,
"y": 0,
"points": [
0,
0,
32,
16,
0,
32
],
"lineWidth": 1,
"fillColor": "rgba(29, 92, 220, 1)"
}
]
}
]
}
]
},
{
"_$id": "y7aniaui",
"_$type": "Sprite",
"name": "btn_restart",
"y": 204,
"width": 744,
"height": 156,
"alpha": 0.18,
"_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": "eepsaznr",
"_$type": "Sprite",
"name": "btn_new",
"y": 408,
"width": 744,
"height": 156,
"alpha": 0.18,
"_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": "17a1hg41",
"_$type": "VBox",
"name": "labels",
"x": 72,
"y": 420,
"width": 744,
"height": 600,
"centerX": 0,
"centerY": 180,
"space": 48,
"align": "center",
"_$child": [
{
"_$id": "4fv9wmfi",
"_$type": "Label",
"name": "Label(1)",
"width": 744,
"height": 156,
"text": "Second Chace",
"fontSize": 72,
"color": "rgba(255, 255, 255, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "o6codx3p",
"_$type": "Label",
"name": "Label(2)",
"y": 204,
"width": 744,
"height": 156,
"text": "Restart",
"fontSize": 72,
"color": "rgba(29, 92, 220, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
},
{
"_$id": "2r6iotpo",
"_$type": "Label",
"name": "Label(3)",
"y": 408,
"width": 744,
"height": 156,
"text": "New Game",
"fontSize": 72,
"color": "rgba(29, 92, 220, 1)",
"bold": true,
"align": "center",
"valign": "middle",
"padding": "0,0,0,0"
}
]
}
]
},
{
"_$id": "jkqju6ok",
"_$type": "Label",
"name": "Label",
"x": 172,
"y": 510,
"y": 511,
"width": 736,
"height": 100,
"centerX": 0,
"centerY": -400,
"text": "游戏结束",
"font": "",
"centerY": -399,
"text": "Game Over",
"fontSize": 80,
"color": "rgba(0, 0, 0, 1)",
"bold": true,
@@ -94,32 +288,19 @@
"_$id": "39t7ygbe",
"_$type": "Label",
"name": "Label(1)",
"x": 172,
"y": 667,
"width": 736,
"x": 186,
"y": 644,
"width": 709,
"height": 300,
"centerX": 0,
"centerY": -143,
"text": "你犯了3个错误所以你输掉了游戏",
"font": "",
"fontSize": 60,
"centerY": -166,
"text": "You lost the game because you made 3 mistakes",
"fontSize": 50,
"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,50 @@
export const EVENT_TYPES = {
NOT_UPDATE_MISTAKE: "NOT_UPDATE_MISTAKE",//更新分数
}
export class EventManager {
private static instance: EventManager
public static getInstance(): EventManager {
if (!EventManager.instance) {
EventManager.instance = new EventManager()
}
return EventManager.instance
}
private listeners: Map<string, Array<any>> = new Map()
public RegisterEvent(eventID: string, func: any): void {
if (this.listeners.has(eventID) == false) {
this.listeners.set(eventID, new Array())
}
var list: Array<any> = this.listeners.get(eventID)
var find = list.indexOf(func)
if (find < 0) {
list.push(func)
}
}
public UnregisterEvent(eventID: string, func: any): void {
if (this.listeners.has(eventID)) {
var list: Array<any> = this.listeners.get(eventID)
var find = list.indexOf(func)
if (find >= 0) {
list.splice(find, 1)
}
}
}
public DispatchEvent(eventID: string, arg: any): void {
if (this.listeners.has(eventID)) {
var list: Array<any> = this.listeners.get(eventID)
for (var i=0; i<list.length; i++) {
list[i](arg)
}
}
}
}

View File

@@ -0,0 +1,3 @@
{
"uuid": "1784429c-7fbe-47bc-8281-9a34510da81b"
}

View File

@@ -3,6 +3,7 @@ import { config } from "../constants/config";
import { UIManager } from "../models/UIManager";
import { StorageManager } from "../models/StorageManager";
import { LevelManager } from "../models/LevelManager";
import { EventManager, EVENT_TYPES } from "../models/EventManager";
import { Difficulty } from "./Difficulty";
const { regClass, property } = Laya;
@@ -12,14 +13,25 @@ export class GameOver extends Laya.Script {
declare owner : Laya.Box;
@property(Laya.Button)
public btn_restart: Laya.Button
@property(Laya.Sprite)
public btn_second: Laya.Sprite
@property(Laya.Button)
public btn_new: Laya.Button
@property(Laya.Sprite)
public btn_restart: Laya.Sprite
@property(Laya.Sprite)
public btn_new: Laya.Sprite
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
onAwake(): void {
this.btn_second.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
doStage.set_mistake(doStage.get_mistake()-1)
EventManager.getInstance().DispatchEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, "adsf")
this.owner.destroy()
})
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
var difficulty = doStage.get_difficulty()

View File

@@ -6,6 +6,7 @@ import { DOStage } from "../models/DOStage";
import { config } from "../constants/config";
import { StorageManager } from "../models/StorageManager";
import { Utility_ConvertSecondToString } from "../utils/utility";
import { EVENT_TYPES, EventManager } from "../models/EventManager";
const { regClass, property } = Laya;
@@ -54,9 +55,9 @@ export class Stage extends Laya.Script {
private data: DOStage;
private selectedBlock: Block;
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
private static _instance: Stage
onAwake(): void {
Stage._instance = this
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
UIManager.getInstance().loadHomeUI();
UIManager.getInstance().closeStageUI();
@@ -97,6 +98,18 @@ export class Stage extends Laya.Script {
this.btn_hint_normal = this.btn_hint.getChildByName("Image").getChildByName("normal") as Laya.Box
this.btn_hint_ad = this.btn_hint.getChildByName("Image").getChildByName("ad") as Laya.Box
this.btn_hint_label = this.btn_hint.getChildByName("Image").getChildByName("normal").getChildByName("label") as Laya.Label
EventManager.getInstance().RegisterEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, Stage.EventUpdateMistak)
}
onDestroy(): void {
EventManager.getInstance().UnregisterEvent(EVENT_TYPES.NOT_UPDATE_MISTAKE, Stage.EventUpdateMistak)
}
public static EventUpdateMistak(arg: any): void {
if (Stage._instance) {
Stage._instance.onUpdateMistake()
}
}
public onLoadStage(doStage: DOStage): void {