sourcegames/maze/play.xtl

1⍝!/usr/bin/env xetal 2⍝│ The maze: find the way out (>). Up (or w) steps ahead, down (or s) 3⍝│ steps back, left and right (or a and d) turn a quarter; m shows or 4⍝│ hides a mini map of what you have seen; r starts a new maze. Each game 5⍝│ is a new maze, carved from its seed. Finding the way out ends the 6⍝│ program (on the page, Play or any key then starts a new one). On the 7⍝│ page the maze is in a dialog and your keys come to the program as 8⍝│ events; at the command line, lines such as "key UP" on standard input. 9⍝│ The rules are Walls.xtl's. 10"mz:" u̲se< "Walls" 11 12⍝│ Show the view, then wait for the next key. 13ᵘs̲how ← { s → 14 _ ← ⎕S̲HOW ᵐᶻd̲raw s 15 0 < ᵐᶻs̲tatus s ? ᵘe̲nd s 16 ᵘl̲oop s 17} 18⍝│ The next event: a key acts; the end of the events ends the game. 19ᵘl̲oop ← { s → 20 e ← ⎕E̲VENT @ 21 "end" m̲atch ⎕E̲KIND e ? "THE END" 22 n̲ot "key" m̲atch ⎕E̲KIND e ? ᵘl̲oop s 23 name ← f̲ormat ⎕E̲KEY e 24 "r" m̲atch name ? ᵘs̲how ᵐᶻn̲ew 0 25 ᵘs̲how s ᵐᶻk̲ey name 26} 27⍝│ The way out found (the program ends with it). 28ᵘ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!"
29ᵘs̲how ᵐᶻn̲ew 0