Options
All
  • Public
  • Public/Protected
  • All
Menu

Online game manager between two players

Hierarchy

  • OnlineGame

Index

Constructors

constructor

  • Build a new game manager

    Parameters

    • session: Game

      game information

    • io: Server

      Server socket reference

    • players: Array<string>

      Array of player tokens that will play this game

    • ui: GUI

      Optional GUI reference

    • options: Options

      Server startup options

    Returns OnlineGame

Properties

Private currentPlayer

currentPlayer: number

Private firstPlayer

firstPlayer: number

Private game

game: UTTT

Private gameStart

gameStart: [number, number]

Private gameUIId

gameUIId: number

Private io

io: Server

Private maxGames

maxGames: number

Private players

players: Array<string>

Private session

session: Game

Private state

state: State

Private timeout

timeout: number

Private ui

ui: GUI

Methods

handleGameEnd

  • handleGameEnd(winner: number, playerDisconnected?: boolean): void
  • Handle each individual game

    Parameters

    • winner: number

      Game's winner, used to update the state

    • Default value playerDisconnected: boolean = false

      Whether the game was stopped due to a player disconnecting. If true, the session will be finished

    Returns void

handlePlayerMove

  • handlePlayerMove(player: number): (Anonymous function)
  • Handles a specific player move - this returns a function configured for the specified player, it's intended to be used as the callback for the player socket.

    Parameters

    • player: number

      Player number (0-1)

    Returns (Anonymous function)

    Move handler with the player number embedded for logging

Private log

  • log(message: string, skipRender?: boolean): void
  • Log a message to the console or the GUI if it's enabled

    Parameters

    • message: string
    • Default value skipRender: boolean = false

      only for GUI mode, set to true to avoid re-rendering

    Returns void

Private parseMove

  • parseMove(data: string): Coords
  • Receive a move from a player and convert it to an object of board and move

    Parameters

    • data: string

      String received from the client

    Returns Coords

playGame

  • playGame(): void

Private sendAction

  • sendAction(action: string, player: number): void
  • Send an action to a player

    Parameters

    • action: string

      Action to send

    • player: number

      Player number (0-1)

    Returns void

Private sessionEnd

  • sessionEnd(): void

Private writeMove

  • writeMove(coords: Coords): string
  • Encode a move received from a player to be sent to the opponent

    Parameters

    • coords: Coords

    Returns string

Generated using TypeDoc