programgames/robot-chase/play.xtl

source · imports r: games/robot-chase/RobotChase.xtl; p: lib/Play.xtl

said : Char

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

said : Char

value · line 10
said ← p̲rint! "*** ROBOT CHASE ***"

said : Char

value · line 11
said ← p̲rint! "EVADE THE ROBOTS - MAKE THEM COLLIDE."

ᵘa̲sk : Any a => a -> Int

function · line 15

A command: the first number on the line; one that is not a command is asked for again.

ᵘa̲sk ← { s →
  said ← p̲rint! ""
  said ← p̲rint! "1-9=MOVE(5=WAIT) 0=TELE 10=LRS 99=QUIT"
  c ← ᵖn̲umber "COMMAND ?"
  (c m̲ember? 0 1 2 3 4 5 6 7 8 9 10 99) ? c◆ ᵘa̲sk s
}

ᵘs̲how : Int -> Char

function · line 23

The board and its header, as the BASIC prints them each turn.

ᵘs̲how ← { s →
  said ← p̲rint! ""
  pic ← ⎕S̲HOW ʳp̲icture s
  said ← p̲rint! @ f̲ormat< "TURN {r:t_urn s}   ROBOTS {'+ r_/ r:a_live s}   TELE {r:t_ele s}"
  ʳv̲iew s
}
f̲ormat< expands to
("TURN " c̲at (f̲ormat (ʳt̲urn s)) c̲at "   ROBOTS " c̲at (f̲ormat ('+ r̲/ ʳa̲live s)) c̲at "   TELE " c̲at (f̲ormat (ʳt̲ele s)))

ᵘt̲urn : Int -> Char

function · line 31

A turn: show, read, move (or scan), say what happened, until the end.

ᵘt̲urn ← { s →
  shown ← p̲rint! ᵘs̲how s
  c ← ᵘa̲sk s
  c = 10 ? ᵘt̲urn ᵘs̲can s
  t ← s ʳm̲ove c
  0 = ʳe̲vent t ? ᵘa̲fter t◆ ᵘa̲fter ᵘs̲ay t
}

ᵘs̲ay : Int -> Int

function · line 38
ᵘs̲ay ← { t →
  told ← p̲rint! ʳm̲essage t
  t
}
Used in: ᵘt̲urn

ᵘa̲fter : Int -> Char

function · line 42
ᵘa̲fter ← { t → 0 < ʳs̲tatus t ? ᵘe̲nd t◆ ᵘt̲urn t }
Used in: ᵘt̲urn

ᵘs̲can : Int -> Int

function · line 43
ᵘs̲can ← { s →
  said ← p̲rint! ""
  said ← p̲rint! "LRS: ROBOTS, WRECKS, YOU IN EACH 4X4 REGION"
  shown ← p̲rint! ʳl̲rs s
  s
}
Used in: ᵘt̲urn

ᵘe̲nd : Int -> Char

function · line 50

The end: (unless you resigned) the board once more, then the verdict.

ᵘe̲nd ← { s →
  9 = ʳe̲vent s ? "GAME OVER"
  shown ← p̲rint! ᵘs̲how s
  said ← p̲rint! ""
  1 = ʳs̲tatus s ? @ f̲ormat< "*** YOU WIN IN {r:t_urn s} TURNS! ***"◆ "*** YOU WERE CAUGHT. ***"
}
f̲ormat< expands to
("*** YOU WIN IN " c̲at (f̲ormat (ʳt̲urn s)) c̲at " TURNS! ***")
Used in: ᵘa̲fter