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

Cipher

A custom heart for each life and a title screen with the rules finish the game. Cipher, complete — and Volume 2 begun.

100% of Cipher

The game is complete in substance; two touches finish it. A custom heart in place of the star for each life, and a title screen that states the rules before the first word. Both use tools you have — the point is the polish, and the close of the first Volume 2 game.

  10 BORDER 0: PAPER 0: INK 7: CLS
  20 DATA 0,102,255,255,255,126,60,24
  30 FOR j = 0 TO 7: READ b: POKE USR "A" + j, b: NEXT j
  40 RANDOMIZE
  50 LET a$ = "*** CIPHER ***": LET y = 5: GO SUB 9000
  60 PRINT AT 7, 4; "Guess the hidden word,"
  70 PRINT AT 8, 4; "one letter at a time."
  80 PRINT AT 9, 4; "You have 7 lives per word."
  90 PLOT 120, 78: DRAW 16, 0: DRAW 0, -16: DRAW -16, 0: DRAW 0, 16: CIRCLE 128, 86, 8
 100 PRINT AT 15, 4; "Press any key to start"
 110 PAUSE 0
 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 120
 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 2: FOR i = 1 TO lives: PRINT CHR$ 144;: 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 title screen: the centred title, the rules, a small drawn icon, and Press any key to start
The finished front door: the rules, a drawn icon, and a key to begin.

Hearts and a front door

Lines 20–30 define a heart as a user-defined graphic — the DATA/READ/POKE USR recipe from Hi-Lo — and the lives bar (line 350) now prints CHR$ 144 in red instead of a star, so each life is a little heart. Lines 50–110 are the title: GO SUB 9000 centres the name, a few PRINT AT lines give the rules, and PLOT/DRAW/CIRCLE from Reflex sketch a small icon before PAUSE 0 waits for the player. A turn-based game needs no clock on its front door, so the rules can sit there as long as the reader likes.

What you built

Cipher began as a word behind underscores and grew into a data-driven word game: a reveal that writes guesses into a string by slice, a round with lives and a tried-set, a coloured board, a list of words chosen at random from DATA, a running tally, and end screens. The two new ideas carried it — slice-assignment for the reveal, and DATA as a content list for the words — while everything else was Volume 1 craft, reused without ceremony.

That reuse is the story of Volume 2. You are past learning the verbs; now you arrange them into programs that hold and reason about state. Next: Quiz Master — four rounds of questions, a climbing score, and arrays to hold them.