Clear the Board
A game needs an ending. Count the pickups at the start, count them down as they're collected, and when the last one's gone, break the loop and show ALL CLEAR with the final score. The session gets a shape: enter, clear, done.
Collecting forever isn't a game — it needs a finish. Give the rover a goal it can complete: clear every pickup. Count how many there are, count them down as they go, and when the last one's taken, the board is clear and the game ends in triumph.
10 POKE 53281,0:PRINT CHR$(147)
20 GOSUB 500
30 SC=0:NP=4:GOSUB 700
40 R=4:C=5
50 POKE 1024+R*40+C,160:POKE 55296+R*40+C,7
60 J=PEEK(56320)
70 NR=R:NC=C
80 IF (J AND 1)=0 THEN NR=R-1
90 IF (J AND 2)=0 THEN NR=R+1
100 IF (J AND 4)=0 THEN NC=C-1
110 IF (J AND 8)=0 THEN NC=C+1
120 IF NR=R AND NC=C THEN 60
130 TC=PEEK(1024+NR*40+NC)
140 IF TC=160 THEN 60
150 IF TC=81 THEN SC=SC+10:NP=NP-1:GOSUB 700
160 POKE 1024+R*40+C,32
170 R=NR:C=NC
180 POKE 1024+R*40+C,160:POKE 55296+R*40+C,7
185 IF NP=0 THEN 900
190 GOTO 60
500 FOR C=1 TO 38
510 POKE 1024+40+C,160:POKE 55296+40+C,1
520 POKE 1024+23*40+C,160:POKE 55296+23*40+C,1
530 NEXT C
540 FOR R=1 TO 23
550 POKE 1024+R*40+1,160:POKE 55296+R*40+1,1
560 POKE 1024+R*40+38,160:POKE 55296+R*40+38,1
570 NEXT R
580 FOR R=3 TO 12:POKE 1024+R*40+19,160:POKE 55296+R*40+19,1:NEXT R
590 FOR C=8 TO 30:POKE 1024+16*40+C,160:POKE 55296+16*40+C,1:NEXT C
600 POKE 1024+4*40+8,81:POKE 55296+4*40+8,3
610 POKE 1024+4*40+11,81:POKE 55296+4*40+11,3
620 POKE 1024+4*40+14,81:POKE 55296+4*40+14,3
630 POKE 1024+4*40+17,81:POKE 55296+4*40+17,3
650 RETURN
700 POKE 1024+1,19:POKE 1024+2,3:POKE 1024+3,15:POKE 1024+4,18:POKE 1024+5,5
710 FOR I=1 TO 5:POKE 55296+I,7:NEXT I
720 S$=STR$(SC)
730 FOR I=1 TO LEN(S$)
740 POKE 1024+6+I,ASC(MID$(S$,I,1)):POKE 55296+6+I,7
750 NEXT I
760 RETURN
900 PRINT CHR$(147):POKE 53281,5:POKE 646,1
910 PRINT "ALL CLEAR!"
920 PRINT "FINAL SCORE: ";SC
930 END
A single counter does it. Line 30 sets NP = 4 — the number of pickups on the board. Line 150,
which already scores a pickup, now also drops NP by one each time one's collected. Then the new
line 185 checks it: IF NP = 0 THEN 900 — when the count reaches zero, the last pickup is gone,
so jump out of the game loop to the finish at line 900, which turns the screen green and shows
ALL CLEAR! and the score.
This is the win condition, the other half of the loop-with-a-goal you met in Safe Cracker. There, the loop ended when the safe cracked or the guesses ran out; here it ends when the board is clear. Either way, the lesson is the same: a game loop runs until something specific happens, and then it stops with a result. Counting the pickups down is how the rover's world knows it's finished.
Try this
- More to clear. Add more pickups in the maze routine and bump
NPon line 30 to match. The board takes longer to clear — a bigger level from two small changes. - Make the win land. Add a triumphant rising SID tone at line 900 before the screen changes, so clearing the board is heard as an achievement, not just shown.
What's next
The game can be won — but it starts the instant you run it, with no front door. In Unit 6 a title screen and a fire-to-start turn the program into a game you'd type in from a magazine.