Steer a blinking man through a random maze to the treasure ($) before the clock runs out. A new maze of walls, corridors and bonus dots is drawn each game, and the treasure and the man are placed at random. The arrow keys 5–8 move the man, who keeps going in the last direction pressed until he meets a wall. Each blink costs a unit of time, and eating a dot gains one back. Pressing S fires a blaster that clears the nine squares around the man, at a cost of nine units, which helps when he or the treasure starts out walled in. Blasting the treasure loses the game. Reaching it in time flashes "YOU WON" and shows how many blinks were left.
A type-in by Thomas B. Woods from SYNC, March/April 1983. The tape holds two recordings. Both have REMs reading "ZX MAZE", "SYNC MARCH/APRIL 1983" and "USE ARROWS TO MOVE AND *S*= BLAST". ZXMAZE1 adds "COPIED BY G. HARR", the name of the person who typed it in. This copy starts with 100 blinks instead of the magazine's 50. It also restarts with GOTO 8 instead of RUN, and it replaces the article's copyright and author REMs with the lines above.
Program Analysis
Program Structure
- Lines 7–90:
GOTO 2050clears the screen and switches toFAST. The program then sets the clockCand fills a numeric arrayA(21,31)that maps the screen: 0 for a wall, 1 for a corridor, -1 for a bonus dot. - Lines 100–155: place the treasure, which is marked as 10 in the map, then the man.
- Lines 157–250: the main loop. It blinks the man by printing
Oand then*, checks for a win or time out, adjusts the clock from the map value under the man, and readsINKEY$. - Lines 500–820: one movement routine for each arrow, reached with
GOTO 100*VAL L$. Each one checks the map square ahead and moves only when it is not 0. - Lines 1000–1060: the blast animation, and the clearing of the surrounding map squares.
- Lines 2000–2060: the flashing win or lose messages and the replay prompt.
Notable Techniques
- Walls are found from the array that maps the screen, not by reading the display. This is the point the original article set out to teach.
- Because
L$keeps the last key pressed, the man goes on moving without the key being held down. - The direction routines sit at 500, 600, 700 and 800, so a single computed
GOTO 100*VAL L$chooses between them.
Potential Issues
- Lines 2010 and 2025 test
A(Q,N)to see whether the treasure was blasted. After a blast,QandNare left one past the end of the blast loops. If the man blasted on the bottom row or the right-hand column and later wins, they can point outside the array and cause report 3. - The blast clears only the map squares. The maze walls stay on screen, so a cleared wall still looks solid.
- The man can be placed on the treasure, or sealed in, at the start. The blaster is the only way out.
Source Code
1 REM ZX MAZE
2 REM SYNC MARCH/APRIL 1983
3 REM COPIED BY G. HARR
4 REM USE ARROWS TO MOVE AND *S*= BLAST
7 GOTO 2050
8 LET C=100
10 DIM A(21,31)
20 FOR N=1 TO 30
30 FOR Q=1 TO 20
40 IF INT (RND*10)>5 THEN GOTO 70
42 LET A(Q,N)=1
45 IF INT (RND*10)>5 THEN GOTO 61
50 NEXT Q
55 NEXT N
60 GOTO 100
61 PRINT AT Q,N;"."
62 LET A(Q,N)=-1
63 GOTO 50
70 PRINT AT Q,N;"█"
90 GOTO 50
100 LET X=INT (RND*28)+2
110 LET Y=INT (RND*18)+2
120 PRINT AT Y,X;"$"
130 LET A(Y,X)=10
140 LET X=INT (RND*28)+2
150 LET Y=INT (RND*18)+2
155 LET L$="X"
157 SLOW
160 PRINT AT Y,X;"O";AT Y,X;"*"
162 IF C<=0 OR A(Y,X)=10 THEN GOTO 2000
163 LET C=C-A(Y,X)
164 IF A(Y,X)=-1 THEN LET A(Y,X)=1
165 IF INKEY$ <>"" THEN LET L$=INKEY$
170 IF L$>="5" AND L$<="8" THEN GOTO 100*VAL L$
180 PRINT AT Y,X;" "
190 IF INKEY$ ="S" THEN GOTO 1000
250 GOTO 160
500 PRINT AT Y,X;" "
510 IF X>2 THEN IF A(Y,X-1)<>0 THEN LET X=X-(X>2)
520 GOTO 160
600 PRINT AT Y,X;" "
610 IF Y<20 THEN IF A(Y+1,X)<>0 THEN LET Y=Y+(Y<20)
620 GOTO 160
700 PRINT AT Y,X;" "
710 IF Y>2 THEN IF A(Y-1,X)<>0 THEN LET Y=Y-(Y>2)
720 GOTO 160
800 PRINT AT Y,X;" "
810 IF X<30 THEN IF A(Y,X+1)<>0 THEN LET X=X+(X<30)
820 GOTO 160
1000 PRINT AT Y-1,X-1;" * ";AT Y,X-1;"*[O]*";AT Y+1,X-1;" * ";AT Y-1,X-1;" ";AT Y,X-1;" O ";AT Y+1,X-1;" "
1010 FOR Q=Y-1 TO Y+1
1015 PRINT AT Y,X;"*"
1020 FOR N=X-1 TO X+1
1025 IF A(Q,N)=10 THEN GOTO 2000
1030 LET A(Q,N)=1
1035 PRINT AT Y,X;"O"
1037 LET C=C-1
1040 NEXT N
1050 NEXT Q
1060 GOTO 160
2000 FOR B=1 TO 7
2005 IF A(Y,X)=10 THEN PRINT AT 10,0;"[~~][,,][~~][,,][~~][,,][~~][,,][~~][,,]* YOU WON *[,,][~~][,,][~~][,,][~~][,,][~~][,,][~~]";AT 10,0;"[X][X][X][X][X][X][X][X][X][X]* YOU WON *[X][X][X][X][X][X][X][X][X][X]";AT 10,0;"XXXXXXXXXX* [Y][O][U]█[W][O][N] *XXXXXXXXXX";AT 10,0;"*********** [Y][O][U]█[W][O][N] ***********";AT 10,0;" YOU WON "
2010 IF A(Q,N)=10 OR C<=0 THEN PRINT AT 10,0;"████████████[Y][O][U]█[L][O][S][E]████████████"
2020 NEXT B
2025 IF A(Q,N)=10 THEN PRINT AT 10,0;" YOU BLEW UP THE TREASURE "
2027 PRINT TAB 2;" TIME REMAINING: ";C*(C>0);" BLINKS"
2030 PRINT AT 21,0;"PLAY AGAIN? HIT [E][N][T][E][R]"
2040 INPUT A$
2050 CLS
2055 FAST
2060 GOTO 8Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

