Documentation

Game logic

v1 · Deprecated

Framework v1 is deprecated for new games. Existing games remain playable and editable.

Scores and game end

getPlayerScores (required)

type GetPlayerScoresFn<MetaData = Record<string, unknown>> =
  (gameState: GameState<MetaData>) => Scores;

type Scores = Record<string /* playerId */, {
  publicPoints: number[];                   // one entry per scoreLabel
  privatePoints: number[];                  // hidden from non-owner
}>;

export const getPlayerScores: GetPlayerScoresFn = (state) => ({
  [state.players()[0].playerId]: { publicPoints: [3], privatePoints: [] },
  [state.players()[1].playerId]: { publicPoints: [1], privatePoints: [] },
});

Called after applyActions. The map key is playerId.toString(). Read-only.

publicPoints[i] corresponds to gameConfig().scoreLabels[i]. privatePoints are nulled on the wire for any viewer who isn't that player.

isGameOver (required)

type IsGameOverFn<MetaData = Record<string, unknown>> =
  (gameState: GameState<MetaData>, scores: Scores) => boolean;

export const isGameOver: IsGameOverFn = (state, scores) =>
  Object.values(scores).some((s) => s.publicPoints[0] >= 3);

Called after getPlayerScores. Return true to end the game. Read-only.

Need a hand with this?

Join our Discord