Skip to the content

Karakuriからくり

Play eight native puzzles, run bounded searches, step deterministic physics and mount a canvas player controlled by pointer or keyboard.

Karakuri is the Japanese word からくり for a mechanism or ingenious device. About the name

Contents

Reference · Controllers and canvas player

Controllertype

One level of one game, played.

Import it

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

Also exported from: @johnmorrisdotca/karakuri

Definition

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;
}

Members

NameTypeDescription
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.

Examples

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]
}

What it prints (run when this page was built)

View sourceEdit on GitHubMade from the source of @johnmorrisdotca/karakuri 0.2.1.