Skip to content
Game 10 Unit 16 of 16 1 hr learning time

The Complete Game

The finished Night Patrol — five floors of stealth, sightlines, and escalating tension.

100% of Night Patrol

Every system is in place: map rendering, wall collision, guard patrols, sightlines, detection drama, lives, objectives, exits, five floors, title screen, victory sequence. This is Night Patrol — the complete game.

The Program

10 BORDER 0: PAPER 0: INK 7: CLS
15 GO SUB 900
20 DIM m$(8, 16)
30 LET v = 3: LET e = 0: LET l = 1
35 DIM b(5): LET b(1) = 1: LET b(2) = 5: LET b(3) = 4: LET b(4) = 6: LET b(5) = 3
40 RESTORE 1000
50 REM load floor
55 BORDER b(l)
60 FOR i = 1 TO 8
70 READ m$(i)
80 NEXT i
90 READ r, c, g, h, d$, o, p, w, x
100 LET q = 1: LET t = 0: LET s = 20 - l * 3: LET f$ = d$(1 TO 1)
110 LET j = 0
120 CLS
125 PRINT AT 10, 5; INK 7; "Floor "; l
126 PAUSE 40
130 CLS: GO SUB 800
135 PRINT AT o + 2, p + 2; INK 6; "*"
136 PRINT AT w + 2, x + 2; INK 1; "X"
140 GO SUB 870
150 REM game loop
155 GO SUB 700
160 PRINT AT r + 2, c + 2; INK 7; BRIGHT 1; "@"
170 PRINT AT g + 2, h + 2; INK 2; "G"
180 LET t = t + 1
190 LET k$ = INKEY$
200 IF k$ = "" THEN GO TO 240
210 LET u = r: LET i = c
212 IF k$ = "q" THEN LET u = r - 1
214 IF k$ = "a" THEN LET u = r + 1
216 IF k$ = "o" THEN LET i = c - 1
218 IF k$ = "p" THEN LET i = c + 1
220 IF u < 1 OR u > 8 OR i < 1 OR i > 16 THEN GO TO 240
222 IF m$(u)(i TO i) = "#" THEN GO TO 240
224 PRINT AT r + 2, c + 2; " "
226 LET r = u: LET c = i
228 IF r = o AND c = p AND j = 0 THEN LET j = 1: BEEP 0.1, 20: PRINT AT w + 2, x + 2; INK 4; "X": GO SUB 870
230 IF r = w AND c = x AND j = 1 THEN GO TO 550
240 IF t < s THEN GO TO 320
250 LET t = 0
255 GO SUB 760
260 PRINT AT g + 2, h + 2; " "
270 LET f$ = d$(q TO q)
280 IF f$ = "N" THEN LET g = g - 1
290 IF f$ = "S" THEN LET g = g + 1
300 IF f$ = "W" THEN LET h = h - 1
310 IF f$ = "E" THEN LET h = h + 1
315 LET q = q + 1: IF q > LEN d$ THEN LET q = 1
320 IF r = g AND c = h THEN GO TO 400
330 GO TO 150
400 REM detected
405 GO SUB 760
410 LET v = v - 1
415 PRINT AT g + 1, h + 2; INK 2; BRIGHT 1; "!"
420 BEEP 0.05, 30: BEEP 0.05, 25
425 BORDER 2: PAUSE 5: BORDER 0: PAUSE 3
430 BORDER 2: PAUSE 5: BORDER b(l)
435 BEEP 0.1, 20: BEEP 0.15, 15
440 PRINT AT g + 1, h + 2; " "
445 IF v = 0 THEN GO TO 500
460 PRINT AT g + 2, h + 2; " "
470 PRINT AT r + 2, c + 2; " "
480 RESTORE 1000: FOR i = 1 TO (l - 1) * 9 + 8: READ a$: NEXT i: READ r, c, g, h, d$, o, p, w, x
490 LET q = 1: LET f$ = d$(1 TO 1): LET t = 0
495 GO SUB 870: GO TO 150
500 CLS: BORDER 0
510 PRINT AT 8, 9; INK 2; "GAME OVER"
520 PRINT AT 10, 8; "Score: "; e
525 PRINT AT 11, 8; "Floor: "; l
530 BEEP 0.15, 0: BEEP 0.15, -3: BEEP 0.2, -7
540 STOP
550 REM floor complete
560 LET e = e + 10 * l
565 GO SUB 760
570 BEEP 0.15, 12: BEEP 0.15, 16: BEEP 0.3, 19
580 PRINT AT 12, 5; INK 4; "FLOOR "; l; " COMPLETE!"
590 PAUSE 50
600 LET l = l + 1
610 IF l > 5 THEN GO TO 650
620 GO TO 50
650 REM victory
660 CLS: BORDER 0
670 PRINT AT 6, 8; INK 4; "YOU ESCAPED!"
680 PRINT AT 8, 8; "Score: "; e
685 PRINT AT 10, 5; INK 7; "All floors cleared!"
690 BEEP 0.15, 12: BEEP 0.15, 16: BEEP 0.15, 19: BEEP 0.15, 24: BEEP 0.3, 24
695 STOP
700 REM === draw sightline ===
710 LET a = g: LET b = h
720 IF f$ = "N" THEN LET a = a - 1
722 IF f$ = "S" THEN LET a = a + 1
724 IF f$ = "W" THEN LET b = b - 1
726 IF f$ = "E" THEN LET b = b + 1
728 IF a < 1 OR a > 8 OR b < 1 OR b > 16 THEN RETURN
730 IF m$(a)(b TO b) = "#" THEN RETURN
732 IF a = r AND b = c THEN GO TO 400
734 PRINT AT a + 2, b + 2; INK 6; "."
736 GO TO 720
760 REM === clear sightline ===
770 LET a = g: LET b = h
772 IF f$ = "N" THEN LET a = a - 1
774 IF f$ = "S" THEN LET a = a + 1
776 IF f$ = "W" THEN LET b = b - 1
778 IF f$ = "E" THEN LET b = b + 1
780 IF a < 1 OR a > 8 OR b < 1 OR b > 16 THEN RETURN
782 IF m$(a)(b TO b) = "#" THEN RETURN
784 IF a = o AND b = p AND j = 0 THEN PRINT AT a + 2, b + 2; INK 6; "*": GO TO 772
786 IF a = w AND b = x THEN PRINT AT a + 2, b + 2; INK 4; "X": GO TO 772
788 PRINT AT a + 2, b + 2; " "
790 GO TO 772
800 REM === draw map ===
810 FOR y = 1 TO 8
820 FOR x = 1 TO 16
830 IF m$(y)(x TO x) = "#" THEN PRINT AT y + 2, x + 2; INK 1; CHR$ 143
840 NEXT x
850 NEXT y
860 RETURN
870 REM === draw HUD ===
880 PRINT AT 0, 0; INK 7; "Lives:"; v; " Score:"; e; " Floor:"; l; "  "
885 IF j = 0 THEN PRINT AT 1, 0; INK 6; "Find * then reach X "
886 IF j = 1 THEN PRINT AT 1, 0; INK 4; "Go to X exit!       "
890 RETURN
900 REM === title screen ===
905 PRINT AT 3, 7; INK 1; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143
910 PRINT AT 4, 7; INK 1; CHR$ 143; " "; CHR$ 143; "  "; CHR$ 143; "  "; CHR$ 143; "  "; CHR$ 143; " "; CHR$ 143
915 PRINT AT 5, 7; INK 1; CHR$ 143; " "; CHR$ 143; "  "; CHR$ 143; "  "; CHR$ 143; "  "; CHR$ 143; " "; CHR$ 143
920 PRINT AT 6, 7; INK 1; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143; CHR$ 143
925 PRINT AT 9, 7; INK 7; BRIGHT 1; "NIGHT PATROL"
930 PRINT AT 13, 6; INK 5; "Sneak past the"
935 PRINT AT 14, 6; INK 5; "guards. Collect *"
940 PRINT AT 15, 6; INK 5; "then reach the X."
945 PRINT AT 18, 5; INK 7; "Press any key"
950 BEEP 0.3, 0: BEEP 0.15, -5
955 PAUSE 0
960 RETURN
1000 REM floor 1
1010 DATA "################"
1020 DATA "#              #"
1030 DATA "#  ## ####  #  #"
1040 DATA "#     #     #  #"
1050 DATA "#  ####  #     #"
1060 DATA "#        #  #  #"
1070 DATA "#   ##      #  #"
1080 DATA "################"
1090 DATA 6,2,3,10,"WWWWWWEEEEEE",2,14,6,15
1100 REM floor 2
1110 DATA "################"
1120 DATA "#   #     #    #"
1130 DATA "#   #  ## # #  #"
1140 DATA "#   #     #    #"
1150 DATA "### #####  #   #"
1160 DATA "#          #   #"
1170 DATA "#   # #     #  #"
1180 DATA "################"
1190 DATA 6,2,3,5,"SSSSNNNN",2,14,6,15
1200 REM floor 3
1210 DATA "################"
1220 DATA "#       #      #"
1230 DATA "# ####  # ###  #"
1240 DATA "#       #      #"
1250 DATA "# ##### # ###  #"
1260 DATA "#              #"
1270 DATA "#  # #   # #   #"
1280 DATA "################"
1290 DATA 6,2,2,3,"EEEEEEEWWWWWWW",2,14,6,15
1300 REM floor 4
1310 DATA "################"
1320 DATA "#  #     #  #  #"
1330 DATA "#  #  #  #     #"
1340 DATA "#     #     #  #"
1350 DATA "#  #  #  #  #  #"
1360 DATA "#  #     #     #"
1370 DATA "#     #     #  #"
1380 DATA "################"
1390 DATA 6,2,2,8,"EEEESSSSWWWWNNNN",2,14,6,15
1400 REM floor 5
1410 DATA "################"
1420 DATA "#    #    #    #"
1430 DATA "# ## # ## # ## #"
1440 DATA "#    #    #    #"
1450 DATA "#### # ## # ####"
1460 DATA "#    #    #    #"
1470 DATA "# ##   ##   ## #"
1480 DATA "################"
1490 DATA 6,2,2,4,"EEEEEEEEEEWWWWWWWWWW",2,14,6,15

Night Patrol floor 1 — guard patrolling with sightline

The Complete Game Loop

The game follows a clear structure:

  1. Title screen — building silhouette, instructions, press any key
  2. Floor intro — “Floor N” displayed briefly
  3. Map drawing — walls, objective, exit rendered from data
  4. Game loop — draw sightline, draw player and guard, check input, move guard on tick, check detection, check objective/exit
  5. Detection — exclamation mark, alarm, border flash, life lost, reset
  6. Floor complete — score awarded, next floor loaded
  7. Victory or game over — escape message or final score

What Changed From Unit 15

The code is functionally identical to unit 15. This unit is about playing the game, not changing it. Run it, test every floor, and ask:

  • Is every floor solvable? Walk through each one. Can you reach the objective and exit without being detected?
  • Is the difficulty curve fair? Floor 1 should be easy. Floor 5 should be tense but achievable.
  • Do the sightlines clear properly? Watch the guard turn corners. Do stale dots linger?
  • Does detection feel right? Not too fast (unfair), not too slow (breaks tension).
  • Does the scoring make sense? Later floors are worth more. Does the total feel rewarding?

What You Built

Night Patrol is roughly 100 lines of BASIC that create a genuine stealth game. The map lives in DATA. The guard follows a route string. The sightline extends cell by cell. Detection is visual and audible. Five floors escalate the challenge.

Every technique from previous games contributed:

  • DIM arrays from Minefield — storing the map
  • String slicing from Word Worm — reading individual map cells
  • Counter-based timing from Word Worm — controlling guard speed
  • INKEY$ and erase-redraw from every game — player movement
  • DATA/READ from Quiz Master — loading level data
  • GO SUB from Minefield — organising code into subroutines
  • RESTORE — new in this game, navigating between data blocks

The Design Choices

The game works because of decisions made in data, not code:

  • 8x16 grid — small enough for BASIC’s speed, large enough for interesting layouts
  • One guard per floor — keeps the code simple, the challenge comes from sightlines
  • Visible sightlines — the player always knows the danger, so detection feels fair
  • Route strings — predictable AI that rewards patience and pattern reading
  • Gated exit — forces two passes through the danger zone

Try This

Design your own floors. The hardest part of Night Patrol is level design, not code. Create floor 6: draw the map in the DATA statements, choose guard position and route, place the objective in a dangerous spot, put the exit where the player must cross the sightline to reach it.

Speed challenge. Change the speed formula to s = 15 - l * 2. The guard moves much faster on later floors. Does the game still feel fair, or does BASIC’s input speed become the bottleneck?