“Time Bomb” is a reaction and knowledge game that displays analogue clock faces on screen and challenges the player to read the time correctly within a countdown. The program generates random times using RND, filters them by difficulty level (1–5), where level 1 only allows times on the hour, level 2 on the half-hour, and so on down to five-minute and one-minute increments. Clock hands are drawn using trigonometric PLOT loops: a minute hand of length 14 units and an hour hand of length 10 units, both calculated with SIN and COS from the centre point (33, 22). A custom line-drawing subroutine at line 1000 steps along the dominant axis to plot each hand pixel by pixel. The player has five seconds on the counter and wins by reaching 10 correct answers; a wrong answer costs one count, a correct answer adds one, and reaching zero triggers an animated “BOOM” loop.
Program Analysis
Program Structure
The program is divided into four logical sections:
- Lines 1–20: Introduction, rules display, and difficulty level input.
- Lines 30–410: Main game loop — time generation, clock rendering, and response checking.
- Lines 1000–1120: Subroutine to draw a clock hand as a plotted line.
- Lines 2000–2120: Win and lose animations (flashing inverse-video loops).
Time Generation and Difficulty Filtering
A random integer between 100 and 1299 is generated at line 40 and treated as an HHMM time string. The minutes portion M$ is extracted by taking characters 3 onwards of the zero-padded string T$. Lines 80–120 reject invalid or unsuitable values in a retry loop:
- Line 80: Rejects minutes ≥ 60.
- Line 90: Level 1 — only exact hours (minutes must be 0).
- Line 100: Level 2 — minutes must be a multiple of 30.
- Line 110: Level 3 — multiples of 15.
- Line 120: Level 4 — multiples of 5.
- Level 5 (implicit): any valid time passes through.
This rejection-sampling approach is simple but can loop many times at lower levels since only a small fraction of random values satisfy the constraints.
Clock Face Rendering
The clock is drawn in two passes. First, hour numerals 1–12 are placed with PRINT AT using the formula AT 10-8*COS(D/6*PI), 16+8*SIN(D/6*PI) (line 160), positioning each digit on a circle of radius 8 character cells. Second, the clock rim is plotted as 60 individual points on a circle of radius 20 pixels centred at (33, 22) using PLOT with SIN/COS (lines 190–200).
Hand Calculation
The minute hand endpoint is computed at lines 240–260 using L = VAL M$ / 30 * PI, giving a full circle across 60 minutes, with hand length 14 pixels. Hour hand position is calculated at lines 210–300: the hour value H starts as twice the integer hours and is incremented at lines 220–230 if minutes are past the quarter or three-quarter marks (a coarse but functional approximation of hour-hand sweep). The angle G = H/12*PI drives a hand of length 10 pixels.
Line-Drawing Subroutine (Lines 1000–1120)
Rather than using a Bresenham algorithm, the subroutine draws each hand by stepping from the clock centre (33, 22) toward the computed endpoint (D, E). The dominant axis difference is found at line 1070:
C = (A AND ABS A >= ABS B) + (B AND ABS B > ABS A)
This uses ZX81 BASIC’s numeric AND to select whichever of the horizontal or vertical span is larger as the step count, ensuring a roughly continuous line. The guard at line 1080 prevents division by zero when the endpoint equals the centre. Each point is plotted by stepping F from 0 to C and interpolating both coordinates.
Response Handling
The player enters the time as a plain integer (e.g., 130 for 1:30). The response is compared directly to TIME (the raw random integer) at line 350. A correct answer increments COUNT; reaching 10 wins. A wrong answer decrements it; reaching 0 loses. The game then loops back to line 40 for a new time.
Win/Lose Animations
Both end states use infinite GOTO loops. The win screen (line 2010) alternates a normal and inverse-video “YOU DID IT” on each pass. The lose screen (lines 2110–2120) similarly alternates “BOOM” in normal and inverse video, creating a flashing effect.
Bugs and Anomalies
- The hour-hand approximation (incrementing
Hat the 15- and 45-minute marks) means the hour hand only takes two intermediate positions per hour rather than sweeping continuously, which can make some times ambiguous to read. - The difficulty level filter has no upper bound check; entering a level above 5 will accept any valid time (same as level 5) since no rule rejects it.
- The
INPUT RESPONSEat line 340 expects a numeric value; entering a non-numeric string would cause an error rather than a graceful wrong-answer response. - Variable
Dis reused as both the loop variable in the numeral-drawingFORloop (line 150) and as the x-endpoint of clock hands (lines 260, 300), which is not a problem in practice because the hand calculations happen after the loop exits.
Content
Source Code
1 REM "TIME BOMB"
2 FAST
5 RAND
10 PRINT "YOU HAVE FIVE SECONDS TO DEFUSE A BOMB. YOU WILL BE SHOWN A SERIES OF CLOCK FACES SHOWING TIMES PICKED AT RANDOM. IF YOU ENTER THE CORRECT TIME YOU ARE GIVEN AN EXTRA SECOND. IF YOU ENTER THE WRONG TIME IT COSTS YOU A SECOND. IF THE COUNT REACHES ZERO THE BOMB EXPLODES. IF THE COUNT REACHES 10 YOU DEFUSE THE BOMB. DO NOT ENTER ACOLON TO ENTER THE TIME. 1:30 IS ENTERED AS 130. SELECT LEVEL(1 - 5)"
20 INPUT LEVEL
30 LET COUNT=5
40 LET TIME=INT (RND*1200)+100
50 LET T$=STR$ TIME
60 IF LEN T$=3 THEN LET T$="0"+T$
70 LET M$=T$(3 TO )
80 IF VAL M$>59 THEN GOTO 40
90 IF VAL M$<>0 AND LEVEL=1 THEN GOTO 40
100 IF (VAL M$/30)<>INT (VAL M$/30) AND LEVEL=2 THEN GOTO 40
110 IF (VAL M$/15)<>INT (VAL M$/15) AND LEVEL=3 THEN GOTO 40
120 IF (VAL M$/5)<>INT (VAL M$/5) AND LEVEL=4 THEN GOTO 40
130 CLS
150 FOR D=1 TO 12
160 PRINT AT 10-8*COS (D/6*PI),16+8*SIN (D/6*PI);D
170 NEXT D
180 FOR I=1 TO 60
190 PLOT 33+20*SIN (I/30*PI),22+20*COS (I/30*PI)
200 NEXT I
210 LET H=2*INT (TIME/100)
220 IF VAL M$>15 THEN LET H=H+1
230 IF VAL M$>45 THEN LET H=H+1
240 LET L=VAL M$/30*PI
250 LET D=33+14*SIN L
260 LET E=22+14*COS L
270 GOSUB 1000
280 LET G=H/12*PI
290 LET D=33+10*SIN G
300 LET E=22+10*COS G
310 GOSUB 1000
330 PRINT AT 0,25;COUNT
340 INPUT RESPONSE
350 IF RESPONSE<>TIME THEN GOTO 390
360 LET COUNT=COUNT+1
370 IF COUNT=10 THEN GOTO 2000
380 GOTO 410
390 LET COUNT=COUNT-1
400 IF COUNT=0 THEN GOTO 2100
410 GOTO 40
\n1000 REM DRAW
\n1010 LET X=33
\n1020 LET Y=22
\n1050 LET A=X-D
\n1060 LET B=Y-E
\n1070 LET C=(A AND ABS A>=ABS B)+(B AND ABS B>ABS A)
\n1080 IF C=0 THEN LET C=0.1
\n1090 FOR F=0 TO C STEP SGN C
\n1100 PLOT X+A/C*-F,Y+B/C*-F
\n1110 NEXT F
\n1120 RETURN
\n2000 CLS
\n2010 PRINT "YOU DID IT","%Y%O%U% %D%I%D% %I%T"
\n2020 GOTO 2010
\n2100 CLS
\n2110 PRINT "BOOM";"%B%O%O%M";
\n2120 GOTO 2110
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.


