programgames/trek/play.xtl

source · imports t: games/trek/StarTrek.xtl; p: lib/Play.xtl

said : Char

value · line 9
said ← p̲rint! ""

said : Char

value · line 10
said ← p̲rint! "*** STAR TREK ***"

said : Char

value · line 11
said ← p̲rint! "DEFEND THE FEDERATION."

said : Char

value · line 12
said ← p̲rint! ""

ᵘa̲rgs : (Num a, Num b) => a -> b -> Int

function · line 17

A command's arguments, asked for as the BASIC asks: a factor or a number of sectors only after a good course; nothing to fire with when there is nothing to fire at, or no torpedoes.

ᵘa̲rgs ← { s c →
  c = 3 ? ᵘc̲ourseAnd "WARP FACTOR 1-8 ?"
  c = 4 ? ᵘc̲ourseAnd "SECTORS 1-8 ?"
  (c = 5) ∧ 0 < ᵗh̲ere s ? ᵖn̲umber "ENERGY TO FIRE ?"
  (c = 6) ∧ 0 < ᵗt̲orps s ? ᵖn̲umber "TORPEDO COURSE 1-8 ?"
  c = 7 ? ᵖn̲umber "ENERGY TO SHIELDS (NEG=DRAIN) ?"
  0
}
Used in: ᵘt̲urn

ᵘc̲ourseAnd : Char -> Int

function · line 25
ᵘc̲ourseAnd ← { prompt →
  c ← ᵖn̲umber "COURSE 1-8 ?"
  (c < 1) ∨ c > 8 ? c c̲at 0
  c c̲at ᵖn̲umber prompt
}
Used in: ᵘa̲rgs

ᵘt̲urn : Int -> Char

function · line 32

A turn: the menu, a command, its result, until the game is over.

ᵘt̲urn ← { s →
  0 < ᵗs̲tatus s ? p̲rint! ᵗe̲nd s
  said ← p̲rint! ""
  said ← p̲rint! "1=SRS 2=LRS 3=WAR 4=IMP 5=PHA 6=TOR 7=SHE 8=STA 9=HEL 0=QUI"
  c ← ᵖn̲umber "COMMAND ?"
  ᵘt̲urn s ᵗc̲ommand c c̲at s ᵘa̲rgs c
}
Used in: ᵘt̲urn, done

s : Int

value · line 39
s ← ᵗn̲ew 0
Used in: said, done

said : Char

value · line 40
said ← p̲rint! @ f̲ormat< "STARDATE {t:d_ate s} - YOU HAVE 30 DAYS TO DESTROY {t:k_lingons s} KLINGONS."
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.")

done : Char

value · line 41
done ← ᵘt̲urn s