Have ideas to improve npm?Join in the discussion! »

    @ttn/card-game

    0.0.3 • Public • Published

    card-game

    A small JavaScript abstraction for creating card based games, such as Cards Against Humanity, What Do You Meme?, etc.

    Installation

    npm install @ttn/card-game --save
    

    API

    import createCardGame, {
      // events
      DECK_CHANGE,
      PLAYER_ADDED,
      PLAYER_REMOVED,
      PLAYER_SCORED,
      PLAYER_SKIPPED,
      STATE_CHANGED,
     
      // game states
      WAITING_FOR_PLAYERS,
      COUNTDOWN_TO_GAME,
      GAME_PLAYING,
      CZAR_PICKING,
      CZAR_PICKED,
    } from '@ttn/card-game';
     
    // all arguments to the constructor are optional
    const game = createCardGame({
      // minimum # of players to require before starting a game
      minPlayers: Number | Infinity,
      // maximum # of players
      maxPlayers: Number | Infinity,
      // object of numbers for state change countdowns
      countdowns: {
         // # of seconds to wait before a game starts
        countdownToGame: Number,
        // # of seconds that players can submit a card in
        gameDuration: Number,
        // # of seconds to wait for a czar to pick a winner before skipping
        czarPicking: Number,
        // # of seconds to wait before creating a new game
        winnerPicked: Number,
      },
      // czarCards should be an array of any types
      czarCards: [Mixed],
      // playerCards should be an array of any types, the length of which should be at least minPlayers * 10
      playerCards: [Mixed],
    });
     
    /*
     * Events are dispatched as the game's state changes, which you can observe by calling
     * subscribe().
     *
     * The `receiver` function provided to `subscribe` should accept one argument of an object
     * with `type` and `payload` properties.
     *
     * `type` will be one of:
     *    DECK_CHANGE | PLAYER_ADDED | PLAYER_REMOVED | PLAYER_SCORED | PLAYER_SKIPPED | STATE_CHANGED
     * `payload` will be a mixed type, depending on the event
     */
    const unsubscribe = game.subscribe(receiver: Function) : Function
     
    game.getState() : Object
    game.addPlayer(playerId: String) : Promise
    game.removePlayer(playerId: String) : Promise
    game.submitCards(playerId: String, [cardId: String]) : Promise
    game.pickWinner(cardId: String) : Promise

    Install

    npm i @ttn/card-game

    DownloadsWeekly Downloads

    12

    Version

    0.0.3

    License

    MIT

    Last publish

    Collaborators

    • avatar