Reference · Playable number grid
KazuMounttype
The native mounted number grid, its current game/detail, controls and cleanup methods.
Import it
import type { KazuMount } from "@johnmorrisdotca/kazu/play";
Definition
type KazuMount = {
readonly host: HTMLElement;
game: () => KazuGame;
detail: () => KazuEventDetail;
load: (puzzle: Pick<KazuMountOptions, "kind" | "size" | "givens" | "solution" | "level" | "seed" | "run" | "notes" | "elapsed">) => boolean;
set: (changes: KazuMountSettings) => void;
select: (cell: number | null) => void;
enter: (value: number) => void;
pencil: (on?: boolean) => void;
undo: () => void;
hint: () => void;
check: () => void;
restart: () => void;
destroy: () => void;
};
Members
| Name | Type | Description |
|---|---|---|
host | HTMLElement | |
game | () => KazuGame | The game as it stands. |
detail | () => KazuEventDetail | What the events would tell now. |
load | (puzzle: Pick<KazuMountOptions, "kind" | "size" | "givens" | "solution" | "level" | "seed" | "run" | "notes" | "elapsed">) => boolean | Play another puzzle (or the same one again, fresh). |
set | (changes: KazuMountSettings) => void | Change how it plays: hints, check, conflicts, peers, tidy, tapToStep, language, clock, controls. |
select | (cell: number | null) => void | Choose a cell (or none, with null). |
enter | (value: number) => void | Write a number into the chosen cell, or a pencil mark if Pencil is on; 0 empties the cell. |
pencil | (on?: boolean) => void | Turn Pencil on or off. |
undo | () => void | |
hint | () => void | |
check | () => void | |
restart | () => void | Start again: every entry gone and the clock at nothing. |
destroy | () => void | Take the board down: its listeners, its timers and everything it put in the host. |
Examples
import type { KazuPuzzle } from "@johnmorrisdotca/kazu";
import { decodeCells } from "@johnmorrisdotca/kazu";
import type { KazuMount } from "@johnmorrisdotca/kazu/play";
import { mountKazu } from "@johnmorrisdotca/kazu/play";
const puzzle: KazuPuzzle = {"kind":"number-place","size":4,"level":"easy","seed":42,"givens":"14..2..1412.3..4","solution":"1432234141233214"};
const kind = puzzle.kind;
const size = puzzle.size;
const givens = puzzle.givens;
const answer = puzzle.solution;
const solution = decodeCells(answer,size)!;
const host = document.createElement("div");
document.body.append(host);
const board: KazuMount | null = mountKazu(host,{kind,size,givens,solution:answer});
console.log(board?.detail().progress);
board?.destroy();