This program implements a two-player dice game where the user competes against the computer over 10 rolls, with the highest cumulative score winning. The player rolls by pressing ENTER to stop an animated spinning die, while the computer rolls automatically using a random number generator. Die faces are rendered using dot characters printed at fixed screen positions via AT coordinates. The computer’s roll subroutine is selected through a calculated GOSUB using the expression `(200+10*INT(RND*6))`, jumping directly to one of six face-display routines at lines 200–250.
Program Analysis
Program Structure
The program is organised into a main game loop and a set of subroutines. Initialisation occurs at lines 5–11, the game loop runs from lines 25–60, and line 100 halts execution. The subroutine at lines 180–199 handles the player’s roll (animated die with ENTER to stop), and lines 200–255 contain six individual die-face display routines, one per pip value.
| Lines | Purpose |
|---|---|
| 5–11 | Title print, initialise scores M (player) and Y (computer) to 0 |
| 20 | Draw static screen layout with column headers |
| 25–60 | Main FOR loop, 10 iterations |
| 180–199 | Player roll subroutine — animated spinning die, stopped by ENTER |
| 200–255 | Six die-face display routines, each setting D and RETURNing |
| 300–310 | SAVE and RUN (program re-launch) |
Calculated GOSUB Technique
Both the player animation loop (line 190) and the computer’s roll (line 50) use a calculated GOSUB expression: GOSUB (200+10*INT(RND*6)). This evaluates to one of 200, 210, 220, 230, 240, or 250, directly calling the appropriate die-face subroutine. This is an efficient idiom that replaces what would otherwise require a multi-branch IF/THEN chain, saving lines and execution time.
Die Face Rendering
Each die face is drawn using two rows of three characters printed with AT coordinates. Pips are represented by the period character (.) and blanks as spaces, within a fixed 3×2 character cell at columns 13–15, rows 10–11. A surrounding box border is drawn at lines 185 once per player turn.
| Line | Die Value | Row 10 (cols 13–15) | Row 11 (cols 13–15) |
|---|---|---|---|
| 200 | 1 | " . " | " " |
| 210 | 2 | " . " | " . " |
| 220 | 3 | ".. " | " . " |
| 230 | 4 | ".. " | ".. " |
| 240 | 5 | "..." | ".. " |
| 250 | 6 | "..." | "..." |
Player Input Idiom
The player’s roll animation at lines 190–192 uses a tight loop: GOSUB (200+10*INT(RND*6)) picks and displays a random face, then line 192 checks IF INKEY$="" THEN GOTO 190. This continues cycling through random die faces until any key is held, at which point the loop exits and the displayed face value (stored in D) is used. This is a classic Sinclair BASIC spinning-die idiom without requiring a PAUSE statement.
Score Tracking
Player score is accumulated in M and computer score in Y, both initialised to zero at lines 10–11. After each pair of rolls, both totals are printed at fixed AT positions in line 30 and line 45. No win/loss comparison or message is displayed at line 100 — execution simply stops, leaving the final scores visible on screen for the player to judge.
Bugs and Anomalies
- The program never compares
MandYat the end, so no winner is announced — the player must read the scores manually afterSTOPat line 100. - The die border drawn at line 185 uses strings of different lengths (
" "at row 12 is 8 characters while others are 6), creating a slightly uneven box. - Line 300 contains a
SAVEfollowed byRUNat line 310, providing a convenient way to both save and immediately restart the game.
Content
Source Code
5 PRINT " DICE"
10 LET M=0
11 LET Y=0
20 PRINT AT 0,2;"HIGHEST SCORE IN 10 ROLLS WINS";AT 2,5;" YOU ME "
25 FOR I=1 TO 10
30 PRINT AT 3,6;M;AT 3,19;Y;AT 16,11;"YOUR ROLL."
35 GOSUB 180
40 LET M=M+D
45 PRINT AT 3,6;M;AT 16,10;" MY ROLL. "
50 GOSUB (200+10*INT (RND*6))
55 LET Y=Y+D
60 NEXT I
100 STOP
180 PRINT AT 18,0;"PRESS ENTER TO STOP THE DICE."
185 PRINT AT 9,12;" DICE ";AT 10,12;" ";AT 11,12;" ";AT 12,12;" "
190 GOSUB (200+10*INT (RND*6))
192 IF INKEY$="" THEN GOTO 190
199 RETURN
200 PRINT AT 10,13;" . ";AT 11,13;" "
202 LET D=1
205 RETURN
210 PRINT AT 10,13;" . ";AT 11,13;" . "
212 LET D=2
215 RETURN
220 PRINT AT 10,13;".. ";AT 11,13;" . "
222 LET D=3
225 RETURN
230 PRINT AT 10,13;".. ";AT 11,13;".. "
232 LET D=4
235 RETURN
240 PRINT AT 10,13;"...";AT 11,13;".. "
242 LET D=5
245 RETURN
250 PRINT AT 10,13;"...";AT 11,13;"..."
252 LET D=6
255 RETURN
300 SAVE "1007%1"
310 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
