添加广播逻辑
This commit is contained in:
@@ -11,78 +11,272 @@
|
|||||||
"right": 0,
|
"right": 0,
|
||||||
"top": 0,
|
"top": 0,
|
||||||
"bottom": 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": [
|
"_$child": [
|
||||||
{
|
{
|
||||||
"_$id": "li6t446m",
|
"_$id": "0a0ovv4z",
|
||||||
"_$type": "Image",
|
"_$type": "Box",
|
||||||
"name": "bg",
|
"name": "center",
|
||||||
"x": 90,
|
"x": 96,
|
||||||
"y": 404,
|
"y": 420,
|
||||||
"width": 900,
|
"width": 888,
|
||||||
"height": 1112,
|
"height": 1080,
|
||||||
"_mouseState": 2,
|
"_mouseState": 2,
|
||||||
"centerX": 0,
|
"centerX": 0,
|
||||||
"centerY": 0,
|
"centerY": 0,
|
||||||
"skin": "res://6ad19646-ed7a-431c-a50e-65c2bcb40751",
|
"_$child": [
|
||||||
"sizeGrid": "40,60,50,60,0",
|
{
|
||||||
"color": "#ffffff"
|
"_$id": "xs71kk61",
|
||||||
},
|
"_$type": "Sprite",
|
||||||
{
|
"name": "Sprite",
|
||||||
"_$id": "sco68sr2",
|
"width": 888,
|
||||||
"_$type": "Button",
|
"height": 1080,
|
||||||
"name": "btn_restart",
|
"_gcmds": [
|
||||||
"x": 172,
|
{
|
||||||
"y": 1032,
|
"_$type": "DrawRoundRectCmd",
|
||||||
"width": 736,
|
"x": 0,
|
||||||
"height": 152,
|
"y": 0,
|
||||||
"_mouseState": 2,
|
"width": 1,
|
||||||
"centerX": 0,
|
"height": 1,
|
||||||
"centerY": 148,
|
"lt": 20,
|
||||||
"stateNum": 1,
|
"rt": 20,
|
||||||
"skin": "res://2e8c9585-e650-4494-a329-807fd2d2a532",
|
"lb": 20,
|
||||||
"sizeGrid": "24,40,24,40,0",
|
"rb": 20,
|
||||||
"label": "重新开始",
|
"percent": true,
|
||||||
"labelFont": "",
|
"lineWidth": 1,
|
||||||
"labelSize": 60,
|
"fillColor": "#FFFFFF"
|
||||||
"labelBold": true,
|
}
|
||||||
"labelColors": "#1d5cdc,#1d5cdc,#1d5cdc",
|
]
|
||||||
"labelAlign": "center",
|
},
|
||||||
"labelVAlign": "middle"
|
{
|
||||||
},
|
"_$id": "xz2d429f",
|
||||||
{
|
"_$type": "VBox",
|
||||||
"_$id": "p8wk9udp",
|
"name": "buttons",
|
||||||
"_$type": "Button",
|
"x": 72,
|
||||||
"name": "btn_new",
|
"y": 420,
|
||||||
"x": 172,
|
"width": 744,
|
||||||
"y": 1234,
|
"height": 600,
|
||||||
"width": 736,
|
"centerX": 0,
|
||||||
"height": 152,
|
"centerY": 180,
|
||||||
"_mouseState": 2,
|
"space": 48,
|
||||||
"centerX": 0,
|
"align": "center",
|
||||||
"centerY": 350,
|
"_$child": [
|
||||||
"stateNum": 1,
|
{
|
||||||
"skin": "res://2e8c9585-e650-4494-a329-807fd2d2a532",
|
"_$id": "0w6x8zzw",
|
||||||
"sizeGrid": "24,40,24,40,0",
|
"_$type": "Sprite",
|
||||||
"label": "新游戏",
|
"name": "btn_second",
|
||||||
"labelFont": "",
|
"width": 744,
|
||||||
"labelSize": 60,
|
"height": 156,
|
||||||
"labelBold": true,
|
"_gcmds": [
|
||||||
"labelColors": "#1d5cdc,#1d5cdc,#1d5cdc",
|
{
|
||||||
"labelAlign": "center",
|
"_$type": "DrawRoundRectCmd",
|
||||||
"labelVAlign": "middle"
|
"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",
|
"_$id": "jkqju6ok",
|
||||||
"_$type": "Label",
|
"_$type": "Label",
|
||||||
"name": "Label",
|
"name": "Label",
|
||||||
"x": 172,
|
"x": 172,
|
||||||
"y": 510,
|
"y": 511,
|
||||||
"width": 736,
|
"width": 736,
|
||||||
"height": 100,
|
"height": 100,
|
||||||
"centerX": 0,
|
"centerX": 0,
|
||||||
"centerY": -400,
|
"centerY": -399,
|
||||||
"text": "游戏结束",
|
"text": "Game Over",
|
||||||
"font": "",
|
|
||||||
"fontSize": 80,
|
"fontSize": 80,
|
||||||
"color": "rgba(0, 0, 0, 1)",
|
"color": "rgba(0, 0, 0, 1)",
|
||||||
"bold": true,
|
"bold": true,
|
||||||
@@ -94,32 +288,19 @@
|
|||||||
"_$id": "39t7ygbe",
|
"_$id": "39t7ygbe",
|
||||||
"_$type": "Label",
|
"_$type": "Label",
|
||||||
"name": "Label(1)",
|
"name": "Label(1)",
|
||||||
"x": 172,
|
"x": 186,
|
||||||
"y": 667,
|
"y": 644,
|
||||||
"width": 736,
|
"width": 709,
|
||||||
"height": 300,
|
"height": 300,
|
||||||
"centerX": 0,
|
"centerX": 0,
|
||||||
"centerY": -143,
|
"centerY": -166,
|
||||||
"text": "你犯了3个错误所以你输掉了游戏",
|
"text": "You lost the game because you made 3 mistakes",
|
||||||
"font": "",
|
"fontSize": 50,
|
||||||
"fontSize": 60,
|
|
||||||
"color": "rgba(123, 129, 140, 1)",
|
"color": "rgba(123, 129, 140, 1)",
|
||||||
"align": "center",
|
"align": "center",
|
||||||
"valign": "top",
|
"valign": "top",
|
||||||
"wordWrap": true,
|
"wordWrap": true,
|
||||||
"padding": "0,0,0,0"
|
"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"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
50
src/models/EventManager.ts
Normal file
50
src/models/EventManager.ts
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
src/models/EventManager.ts.meta
Normal file
3
src/models/EventManager.ts.meta
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"uuid": "1784429c-7fbe-47bc-8281-9a34510da81b"
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import { config } from "../constants/config";
|
|||||||
import { UIManager } from "../models/UIManager";
|
import { UIManager } from "../models/UIManager";
|
||||||
import { StorageManager } from "../models/StorageManager";
|
import { StorageManager } from "../models/StorageManager";
|
||||||
import { LevelManager } from "../models/LevelManager";
|
import { LevelManager } from "../models/LevelManager";
|
||||||
|
import { EventManager, EVENT_TYPES } from "../models/EventManager";
|
||||||
import { Difficulty } from "./Difficulty";
|
import { Difficulty } from "./Difficulty";
|
||||||
|
|
||||||
const { regClass, property } = Laya;
|
const { regClass, property } = Laya;
|
||||||
@@ -12,14 +13,25 @@ export class GameOver extends Laya.Script {
|
|||||||
declare owner : Laya.Box;
|
declare owner : Laya.Box;
|
||||||
|
|
||||||
|
|
||||||
@property(Laya.Button)
|
@property(Laya.Sprite)
|
||||||
public btn_restart: Laya.Button
|
public btn_second: Laya.Sprite
|
||||||
|
|
||||||
@property(Laya.Button)
|
@property(Laya.Sprite)
|
||||||
public btn_new: Laya.Button
|
public btn_restart: Laya.Sprite
|
||||||
|
|
||||||
|
@property(Laya.Sprite)
|
||||||
|
public btn_new: Laya.Sprite
|
||||||
|
|
||||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
||||||
onAwake(): void {
|
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) => {
|
this.btn_restart.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||||
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
|
var doStage = StorageManager.getInstance().loadStage(config.DEFAULT_STAGE_ID)
|
||||||
var difficulty = doStage.get_difficulty()
|
var difficulty = doStage.get_difficulty()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { DOStage } from "../models/DOStage";
|
|||||||
import { config } from "../constants/config";
|
import { config } from "../constants/config";
|
||||||
import { StorageManager } from "../models/StorageManager";
|
import { StorageManager } from "../models/StorageManager";
|
||||||
import { Utility_ConvertSecondToString } from "../utils/utility";
|
import { Utility_ConvertSecondToString } from "../utils/utility";
|
||||||
|
import { EVENT_TYPES, EventManager } from "../models/EventManager";
|
||||||
|
|
||||||
|
|
||||||
const { regClass, property } = Laya;
|
const { regClass, property } = Laya;
|
||||||
@@ -54,9 +55,9 @@ export class Stage extends Laya.Script {
|
|||||||
private data: DOStage;
|
private data: DOStage;
|
||||||
private selectedBlock: Block;
|
private selectedBlock: Block;
|
||||||
|
|
||||||
|
private static _instance: Stage
|
||||||
//组件被激活后执行,此时所有节点和组件均已创建完毕,此方法只执行一次
|
|
||||||
onAwake(): void {
|
onAwake(): void {
|
||||||
|
Stage._instance = this
|
||||||
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
|
this.btn_back.on(Laya.Event.CLICK, this, ()=>{
|
||||||
UIManager.getInstance().loadHomeUI();
|
UIManager.getInstance().loadHomeUI();
|
||||||
UIManager.getInstance().closeStageUI();
|
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_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_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
|
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 {
|
public onLoadStage(doStage: DOStage): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user