Skip to content
Game 2 Unit 2 of 5 1 hr learning time

Hot and Cold

The game speaks in words — Too high, Too low. Now it speaks in colour too. ABS measures how far off the guess is, and the border shifts from cold blue to burning white, so you feel how close you are before you read a thing.

40% of Lucky Number

The game tells you "Too high!" and "Too low!" — but only in words, and only the direction. It says nothing about how close you are. A real game gives you that at a glance. We'll do it with the border.

  10 BORDER 0: PAPER 0: INK 7: CLS
  20 RANDOMIZE
  30 LET n = INT (RND * 100) + 1
  40 LET c = 0
  50 INVERSE 1: PRINT AT 2, 0; "   *** LUCKY NUMBER ***          ": INVERSE 0
  60 PRINT
  70 PRINT "I'm thinking of a number"
  80 PRINT "between 1 and 100."
  90 PRINT
 120 INPUT "Your guess: "; g
 130 LET c = c + 1
 140 LET d = ABS (g - n)
 150 IF d > 50 THEN BORDER 1
 160 IF d > 25 AND d <= 50 THEN BORDER 5
 170 IF d > 10 AND d <= 25 THEN BORDER 6
 180 IF d > 5 AND d <= 10 THEN BORDER 2
 190 IF d <= 5 THEN BORDER 7
 200 IF g = n THEN GO TO 310
 210 IF g < n THEN PRINT "Too low!"
 220 IF g > n THEN PRINT "Too high!"
 230 GO TO 120
 310 PRINT "Got it! The number was "; n
 320 PRINT "You found it in "; c; " guesses."

Six new lines, slotted into the gap between the counter and the loop. Line 140 measures the distance; lines 150–190 colour the border by how big that distance is.

ZX Spectrum screen with a blue border, the LUCKY NUMBER title and rules, and 'Too high!' — a guess of 95 against a secret of 42.
A guess of 95, secret 42 — far off, so the border turns blue. Cold. You know you're nowhere near before you read the words.

How it works

LET d = ABS (g - n) is the key. ABS gives the absolute value — the size of a number, ignoring its sign. ABS (20 - 42) is 22, and ABS (64 - 42) is also 22: both guesses are 22 away, one below and one above. Direction doesn't matter here, only distance — which is exactly what "hot and cold" measures.

Then five IFs map that distance to a BORDER colour:

DistanceBorderFeeling
Over 50Blue (1)Cold
26–50Cyan (5)Cool
11–25Yellow (6)Warm
6–10Red (2)Hot
5 or lessWhite (7)Burning

The ranges don't overlap — each guess lands in exactly one band — so the border is always a single, honest colour. Guess wildly and it stays blue; close in and it warms through yellow and red to white.

Two channels at once

The game now feeds you two ways at the same time: the words say which direction, the colour says how far. Words you have to read; colour you just see, out at the edge of your vision. That's the whole idea — give the player the same information through more than one sense, and the game starts to feel alive.

Next: sound joins in — a tone that tells you which way to go.