A Growing Sequence
Hold the sequence in a string of digits — grow it with STR$, read it back with s$(i), size it with LEN. The one genuinely new idea in the game.
A flash shows one panel. A memory game needs a whole sequence — and somewhere to keep it.
This is the new idea Bright Spark is built around: store the sequence as a string of
digits. Panel 3 then panel 1 then panel 4 is just the string "314". Strings can grow, and
you can pull out any character by position, which is exactly what a sequence needs.
10 BORDER 0: PAPER 0: INK 7: CLS
20 RANDOMIZE
110 CLS
120 GO SUB 540
140 LET s$ = ""
150 LET s$ = s$ + STR$ (INT (RND * 4) + 1)
170 PAUSE 25
180 FOR i = 1 TO LEN s$
190 LET p = VAL s$(i)
200 GO SUB 640
210 PAUSE 15
220 NEXT i
230 STOP
540 REM --- Draw all panels ---
550 PAPER 2
560 FOR r = 2 TO 9: PRINT AT r, 1; " 1 ": NEXT r
570 PAPER 1
580 FOR r = 2 TO 9: PRINT AT r, 17; " 2 ": NEXT r
590 PAPER 4
600 FOR r = 12 TO 19: PRINT AT r, 1; " 3 ": NEXT r
610 PAPER 6
620 FOR r = 12 TO 19: PRINT AT r, 17; " 4 ": NEXT r
630 PAPER 0: RETURN
640 REM --- Flash panel p ---
650 IF p = 1 THEN PAPER 2: LET pr = 2: LET pc = 1: LET note = 5
660 IF p = 2 THEN PAPER 1: LET pr = 2: LET pc = 17: LET note = 10
670 IF p = 3 THEN PAPER 4: LET pr = 12: LET pc = 1: LET note = 15
680 IF p = 4 THEN PAPER 6: LET pr = 12: LET pc = 17: LET note = 20
690 BRIGHT 1
700 FOR r = pr TO pr + 7: PRINT AT r, pc; " ": NEXT r
710 BEEP 0.3, note
720 BRIGHT 0
730 FOR r = pr TO pr + 7: PRINT AT r, pc; " ": NEXT r
740 PAPER 0: RETURN
Build, index, measure
Three string tools carry the whole sequence:
- Grow it. Line 140 starts
s$empty (""). Line 150 adds one panel: `STR$ (INT (RND * 4)- 1)
rolls a panel number andSTR$turns that *number* into a *character*, which+sticks onto the end ofs$`. Run line 150 again and the sequence is one longer.
- 1)
- Index it. Line 190 reads the
ith panel withs$(i)— character numberiof the string — andVALturns that character back into a number for the flash routine.STR$andVALare opposites: number to string, string to number. - Measure it. Line 180's
FOR i = 1 TO LEN s$walks every character.LEN s$is how many there are — the length of the sequence — so the loop replays exactly as many flashes as the string holds.
Why a string
You could imagine a separate variable per step, but the sequence grows without limit — there is
no fixed number of variables that would do. A string has no such ceiling: it stretches to
whatever length the game reaches, and s$(i) plus LEN let you treat it as a numbered list.
Build, index, measure is the pattern behind any growing collection a program must remember.
Right now the computer shows the sequence and stops. Next: the player repeats it back.