本文へ移動

Karakuriからくり

8つの標準のパズルで遊び、探索や再現できる物理を使い、ポインターやキーボードで操作する盤を表示できます。

「からくり」は、仕組みや工夫した装置を表す言葉です。 名前について(英語)

目次

リファレンス · 操作とキャンバスの表示

Controller型

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

One level of one game, played.

インポート

import type { Controller } from "@johnmorrisdotca/karakuri/play";

ほかのエクスポート元: @johnmorrisdotca/karakuri

定義

interface Controller {
    readonly width: number;
    readonly height: number;
    readonly gesture: "drag" | "tap";
    readonly status: Status;
    readonly result: Say | null;
    readonly info: Say;
    readonly animating: boolean;
    pointerDown(p: Point, id: number): void;
    pointerMove(p: Point, id: number): void;
    pointerUp(p: Point, id: number): void;
    pointerCancel(id: number): void;
    tick(): void;
    draw(g: CanvasRenderingContext2D, theme: Theme): void;
    restart(): void;
    snapshot(): unknown;
}

メンバー

名前型説明
widthnumber

The size of the play area, in the game's units. The player scales it to the box it is given.

heightnumber
gesture"drag" | "tap"

drag games read a finger's whole path, so the player stops the page scrolling under it; tap games leave the page its gestures.

statusStatus
resultSay | null

Why a level was won or lost, in words, once it has been.

infoSay

The line shown above the board.

animatingboolean

Whether time is passing in the game (physics running, an animation playing), so that the player keeps stepping and drawing.

pointerDown(p: Point, id: number): void
pointerMove(p: Point, id: number): void
pointerUp(p: Point, id: number): void
pointerCancel(id: number): void
tick(): void

Advances the game by one fixed step (a sixtieth of a second).

draw(g: CanvasRenderingContext2D, theme: Theme): void
restart(): void

Starts the same level again.

snapshot(): unknown

Plain data for a test or a page to read what is going on.

例

import { createController } from "@johnmorrisdotca/karakuri/play";
import type { Controller } from "@johnmorrisdotca/karakuri/play";

const controller=createController("tube-sort",1);
const value: Controller = controller;
console.log(value);
{
  width: 360,
  height: 420,
  gesture: 'tap',
  status: [Getter],
  result: [Getter],
  info: [Getter],
  animating: [Getter],
  pointerDown: [Function: pointerDown],
  pointerMove: [Function: pointerMove],
  pointerUp: [Function: pointerUp],
  pointerCancel: [Function: pointerCancel],
  tick: [Function: tick],
  draw: [Function: draw],
  restart: [Function: restart],
  snapshot: [Function: snapshot]
}

出力(このページを作ったときに実行した結果)

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

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