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

The Cards

User-defined graphics turn the bare numbers into real playing cards — design a suit symbol, POKE it into the character set, and deal it from a card subroutine.

50% of Hi Lo

The logic works on plain numbers, but Hi-Lo is a card game. This unit makes it look like one, and it is the biggest single step in the build. The new idea: user-defined graphics — shapes you design yourself and add to the Spectrum's character set — drawn through a card subroutine, with a face-down card for the unknown next one.

  10 BORDER 0: PAPER 0: INK 7: CLS
  20 DATA 0,102,255,255,255,126,60,24
  30 DATA 24,60,126,255,126,60,24,0
  40 DATA 24,60,24,126,255,126,24,60
  50 DATA 24,60,126,255,255,24,60,0
  60 FOR u = 0 TO 3: FOR j = 0 TO 7: READ b: POKE USR CHR$ (144 + u) + j, b: NEXT j: NEXT u
  70 LET f$ = "A234567890JQK"
  80 RANDOMIZE
 180 LET a = INT (RND * 13) + 1
 190 LET sa = INT (RND * 4) + 1
 200 LET streak = 0
 210 CLS
 220 INVERSE 1: PRINT AT 0, 0; " *** HI-LO ***  S:"; streak; "            ": INVERSE 0
 230 LET v = a: LET s = sa: LET cx = 5: LET cy = 4: GO SUB 800
 240 LET cx = 18: GO SUB 910
 250 PRINT AT 17, 4;
 260 INPUT "Higher or lower (H/L)? "; g$
 270 LET b = INT (RND * 13) + 1
 280 LET sb = INT (RND * 4) + 1
 290 LET v = b: LET s = sb: LET cx = 18: LET cy = 4: GO SUB 800
 300 LET ok = 0
 310 IF g$ = "H" AND b > a THEN LET ok = 1
 320 IF g$ = "L" AND b < a THEN LET ok = 1
 330 IF b = a THEN LET ok = 1
 340 IF ok = 0 THEN PRINT AT 15, 8; "Wrong!": STOP
 350 LET streak = streak + 1
 370 PRINT AT 15, 8; "Correct!"
 410 LET a = b: LET sa = sb
 420 GO TO 210
 800 REM Draw card at cx, cy with value v and suit s
 810 PAPER 7: INK 0
 820 FOR i = 0 TO 6: PRINT AT cy + i, cx; "         ": NEXT i
 830 LET e$ = f$(v TO v)
 840 IF v = 10 THEN LET e$ = "10"
 850 PRINT AT cy, cx + 1; e$
 860 PRINT AT cy + 6, cx + 7 - LEN e$; e$
 870 IF s <= 2 THEN INK 2
 880 PRINT AT cy + 3, cx + 4; CHR$ (143 + s)
 890 PAPER 0: INK 7
 900 RETURN
 910 REM Draw face-down card at cx, cy
 920 PAPER 1: INK 5
 930 FOR i = 0 TO 6: PRINT AT cy + i, cx; "         ": NEXT i
 940 PRINT AT cy + 3, cx + 4; "?"
 950 PAPER 0: INK 7
 960 RETURN
ZX Spectrum screen: a face-up Ace of diamonds on the left and a blue face-down card with a question mark on the right, under a HI-LO status bar
Two cards on the table — one dealt face up, the next face down until you guess.

User-defined graphics

The Spectrum lets you design your own characters. CHR$ 144 to CHR$ 164 are blank slots — twenty-one characters waiting for a shape. Hi-Lo claims the first four for the card suits.

A character is an 8×8 grid of pixels, stored as eight bytes — one per row. Each byte's bits switch the pixels on or off: 255 is a full row (11111111), 24 is two pixels in the middle (00011000). Lines 20–50 hold the four suit shapes as DATA: eight numbers each. Line 60 installs them:

FOR u = 0 TO 3: FOR j = 0 TO 7: READ b: POKE USR CHR$ (144 + u) + j, b: NEXT j: NEXT u

USR CHR$ (144 + u) is the memory address where character 144 + u lives. READ b pulls the next number from the DATA list, and POKE writes it into that character's grid, one row at a time. The outer loop picks the character; the inner loop writes its eight rows. DATA and READ work as a pair — DATA lists values anywhere in the program, READ walks them in order, like dealing from a deck. It is the tidy way to load a table of numbers (you will meet it again, in full, in later games).

Drawing a card

The card subroutine starts at line 800. Give it a value v, a suit s, and a position cx, cy, then GO SUB 800. It draws a white rectangle (PAPER 7, lines 810–820), prints the rank in two corners (lines 850–860), and stamps the suit in the middle (line 880). The rank comes from a string: line 70 sets f$ = "A234567890JQK", and f$(v TO v) picks the v-th character — card 1 is "A", card 13 is "K". Line 840 handles the one awkward case: card 10 needs two characters, "10". The suit is your custom character, CHR$ (143 + s), and line 870 paints hearts and diamonds red with INK 2 while clubs and spades stay black.

The face-down card

The next card is a mystery until the player commits. The subroutine at line 910 draws it face-down — a blue rectangle with a ? in the middle. Line 240 deals it on the right; line 290 turns it over, drawing the real card once the guess is in. Same game as before, but now it looks like cards on a table.

Next: reward a correct call so a hit feels like a hit.