Skip to main content

Game

The game namespace is the socket.io instance that handles all game events.

These are the Server-to-Client events (see in the code):

interface GameServerToClientEvents {
/** The main thread where the game server sends live updates, (to all clients, once another client made a move i.e) */
gameUpdate: (biasedGameState: BiasedGameState) => void;
/**
* The game server can at any time request an action from a player (the player that needs to take action, will simply be the recipient of the event)
* The player will need to "ack" the event with
*/
gameServerPrompt: <TGSP extends GameServerPrompt>(
prompt: TGSP,
/** The clients "response" to the prompt will be in the ack fn. "false" as a response means the client reported that there was an error answering */
ack: (promptResponse: GameServerPromptResponses[TGSP['id']] | false) => void
) => void;
}

These are the Client-to-Server events (see in the code):

interface GameClientToServerEvents {
/** A player joining a game, to join the socket.io specific game room */
joinGame: (
gameId: string,
/**
* @param currentGameState is false, if creation failed, otherwise we get the latest gameState
*/
ack: (currentGameState: false | BiasedGameState) => void
) => void;

/** All moves by a player are handeled by this event. The server will queue the requested task to the game event queue */
makeMove: (gameTask: GameTask, ack: (success: boolean) => void) => void;
}

As you can see there aren't many events. The client for example only has one event makeMove besides joining a game.

This is because we don't need a different event for every type of move. A move event contains the information which type of move it is in form of a game task.


<code references>