Skip to content
Game 9 Unit 2 of 6 1 hr learning time

The Rules of the Round

Turn the reveal into a game: lives that drop on a miss, a win when the word completes, and a tried-list so a repeated guess never costs you twice.

33% of Cipher

The reveal works, but with nothing at stake it is just typing the alphabet. A round needs three rules: a miss should cost you, completing the word should win, and guessing the same letter twice should not be allowed. All three are patterns you have used before — here they combine into Cipher's round.

  10 BORDER 0: PAPER 0: INK 7: CLS
 120 DATA "SPECTRUM"
 190 RESTORE
 200 READ w$
 210 LET d$ = ""
 220 FOR i = 1 TO LEN w$: LET d$ = d$ + "_": NEXT i
 230 LET lives = 7
 240 LET z$ = ""
 250 CLS
 290 FOR i = 1 TO LEN d$: PRINT d$(i); " ";: NEXT i
 340 PRINT: PRINT "Lives: "; lives
 380 PRINT "Tried: "; z$
 390 PRINT
 400 INPUT "Guess: "; g$: IF g$ >= "a" AND g$ <= "z" THEN LET g$ = CHR$ (CODE g$ - 32)
 410 LET already = 0
 420 FOR i = 1 TO LEN z$
 430 IF z$(i) = g$ THEN LET already = 1
 440 NEXT i
 450 IF already = 1 THEN PRINT "Already tried!": PAUSE 50: GO TO 250
 460 LET z$ = z$ + g$
 470 LET found = 0
 480 FOR i = 1 TO LEN w$
 490 IF w$(i) = g$ THEN LET d$(i TO i) = g$: LET found = 1
 500 NEXT i
 510 IF found = 0 THEN LET lives = lives - 1: BEEP 0.1, -5
 520 IF found = 1 THEN BEEP 0.1, 10
 530 IF d$ = w$ THEN PRINT "You cracked it!": STOP
 540 IF lives = 0 THEN PRINT "The word was "; w$: STOP
 550 GO TO 250
ZX Spectrum Cipher: the word S _ _ _ T _ _ _, Lives: 6, Tried: STZ
Lives drop on a miss; every guess joins the tried list, hit or miss.

Lives, on a miss

Line 230 starts lives at 7; line 470 sets a found flag to 0 before the scan and line 490 flips it to 1 if the guess matches any position. That is the same found-flag pattern from Hi-Lo's ok — check first, respond once. Line 510 responds: IF found = 0 THEN LET lives = lives - 1 with a low beep. Line 540 ends the game when lives reach zero, revealing the word.

A win, when the word completes

Line 530 — IF d$ = w$ THEN ... — compares the revealed string to the answer. The moment the last underscore is filled, d$ equals w$ exactly, and the round is won. Comparing the working copy against the target is the cleanest possible win test: no counting, no flags, just "are they the same yet?"

No wasted guesses

Lines 410–460 are the new wrinkle. Before acting on a guess, a short loop scans z$ — the string of letters already tried — to see if this one is in it (the already flag, the same membership scan you wrote in Bright Spark). If so, the program says "Already tried!" and loops back without spending a life. Otherwise line 460 adds the letter to z$. Keeping a running string of what's been guessed, and checking against it, is how a game remembers a set of things — you will reach for it constantly.

Next: make it look like a game, not a list.