programgames/dungeon/play.xtl
The dungeon: find the way out (>). Arrow keys or WASD move you; walk into a monster to fight it; walk over potions (!) and gold ($) to pick them up; r starts again. Each game is a new dungeon (a map and places drawn from its seed); a game won or lost ends the program (on the page, Play or any key then starts a new one). On the page the dungeon 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 Crawl.xtl's, built on lib/Ecs.
ᵘs̲tep : (Num a, Truthy a) => Char -> a
A key's step: a row and a column (0 0 for any other key, a turn waited).
ᵘs̲tep ← { name → k ← ("UP" "DOWN" "LEFT" "RIGHT" "w" "s" "a" "d") i̲ndexOf e̲nclose name ((1 + (k − 1) m̲od 4) s̲elect 9 2 r̲eshape -1 0 1 0 0 -1 0 1 0 0 0 0 0 0 0 0 0 0) × k ≤ 8 }
Used in: ᵘl̲oop
ᵘl̲oop : (Float, Int, Int, Char, Int) -> Char
Show the dungeon, read the next event, act on a key, again.
ᵘl̲oop ← { s → (W, g, n, m, lv) ← s _ ← p̲rint! m _ ← ⎕S̲HOW ᶜʳd̲raw s 0 < ᶜʳs̲tatus s ? ᵘe̲nd 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 ? ᵘl̲oop ᶜʳn̲ew 0 ᵘl̲oop s ᶜʳt̲urn f̲loat ᵘs̲tep name }
Used in: ᵘl̲oop, games/dungeon/play.xtl:37
ᵘe̲nd : (Float, Int, Int, Char, Int) -> Char
How the game ended (the program ends with it).
ᵘe̲nd ← { s → y ← ᶜʳy̲ou s 1 = ᶜʳs̲tatus s ? @ f̲ormat< "You found the way out with {2 s_elect y} gold in {3 s_elect y} turns!" "You were beaten." }
f̲ormat< expands to
("You found the way out with " c̲at (f̲ormat (2 s̲elect y)) c̲at " gold in " c̲at (f̲ormat (3 s̲elect y)) c̲at " turns!")
Used in: ᵘl̲oop