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

Rounds

One word ends and the next begins: win and lose screens that reveal the answer, a wins-and-losses tally that survives between words, and a loop straight into the next round.

83% of Cipher

A single word is over too soon. Cipher wants to be played in a run — word after word, with a score that climbs. This unit adds proper end screens, a tally that persists across rounds, and a loop back for the next word. It is all framing you built in Volume 1, applied to a turn-based game.

  10 BORDER 0: PAPER 0: INK 7: CLS
  40 RANDOMIZE
 120 DATA "SPECTRUM","COMPUTER","KEYBOARD","PROGRAM","SCREEN"
 130 DATA "PRINTER","CASSETTE","JOYSTICK","MEMORY","CIRCUIT"
 140 DATA "DISPLAY","LOADING","BORDER","COLOUR","PIXEL"
 150 DATA "BINARY","CURSOR","VOLUME","SYSTEM","BEEPER"
 160 LET total = 20
 170 LET wins = 0: LET losses = 0
 180 LET pick = INT (RND * total) + 1
 190 RESTORE
 200 FOR i = 1 TO pick: READ w$: NEXT i
 210 LET d$ = ""
 220 FOR i = 1 TO LEN w$: LET d$ = d$ + "_": NEXT i
 230 LET lives = 7
 240 LET z$ = ""
 250 CLS
 260 INVERSE 1: PRINT AT 0, 0; "       *** CIPHER ***           ": INVERSE 0
 270 PRINT AT 1, 4; "Won: "; wins; "  Lost: "; losses; "   "
 280 PRINT AT 4, 2;
 290 FOR i = 1 TO LEN d$
 300 IF d$(i) = "_" THEN INK 7: PRINT "_ ";
 310 IF d$(i) <> "_" THEN INK 4: PRINT d$(i); " ";
 320 NEXT i
 330 INK 7
 340 PRINT AT 7, 2; "Lives: ";
 350 INK 4: FOR i = 1 TO lives: PRINT "*";: NEXT i
 360 FOR i = lives + 1 TO 7: PRINT " ";: NEXT i
 370 INK 7
 380 PRINT AT 9, 2; "Tried: "; z$; "  "
 390 PRINT AT 12, 2;
 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 AT 14, 2; INK 6; "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 LET wins = wins + 1: GO TO 700
 540 IF lives = 0 THEN LET losses = losses + 1: GO TO 770
 550 GO TO 250
 700 CLS: LET a$ = "*** CIPHER ***": LET y = 6: GO SUB 9000
 710 PRINT AT 9, 4; INK 4; "You cracked it!"
 720 PRINT AT 11, 4; "The word was "; w$
 730 BEEP 0.1, 10: BEEP 0.1, 15: BEEP 0.1, 20
 740 PRINT AT 14, 4; INK 7; "Won: "; wins; "  Lost: "; losses
 750 PRINT AT 18, 4; "Press any key for next word"
 760 PAUSE 0: GO TO 180
 770 CLS: LET a$ = "*** CIPHER ***": LET y = 6: GO SUB 9000
 780 PRINT AT 9, 4; INK 2; "Out of lives!"
 790 PRINT AT 11, 4; "The word was "; w$
 800 BEEP 0.3, -10
 810 PRINT AT 14, 4; INK 7; "Won: "; wins; "  Lost: "; losses
 820 PRINT AT 18, 4; "Press any key for next word"
 830 PAUSE 0: GO TO 180

9000 PRINT AT y, (32 - LEN a$) / 2; BRIGHT 1; a$
9010 RETURN
ZX Spectrum Cipher lose screen: Out of lives!, The word was SPECTRUM, Won: 0 Lost: 1, Press any key for next word
A lost round reveals the answer and updates the tally — then a key brings the next word.

A tally that survives the round

Line 170 sets wins and losses to zero once, before the round loop — so when the game jumps back for a new word, the totals carry over. A win adds to wins, a loss to losses, and the header (line 270) shows both. This is the persistent-score idea from Hi-Lo's best score: keep the counter outside the loop that resets everything else, and it remembers.

Win and lose screens

The win and lose checks now jump to dedicated routines (lines 700 and 770) instead of a bare STOP. Each clears the screen, recentres the title through GO SUB 9000 (the subroutine from Oracle Stone), reveals the word, plays a fanfare or a buzzer, shows the running tally, and waits for a key. Then GO TO 180 — back to pick a fresh word, not back to line 170, so the tally is preserved. The two outcomes get the full performance treatment, the same lesson as every Volume 1 finale: don't report the result, deliver it.

Next: the finishing touches — a custom life icon and a front door.