Skip to the content

Toranpuトランプ

Use a deck, play eleven games with computers, solve a solitaire, or display cards in your own design.

Toranpu is Japanese for playing cards. About the name

Contents

Reference · React components

useCardGamefunction

A card game held in React state. See CardGameState for what it hands back; computerDelay is the milliseconds a computer waits before each move.

Import it

import { useCardGame } from "@johnmorrisdotca/toranpu/react";

Definition

function useCardGame<K extends CardGameKind>(kind: K, options: NewGameOptions, computerDelay?: number): CardGameState<K>

Parameters

NameTypeDescription
kindK

The named card game or sound kind.

optionsNewGameOptions

Options for this call; omitted fields retain their documented defaults.

computerDelay (optional)number

Milliseconds between computer turns in the React view.

Returns

CardGameState<K>

A card game held in React state. See CardGameState for what it hands back; computerDelay is the milliseconds a computer waits before each move.

Examples

import { useCardGame } from "@johnmorrisdotca/toranpu/react";

import { createElement } from "react";
function Table() {
  const table = useCardGame("hearts", { players: ["You", "Aki", "Ben", "Cy"], seed: 42 });
  return createElement("p", null, `${table.moves.length} legal moves`);
}
console.log(createElement(Table));

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/toranpu 2.15.0.