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;
};
メンバー
| 名前 | 型 | 説明 |
|---|---|---|
game | GameOf<K> | null | The game now, or null when the table was one the game is not offered for. |
toPlay | number | null | The seat to move, or null once the game is over. |
computerToPlay | boolean | Whether the seat to move is a computer's. |
moves | readonly MoveOf<K>[] | The moves the seat to move may make: none while a computer is thinking or once the game is over. |
over | boolean | |
winners | readonly 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);この日本語は、まだ日本語を母語とする方の確認を受けていません。訂正を歓迎します。