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

The Board

Lay the round out as a board: an inverse title bar, the word in colour with revealed letters standing out, a lives bar of stars, and the tried letters in their own row.

50% of Cipher

The game plays, but it scrolls up the screen like a teletype. A turn-based game wants a board — a fixed layout that redraws in place each turn. Everything here is presentation you have done before; this unit just arranges it.

  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
 260 INVERSE 1: PRINT AT 0, 0; "       *** CIPHER ***           ": INVERSE 0
 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 PRINT "You cracked it!": STOP
 540 IF lives = 0 THEN PRINT "The word was "; w$: STOP
 550 GO TO 250
ZX Spectrum Cipher board: inverse CIPHER title, the word S _ E _ _ R _ _ with revealed letters in green, a six-star lives bar, and Tried: SERX
The board: an inverse title, the word in colour, a lives bar, and the letters tried so far.

A board that redraws

The loop now opens with CLS and rebuilds the whole screen at fixed PRINT AT positions — the inverse title bar (line 260), the word, the lives, the tried row — so each turn paints over the last instead of scrolling. You built exactly this dashboard pattern in Touchdown; a turn-based game uses it just the same, only without the hurry.

Colour that carries meaning

Lines 290–320 print the word a character at a time, choosing the ink as they go: a still-hidden _ prints white, a revealed letter prints in green (INK 4). The player's eye jumps straight to what they've found. The lives become a bar, too (lines 340–360): a green star per life, then spaces to rub out the ones spent — the same gauge idea as Touchdown's fuel and Dice Roller's chart, here counting down. Numbers would do the job; a shrinking row of stars does it faster.

Next: stop hard-coding one word and pick from a whole list.