sourcegames/trek-adventure/play.xtl

1⍝!/usr/bin/env xetal 2⍝# Trek adventure at the terminal, as the COR24 BASIC game plays it: 3⍝# "Star Trek: Decaying Orbit". Pick commands by number (8 for help); 4⍝# GO, TAKE and USE then ask for a room or an item number. Every command 5⍝# takes a turn; fix the engines before the 30 turns run out. The rules 6⍝# and all the text are in TrekAdventure.xtl. 7ᵗ⁼u̲se< "TrekAdventure" 8ᵖ⁼u̲se< "Play" 9 10⍝# The items here as the TAKE menu lists them, " 3=TOOLKIT". 11ᵘl̲ist ← { v → 12 0 = t̲ally v ? 0 13 shown ← p̲rint! @ f̲ormat< " {f_irst v}={d_isclose (f_irst v) s_elect t:i_tems @}"
f̲ormat< expands to
("  " c̲at (f̲ormat (f̲irst v)) c̲at "=" c̲at (f̲ormat (d̲isclose (f̲irst v) s̲elect ᵗi̲tems @)))
14 1 + ᵘl̲ist 1 d̲rop v 15} 16 17⍝# The argument a command asks for: a room for GO, an item for TAKE (0 18⍝# when there is nothing to take) and USE, else none. 19ᵘa̲rg ← { s c → 20 c = 3 ? ᵖn̲umber "GO TO ROOM# ?" 21 c = 4 ? ᵘt̲akeWhat s 22 c = 5 ? ᵘu̲seWhat s 23 0 24} 25ᵘt̲akeWhat ← { s → 26 said ← p̲rint! "TAKE WHAT?" 27 here ← ᵗp̲resent s 28 0 = t̲ally here ? 0 29 listed ← ᵘl̲ist here 30 ᵖn̲umber "ITEM# ?" 31} 32ᵘu̲seWhat ← { s → 33 said ← p̲rint! "USE WHAT?" 34 said ← p̲rint! "1=TOOLKIT 2=COUPLER 3=COMPUTER" 35 ᵖn̲umber "ITEM# ?" 36} 37 38⍝# A turn: the room, the menu, a command, what it says, the clock. 39ᵘt̲urn ← { s → 40 0 < ᵗs̲tatus s ? s ᵗs̲ay 200 + ᵗs̲tatus s 41 said ← p̲rint! "----------------------------------------" 42 said ← p̲rint! @ f̲ormat< "TURNS LEFT {t:t_urns s}"
f̲ormat< expands to
("TURNS LEFT " c̲at (f̲ormat (ᵗt̲urns s)))
43 said ← p̲rint! "" 44 said ← s ᵗs̲ay ᵗr̲oom s 45 said ← p̲rint! "" 46 said ← p̲rint! "1=LOOK 2=INV 3=GO 4=TAKE" 47 said ← p̲rint! "5=USE 6=THROW 7=FIRE 8=HELP 0=QUIT" 48 c ← ᵖn̲umber "COMMAND ?" 49 c = 0 ? s ᵗs̲ay 204 50 next ← s ᵗm̲ove c c̲at s ᵘa̲rg c 51 said ← next ᵗs̲ay ᵗs̲aid next 52 later ← ᵗc̲lock next 53 said ← later ᵗs̲ay ᵗa̲larms later 54 ᵘt̲urn later 55} 56s ← ᵗn̲ew 0 57said ← s ᵗs̲ay 300 58done ← ᵘt̲urn s