Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

  • EventEmitter
    • Game

Index

Constructors

constructor

  • new Game(room: Room, masterClient: Client): Game

Properties

Protected customEvent$

customEvent$: Observable<object> = fromEvent<CustomEventPayload>(this.masterClient,Event.CUSTOM_EVENT,)

customEvents Observable

masterClient

masterClient: Client

registeredPlayers

registeredPlayers: Set<string> = new Set<string>()

room

room: Room

Static defaultMaxListeners

defaultMaxListeners: number

Static defaultSeatCount

defaultSeatCount: number = 2

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

Static errorMonitor

errorMonitor: keyof symbol

This symbol shall be used to install a listener for only monitoring 'error' events. Listeners installed using this symbol are called before the regular 'error' listeners are called.

Installing a listener using this symbol does not change the behavior once an 'error' event is emitted, therefore the process will still crash if no regular 'error' listener is installed.

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: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

Protected broadcast

  • broadcast(eventId: CustomEventId, eventData?: object, options?: object): Promise<void>
  • 向玩家广播自定义事件。

    Parameters

    • eventId: CustomEventId
    • Default value eventData: object = {}
      • [key: string]: any
    • Default value options: object = {}
      • Optional exclude?: number[]

    Returns Promise<void>

cancelReservation

  • cancelReservation(playerId: string): void

destroy

  • destroy(): void

emit

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

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

    Returns boolean

eventNames

  • eventNames(): Array<string | symbol>
  • Returns Array<string | symbol>

Protected forwardToTheRests

  • 向其他玩家转发自定义事件。 该方法会在转发后的事件内容中增加 originalSenderId 字段。

    Parameters

    • originalEvent: CustomEventPayload

      原始事件

    • Default value transform: function = (data) => data

      变形事件内容

        • (originalEventData: CustomEventData): CustomEventData
        • Parameters

          • originalEventData: CustomEventData

          Returns CustomEventData

    • Default value eventId: CustomEventId = originalEvent.eventId

      指定新的事件 ID

    Returns Promise<void>

getMaxListeners

  • getMaxListeners(): number
  • Returns number

Protected getStream

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

    Parameters

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

    Returns Observable<object>

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

off

  • off(event: string | symbol, listener: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

on

  • on(event: string | symbol, listener: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

once

  • once(event: string | symbol, listener: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

prependListener

  • prependListener(event: string | symbol, listener: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

prependOnceListener

  • prependOnceListener(event: string | symbol, listener: function): this
  • Parameters

    • event: string | symbol
    • listener: function
        • (...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
  • Parameters

    • Optional event: string | symbol

    Returns this

removeListener

  • removeListener(event: string | symbol, listener: function): this
  • Parameters

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

          • Rest ...args: any[]

          Returns void

    Returns this

setMaxListeners

  • setMaxListeners(n: number): this
  • Parameters

    • n: number

    Returns this

Protected takeFirst

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

    Parameters

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

    Returns Observable<object>

terminate

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

    Returns Promise<any>

Static listenerCount

  • listenerCount(emitter: EventEmitter, event: string | symbol): number
  • deprecated

    since v4.0.0

    Parameters

    • emitter: EventEmitter
    • event: string | symbol

    Returns number

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Type alias with type parameter
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc