sourcegames/trek/play.xtl
1⍝!/usr/bin/env xetal
2⍝# Star Trek at the terminal, as the COR24 BASIC game plays it: destroy
3⍝# every Klingon before the stardate runs out. Commands by number (9 is
4⍝# help); warp, impulse, phasers, torpedoes and shields then ask for a
5⍝# course (1 north, clockwise to 8) and a number. The rules are those of
6⍝# StarTrek.xtl.
7ᵗ⁼u̲se< "StarTrek"
8ᵖ⁼u̲se< "Play"
9said ← p̲rint! ""
10said ← p̲rint! "*** STAR TREK ***"
11said ← p̲rint! "DEFEND THE FEDERATION."
12said ← p̲rint! ""
13
14⍝# A command's arguments, asked for as the BASIC asks: a factor or a
15⍝# number of sectors only after a good course; nothing to fire with
16⍝# when there is nothing to fire at, or no torpedoes.
17ᵘa̲rgs ← { s c →
18 c = 3 ? ᵘc̲ourseAnd "WARP FACTOR 1-8 ?"
19 c = 4 ? ᵘc̲ourseAnd "SECTORS 1-8 ?"
20 (c = 5) ∧ 0 < ᵗh̲ere s ? ᵖn̲umber "ENERGY TO FIRE ?"
21 (c = 6) ∧ 0 < ᵗt̲orps s ? ᵖn̲umber "TORPEDO COURSE 1-8 ?"
22 c = 7 ? ᵖn̲umber "ENERGY TO SHIELDS (NEG=DRAIN) ?"
23 0
24}
25ᵘc̲ourseAnd ← { prompt →
26 c ← ᵖn̲umber "COURSE 1-8 ?"
27 (c < 1) ∨ c > 8 ? c c̲at 0
28 c c̲at ᵖn̲umber prompt
29}
30
31⍝# A turn: the menu, a command, its result, until the game is over.
32ᵘt̲urn ← { s →
33 0 < ᵗs̲tatus s ? p̲rint! ᵗe̲nd s
34 said ← p̲rint! ""
35 said ← p̲rint! "1=SRS 2=LRS 3=WAR 4=IMP 5=PHA 6=TOR 7=SHE 8=STA 9=HEL 0=QUI"
36 c ← ᵖn̲umber "COMMAND ?"
37 ᵘt̲urn s ᵗc̲ommand c c̲at s ᵘa̲rgs c
38}
39s ← ᵗn̲ew 0
40said ← p̲rint! @ f̲ormat< "STARDATE {t:d_ate s} - YOU HAVE 30 DAYS TO DESTROY {t:k_lingons s} KLINGONS."
41done ← ᵘt̲urn s
f̲ormat< expands to
("STARDATE " c̲at (f̲ormat (ᵗd̲ate s)) c̲at " - YOU HAVE 30 DAYS TO DESTROY " c̲at (f̲ormat (ᵗk̲lingons s)) c̲at " KLINGONS.")