The Grid
DIM with two indices makes an 8x8 grid, drawn with nested loops, and three targets are hidden on it — collision-checked so no two share a cell.
Every game so far has used a single value or a one-dimensional list. Sonar lives on a grid, so its state needs a second dimension — and once it exists, the game hides three targets on it.
10 BORDER 0: PAPER 0: INK 7: CLS
110 RANDOMIZE
120 DIM g(8,8)
130 FOR i = 1 TO 3
140 LET r = INT (RND * 8) + 1: LET c = INT (RND * 8) + 1
150 IF g(r,c) = 9 THEN GO TO 140
160 LET g(r,c) = 9
170 NEXT i
190 CLS
200 LET a$ = "*** SONAR ***": LET y = 0: GO SUB 9000
240 PRINT AT 3, 11; "12345678"
250 FOR r = 1 TO 8
260 PRINT AT 3 + r, 9; r;
270 FOR c = 1 TO 8
290 IF g(r,c) = 9 THEN PRINT "X";
300 IF g(r,c) = 0 THEN PRINT ".";
320 NEXT c
370 NEXT r
380 STOP
9000 PRINT AT y, (32 - LEN a$) / 2; BRIGHT 1; a$
9010 RETURN
Two indices, not one
DIM g(8,8) (line 120) is Quiz Master's DIM with a second index: 64 cells, each reached by
g(row, col). Think of a spreadsheet — the first number picks the row, the second the column.
Drawing it is the natural partner, a nested loop: the outer FOR r walks the rows, the
inner FOR c the columns within each, printing a dot per cell. You used nested loops for
categories-and-questions in Quiz Master; a grid is the same shape, rows-and-columns.
Hiding the targets
Lines 130–170 place three targets. Each picks a random row and column and marks that cell with
9 — but line 150 guards against a clash: IF g(r,c) = 9 THEN GO TO 140 rolls again if the
cell is already taken, so the three never overlap. "Pick at random, retry on collision" is the
standard way to place distinct things on a board. While you build, the draw shows a 9 cell as
X so you can see where the targets are and check your clue logic; the finished game hides
them.
Next: let the player probe a cell.