MeikyuuMounttype
The mounted flat maze, arrow or mixed board, its game/actions, view and cleanup handle.
Import it
import type { MeikyuuMount } from "@johnmorrisdotca/meikyuu/play";
Definition
type MeikyuuMount = {
readonly host: HTMLElement;
kind: () => MeikyuuKind;
puzzle: () => MeikyuuPuzzle;
mazeGame: () => MazeGame | null;
arrowGame: () => ArrowGame | null;
load: (puzzle: {
kind?: MeikyuuKind;
level?: number;
recipe?: MeikyuuMountOptions["recipe"];
ratio?: MeikyuuMountOptions["ratio"];
}) => boolean;
set: (changes: MazeLook & {
tap?: boolean;
sound?: boolean;
hints?: boolean;
banner?: boolean;
language?: MeikyuuLanguage;
ratio?: MeikyuuMountOptions["ratio"];
stones?: StoneOption;
}) => void;
undo: () => void;
restart: () => void;
hint: () => void;
fit: (mode?: FitMode) => void;
zoomIn: () => void;
zoomOut: () => void;
gutter: (px?: number) => number;
pan: (on?: boolean) => boolean;
edgePan: (on?: boolean) => boolean;
orientation: (setting?: MeikyuuOrientation) => {
setting: MeikyuuOrientation;
orientation: "portrait" | "landscape";
turned: boolean;
};
stoneMode: (on?: boolean) => boolean;
stones: () => readonly number[];
stonesLeft: () => number | null;
stone: (cell: number) => StoneVerdict;
clearStones: () => void;
run: () => string;
restore: (code: string) => boolean;
show: (board: "arrows" | "maze") => void;
destroy: () => void;
};
Members
| Name | Type | Description |
|---|---|---|
host | HTMLElement | |
kind | () => MeikyuuKind | |
puzzle | () => MeikyuuPuzzle | |
mazeGame | () => MazeGame | null | The maze game as it stands (a maze, or the labyrinth of a mixed puzzle), or null for arrows. |
arrowGame | () => ArrowGame | null | The arrow game as it stands, or null for a maze. |
load | (puzzle: { kind?: MeikyuuKind; level?: number; recipe?: MeikyuuMountOptions["recipe"]; ratio?: MeikyuuMountOptions["ratio"]; }) => boolean | Play another puzzle: a level or a recipe. Returns false when there is no such puzzle. |
set | (changes: MazeLook & { tap?: boolean; sound?: boolean; hints?: boolean; banner?: boolean; language?: MeikyuuLanguage; ratio?: MeikyuuMountOptions["ratio"]; stones?: StoneOption; }) => void | Change how it looks or is played: board, trail, tap, sound, hints, language, the shape of the box ( |
undo | () => void | |
restart | () => void | |
hint | () => void | |
fit | (mode?: FitMode) => void | Zoom and move back to the whole board (as |
zoomIn | () => void | Zoom in a step; if the gutters were widened, bring them in a step first. |
zoomOut | () => void | Zoom out a step; if the whole maze is already in the box, widen the gutters a step instead (to |
gutter | (px?: number) => number | The gutter now, in pixels, and set it (between the least and |
pan | (on?: boolean) => boolean | Whether every one-finger drag moves the view; with an argument, turn that on or off. |
edgePan | (on?: boolean) => boolean | Whether a line drawn to the edge moves the view along; with an argument, turn that on or off. |
orientation | (setting?: MeikyuuOrientation) => { setting: MeikyuuOrientation; orientation: "portrait" | "landscape"; turned: boolean; } | How the maze is shown: the setting, and what it came to ( |
stoneMode | (on?: boolean) => boolean | Whether the Stone mode is on (a tap lays a stone or takes one up, and nothing draws); with an argument, turn it on or off. Always off for a board with no stones. |
stones | () => readonly number[] | The cells with a stone on them, in the order they were laid. |
stonesLeft | () => number | null | How many stones can still be laid: null for no limit, 0 for a board with no stones. |
stone | (cell: number) => StoneVerdict | Lay a stone on a cell, or take the one there up: the verdict |
clearStones | () => void | Take every stone up. One Undo puts them back. |
run | () => string | The run so far as one short text, the line's steps and its stones ( |
restore | (code: string) => boolean | Carry on a run kept by |
show | (board: "arrows" | "maze") => void | For a mixed puzzle: look at the arrows or the labyrinth. |
destroy | () => void | Take the board down: its listeners, its timers and everything it put in the host. |
Examples
import type { MazeRecipe } from "@johnmorrisdotca/meikyuu";
import type { MeikyuuMount } from "@johnmorrisdotca/meikyuu/play";
import { mountMeikyuu } from "@johnmorrisdotca/meikyuu/play";
const recipe: MazeRecipe = {shape:"square",w:5,h:5,algorithm:"backtracker",mode:"to-goal",seed:42};
const host = document.createElement("div");
document.body.append(host);
const player: MeikyuuMount | null = mountMeikyuu(host,{kind:"maze",recipe});
console.log(player?.kind());
player?.destroy();