programgames/maze/play.xtl

The maze: find the way out (>). Up (or w) steps ahead, down (or s) steps back, left and right (or a and d) turn a quarter; m shows or hides a mini map of what you have seen; r starts a new maze. Each game is a new maze, carved from its seed. Finding the way out ends the program (on the page, Play or any key then starts a new one). On the page the maze is in a dialog and your keys come to the program as events; at the command line, lines such as "key UP" on standard input. The rules are Walls.xtl's.

source · imports mz: games/maze/Walls.xtl

ᵘs̲how : (Truthy a, Num b) => (Int, Int, Int, Int, a, b, Int) -> Char

function · line 13

Show the view, then wait for the next key.

ᵘs̲how ← { s →
  _ ← ⎕S̲HOW ᵐᶻd̲raw s
  0 < ᵐᶻs̲tatus s ? ᵘe̲nd s
  ᵘl̲oop s
}

ᵘl̲oop : (Truthy a, Num b) => (Int, Int, Int, Int, a, b, Int) -> Char

function · line 19

The next event: a key acts; the end of the events ends the game.

ᵘl̲oop ← { s →
  e ← ⎕E̲VENT @
  "end" m̲atch ⎕E̲KIND e ? "THE END"
  n̲ot "key" m̲atch ⎕E̲KIND e ? ᵘl̲oop s
  name ← f̲ormat ⎕E̲KEY e
  "r" m̲atch name ? ᵘs̲how ᵐᶻn̲ew 0
  ᵘs̲how s ᵐᶻk̲ey name
}

ᵘe̲nd : (Truthy a, Num b) => (Int, Int, Int, Int, a, b, Int) -> Char

function · line 28

The way out found (the program ends with it).

ᵘe̲nd ← { s → @ f̲ormat< "You found the way out in {f_irst mz:y_ou s} steps!" }
f̲ormat< expands to
"You found the way out in " c̲at (f̲ormat (f̲irst ᵐᶻy̲ou s)) c̲at " steps!"
Used in: ᵘs̲how