Dice Game

This file is part of and Timex Sinclair Public Domain Library Tape 1006. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Game

This program implements a simple dice-betting game in which the player starts with $30 and repeatedly wagers on the outcome of three virtual dice rolls. Each round, the player chooses a bet amount (capped at their current stake) and a target number from 1 to 6; three dice are then rolled sequentially using RND, and any die matching the chosen number pays out the bet amount. Display uses inverse-video characters (the %X escapes) for a highlighted “GAME OVER” message, and UDG characters (CHR$ (C+156) and CHR$ (D+156)) to render die face graphics for each roll. A short busy-loop at lines 290–310 serves as a delay routine between dice reveals. The program alternates between a normal and inverse-video version of the “GAME OVER” text in a tight loop to produce a flashing effect.


Program Analysis

Program Structure

The program is organized around a main game loop (lines 10–270) with two subroutines sharing a single RETURN at line 310. The flow is as follows:

  1. Line 10: Initialize stake M=30
  2. Lines 20–70: Display stake, accept and validate bet amount A
  3. Lines 80–110: Accept and validate target number B (1–6)
  4. Lines 120–210: Roll three dice in a FOR loop, display results, accumulate winnings
  5. Lines 220–270: Pause, clear screen, check for bankruptcy or loop back
  6. Lines 280–310: Two subroutines — stake display (line 280) and delay loop (line 290) — sharing one RETURN

Subroutine Sharing

Lines 280–310 implement a dual-entry subroutine pattern. GOSUB 280 prints the current stake and then falls through into the delay loop before returning. GOSUB 290 skips the print and executes only the delay. This is a common Sinclair BASIC memory-saving idiom that avoids duplicating the FOR…NEXT delay code.

Dice Rolling and UDG Display

Each die result D is generated at line 150 with LET D=INT (RND*6)+1, producing values 1–6. The display at line 160 uses CHR$ (C+156) and CHR$ (D+156) to reference UDG characters in the range 157–162, presumably pre-defined elsewhere (or loaded as part of the saved program) to depict die faces. The die index C (1–3) is used to position each result on a separate screen row via AT 11+2*C,0.

Inverse-Video and Flash Effect

Line 160 uses the %X inverse-video escape to render the label text (“DIE”, “FELL”) in inverse. Lines 250 and 260 together create a flashing “GAME OVER” effect: line 250 prints the normal text and line 270 loops back to 250, while line 260 prints the same message in full inverse video. Because the GOTO 250 at line 270 passes through line 260 each cycle, the display alternates between normal and inverse rendering, producing a visible flash.

Win Condition and Stake Management

For each of the three dice, if D=B the player wins A dollars (line 170 sets W=A; line 190 adds W to M). If no die matches, W remains 0 from line 130 and nothing is added. The initial deduction of the bet occurs at line 70 (LET M=M-A) before the dice are rolled, so winnings are net additions on top of the already-reduced stake.

Input Validation

  • Bet size: Line 50 rejects bets larger than the current stake (IF A>M THEN GOTO 40), but does not guard against zero or negative bets.
  • Number choice: Line 110 enforces 1 ≤ B ≤ 6 with IF B<1 OR B>6 THEN GOTO 80.

Delay Routine

The delay subroutine at lines 290–310 is a simple busy-loop iterating 50 times with an empty FOR N=1 TO 50 / NEXT N. This provides a brief pause between dice reveals to create a sense of suspense. The loop count of 50 may feel very short on slower machines but was likely tuned for the target hardware speed.

Save and Auto-Run

Lines 320–340 perform a CLEAR, SAVE, and RUN sequence. The filename "1029%2" contains an inverse-video character (%2), which encodes the auto-run flag in the tape header so the program starts automatically on load.

Notable Anomalies

LineIssue
130LET W=0 is inside the FOR C loop, correctly resetting the win flag each die roll.
250–270The alternating normal/inverse loop never terminates; there is no STOP or escape, so the player must perform a manual break.
50No guard against A≤0; a bet of zero is accepted and results in no stake change per round.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10252 – 10293.

Related Products

Related Articles

Related Content

Image Gallery

Source Code

  10 LET M=30
  20 GOSUB 280
  30 PRINT AT 6,8;"SIZE OF BET ? ";
  40 INPUT A
  50 IF A>M THEN GOTO 40
  60 PRINT "$";A
  70 LET M=M-A
  80 PRINT AT 10,8;"NUMBER ? ";
  90 INPUT B
 100 PRINT B
 110 IF B<1 OR B>6 THEN GOTO 80
 120 FOR C=1 TO 3
 130 LET W=0
 140 GOSUB 290
 150 LET D=INT (RND*6)+1
 160 PRINT AT 11+2*C,0;"%D%I%E% ";CHR$ (C+156);"% %F%E%L%L% ";CHR$ (D+156)
 170 IF D=B THEN LET W=A
 180 IF D=B THEN PRINT ,"WIN $";W
 190 LET M=M+W
 200 GOSUB 280
 210 NEXT C
 220 GOSUB 290
 230 CLS 
 240 IF M>0 THEN GOTO 20
 250 PRINT AT 10,3;"GAME OVER, YOU ARE BROKE"
 260 PRINT AT 10,3;"%G%A%M%E% %O%V%E%R%,% %Y%O%U% %A%R%E% %B%R%O%K%E"
 270 GOTO 250
 280 PRINT AT 2,12;"STAKE $";M; "  "
 290 FOR N=1 TO 50
 300 NEXT N
 310 RETURN 
 320 CLEAR 
 330 SAVE "1029%2"
 340 RUN 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top