本文へ移動

Toranpuトランプ

デッキを使い、11種類のゲームでコンピューターと対戦し、ソリティアを解いたり、独自の絵柄でカードを表示したりできます。

「トランプ」は、日本語で playing cards を指す言葉です。 名前について(英語)

目次

リファレンス · Reactコンポーネント

CardGameState型

リファレンスの説明と例は英語です。見出しと目次は日本語です。

A card game in React state: the game, the moves the person to play may make, and play to make one. Computers take their turns by themselves, one move every computerDelay milliseconds, so a person can follow them. Drawing the table is yours: this holds the game and nothing else.

const table = useCardGame("crazyEights", { players: ["You", "Ann"], computers: [false, true] });
table.moves.map((move) => <button onClick={() => table.play(move)}>…</button>);

インポート

import type { CardGameState } from "@johnmorrisdotca/toranpu/react";

定義

type CardGameState<K extends CardGameKind> = {
    game: GameOf<K> | null;
    toPlay: number | null;
    computerToPlay: boolean;
    moves: readonly MoveOf<K>[];
    over: boolean;
    winners: readonly number[];
    play: (move: MoveOf<K>) => boolean;
    restart: (options?: Partial<NewGameOptions>) => void;
};

メンバー

名前型説明
gameGameOf<K> | null

The game now, or null when the table was one the game is not offered for.

toPlaynumber | null

The seat to move, or null once the game is over.

computerToPlayboolean

Whether the seat to move is a computer's.

movesreadonly MoveOf<K>[]

The moves the seat to move may make: none while a computer is thinking or once the game is over.

overboolean
winnersreadonly number[]

Every seat that won, once the game is over.

play(move: MoveOf<K>) => boolean

Make a move for the person to play. Returns false for a move the rules refuse.

restart(options?: Partial<NewGameOptions>) => void

Deal a new game with the same table and a new seed, or the options given.

例

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

function Table() {
  const value: CardGameState<"hearts"> = useCardGame("hearts", { players: ["Aki", "Ben", "Cy", "Dev"], seed: 42 });
  console.log(value.moves.length);
  return null;
}
console.log(Table.name);

ソースを見るGitHub で編集@johnmorrisdotca/toranpu 2.15.0 のソースから作成しました。

この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。