Hidden and Revealed
Add a second array to track which cells the player has uncovered.
In a real Minesweeper, you can’t see the numbers until you reveal them. The mine data is hidden — you only see what you’ve uncovered. This needs a second array to track each cell’s visibility.
The Program
How It Works
Line 30 creates the state array: DIM s(8,8). Every cell starts at 0 — hidden.
Lines 250-270 reveal three cells by setting s(1,1) = 1, s(4,4) = 1, and s(7,2) = 1.
Lines 300-370 draw the grid with visibility. The display logic checks s(r,c) first:
320 IF s(r, c) = 0 THEN PRINT ".";
330 IF s(r, c) = 1 AND m(r, c) = 9 THEN PRINT "*";
340 IF s(r, c) = 1 AND m(r, c) <> 9 THEN PRINT m(r, c);
State s(r,c) | Display |
|---|---|
| 0 (hidden) | . |
| 1 (revealed), mine | * |
| 1 (revealed), safe | number |
Lines 400-460 show the full “answer key” — every cell revealed — so you can verify the hidden view is correct.
Parallel Arrays
Two arrays with the same dimensions, working together:
| Array | Purpose | Values |
|---|---|---|
m(r,c) | Mine grid | 0-8 (counts) or 9 (mine) |
s(r,c) | Cell state | 0 (hidden) or 1 (revealed) |
The mine grid never changes after setup. The state grid changes during gameplay as the player reveals cells. Keeping them separate means the display logic can check both: “what is here?” and “can the player see it?”
Try This
Reveal all. Add a loop that sets every s(r,c) = 1, then redraw. The hidden view should match the answer key.
Random reveals. Reveal 10 random cells instead of 3 fixed ones. Each time you run the program, different cells are visible.
What You’ve Learnt
- Parallel arrays — two arrays with the same dimensions, different purposes
- State tracking — 0 for hidden, 1 for revealed
- Conditional display — check state before deciding what to show
- Separation of data and visibility — the world exists whether or not you can see it