Options
All
  • Public
  • Public/Protected
  • All
Menu

状态化的游戏

Type parameters

Hierarchy

Index

Constructors

constructor

  • new StatefulGame(room: Room, masterClient: Client, state: State, events?: EventHandlers<State, Event, EP>, filter?: (state: State, player: Player) => State): StatefulGame
  • Parameters

    • room: Room
    • masterClient: Client
    • state: State
    • Default value events: EventHandlers<State, Event, EP> = {}
    • Default value filter: (state: State, player: Player) => State = (s: State,player: Player) => s
        • (state: State, player: Player): State
        • Parameters

          • state: State
          • player: Player

          Returns State

    Returns StatefulGame

Properties

Protected customEvent$

customEvent$: Observable<{ eventData: CustomEventData; eventId: number; senderId: number }>

customEvents Observable

Protected events

events: EventHandlers<State, Event, EP>

Protected filter

filter: (state: State, player: Player) => State

Type declaration

    • (state: State, player: Player): State
    • Parameters

      • state: State
      • player: Player

      Returns State

masterClient

masterClient: Client

registeredPlayers

registeredPlayers: Set<string>

room

room: Room

Protected state

state: State

Static defaultSeatCount

defaultSeatCount: number

每局游戏房间的默认空位数量。

Static Optional maxSeatCount

maxSeatCount: undefined | number

每局游戏房间的最大空位数量。

Static Optional minSeatCount

minSeatCount: undefined | number

每局游戏房间的最小空位数量。

Accessors

availableSeatCount

  • get availableSeatCount(): number

players

  • get players(): Player[]
  • 不包含 masterClient 的玩家列表。

    Returns Player[]

seatCount

  • get seatCount(): number
  • 游戏房间的空位数量

    Returns number

Methods

addListener

  • addListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

Protected broadcast

  • broadcast(eventId: CustomEventId, eventData?: undefined | {}, options?: undefined | { exclude?: number[] }): Promise<void>
  • 向玩家广播自定义事件。

    Parameters

    • eventId: CustomEventId
    • Optional eventData: undefined | {}
    • Optional options: undefined | { exclude?: number[] }

    Returns Promise<void>

Protected broadcastState

  • broadcastState(): void

cancelReservation

  • cancelReservation(playerId: string): void

destroy

  • destroy(): void
  • Returns void

emit

  • emit(event: string | symbol, ...args: any[]): boolean
  • Parameters

    • event: string | symbol
    • Rest ...args: any[]

    Returns boolean

Protected emitEvent

  • emitEvent<N>(name: N, payload?: EP[N], options?: { emitter?: Player }): void
  • 派发游戏事件,在服务端派发的事件只会在服务端被处理

    Type parameters

    • N: Event

    Parameters

    • name: N

      事件名

    • Optional payload: EP[N]

      事件的有效载荷

    • Default value options: { emitter?: Player } = {}
      • Optional emitter?: Player

        以某位玩家的身份派发

    Returns void

eventNames

  • eventNames(): Array<string | symbol>

Protected forwardToTheRests

  • forwardToTheRests(originalEvent: CustomEventPayload, transform?: undefined | ((originalEventData: CustomEventData) => CustomEventData), eventId?: CustomEventId): Promise<void>
  • 向其他玩家转发自定义事件。 该方法会在转发后的事件内容中增加 originalSenderId 字段。

    Parameters

    • originalEvent: CustomEventPayload

      原始事件

    • Optional transform: undefined | ((originalEventData: CustomEventData) => CustomEventData)

      变形事件内容

    • Optional eventId: CustomEventId

      指定新的事件 ID

    Returns Promise<void>

getMaxListeners

  • getMaxListeners(): number

Protected getState

  • getState(): State

Protected getStream

  • getStream(eventId?: CustomEventId, player?: Player, timeout?: undefined | number): Observable<{ eventData: CustomEventData; eventId: number; senderId: number }>
  • 获取指定的自定义事件,指定 player 发送的事件流。 参阅 http://reactivex.io/rxjs 了解更多。

    Parameters

    • Optional eventId: CustomEventId
    • Optional player: Player
    • Optional timeout: undefined | number

    Returns Observable<{ eventData: CustomEventData; eventId: number; senderId: number }>

Protected handleEvent

  • handleEvent<N>(event: GameEvent<N, EP[N]>): void

listenerCount

  • listenerCount(event: string | symbol): number
  • Parameters

    • event: string | symbol

    Returns number

listeners

  • listeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

makeReservation

  • makeReservation(playerId: string): void
  • Parameters

    • playerId: string

    Returns void

off

  • off(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

rawListeners

  • rawListeners(event: string | symbol): Function[]
  • Parameters

    • event: string | symbol

    Returns Function[]

removeAllListeners

  • removeAllListeners(event?: string | symbol): this

removeListener

  • removeListener(event: string | symbol, listener: (...args: any[]) => void): this
  • Parameters

    • event: string | symbol
    • listener: (...args: any[]) => void
        • (...args: any[]): void
        • Parameters

          • Rest ...args: any[]

          Returns void

    Returns this

setMaxListeners

  • setMaxListeners(n: number): this

Protected setState

  • setState(state: Partial<State>): void

Protected takeFirst

  • takeFirst(eventId?: CustomEventId, player?: Player, timeout?: undefined | number): Observable<{ eventData: CustomEventData; eventId: number; senderId: number }>
  • 获取指定的自定义事件,指定 player 发送的从现在开始算的第一个事件的流。 参阅 http://reactivex.io/rxjs 了解更多。

    Parameters

    • Optional eventId: CustomEventId
    • Optional player: Player
    • Optional timeout: undefined | number

    Returns Observable<{ eventData: CustomEventData; eventId: number; senderId: number }>

terminate

  • terminate(): Promise<any>
  • 当收到服务关闭通知时,游戏的结束逻辑。 默认情况下,会等游戏结束或者所有玩家离开房间后认为该局游戏可以下线了。 你可以在子类中扩展或覆盖该行为。

    Returns Promise<any>

Legend

  • Object literal
  • Variable
  • Function with type parameter
  • Type alias with type parameter
  • Interface
  • Interface with type parameter
  • Class with type parameter
  • Constructor
  • Inherited property
  • Inherited method
  • Protected property
  • Protected method
  • Enumeration

Generated using TypeDoc