This program implements a two-team text cricket game where players deliver a ball by pressing “7” and attempt to hit it with “5” (off-side) or “8” (on-side). The difficulty level (1–3) controls the speed of the ball’s on-screen animation by varying the loop count in the FOR/NEXT delay at lines 120–122. Dismissal outcomes include being bowled (ball landing on the stumps at column B), caught behind (wrong-side shot), caught (random fielder), or dropped. The scoreboard uses a field diagram drawn with “O” and “A” characters to represent fielders, and the innings subroutine at 8505 also sets key variables M, A, and B used throughout the game.
Program Analysis
Program Structure
The program is divided into several functional blocks:
- Lines 3–27: Initialisation, key legend display, difficulty selection, and team name input.
- Lines 28–76: Innings setup — selects which team bats, prints innings header, then jumps into the main input loop.
- Lines 95–1250: Ball delivery animation loop — moves a
*up the screen, optionally deflecting it laterally at step 10. - Lines 1300–1308: Bowled dismissal handling.
- Lines 2000–2250: Fielding outcomes — caught or dropped, chosen randomly.
- Lines 3000–3035: Caught-behind dismissal.
- Lines 4500–5000: Delivery trigger — waits for key “7” before launching the ball.
- Lines 5005–6095: Shot trajectory calculation and run scoring.
- Lines 6095–8000: Scoreboard update and wicket/innings check.
- Lines 8200–8500: Innings end, next innings, and match end handling.
- Lines 8505–8620: Field-drawing subroutine and wicket-fall animation.
- Lines 8630–8680: Match result and winner announcement.
- Lines 8680–8700:
CLEAR/SAVE/RUNblock for saving the program.
Difficulty and Timing
Difficulty is selected as 1–3 and mapped to variable P at lines 15–17. P is used as the upper bound of an inner delay loop at lines 120–122: difficulty 1 gives P=3 (slow), difficulty 2 gives P=1 (medium), and difficulty 3 gives P=-1 (the FOR loop body executes zero times, giving the fastest ball). This is a concise way to scale animation speed without separate code paths.
Ball Delivery Animation
The delivery loop runs from N=1 to 20 (line 115), printing and erasing * at PRINT AT X,Y, moving X up the screen by one row each iteration. At N=10 a lateral offset Q=INT(RND*5-3) is added to Y, simulating swing or spin. At N=12 the batting window opens: pressing “5” or “8” depending on which side the ball is on routes to line 5001 (shot), while the wrong-side key routes to line 3000 (caught behind). Pressing “0” before step 12 (line 140) advances N to 13, acting as a leave/defensive shot.
Shot and Run Calculation
When a shot is played, lines 5005–5007 save the ball’s final position in C and D, then choose a random trajectory direction H (1–4) and a distance variable S (0–14). The ball is then animated in one of four diagonal directions across the field. Specific coordinate pairs at lines 6000–6015 represent fielding positions; hitting one triggers the caught/dropped subroutine at line 2000. At the end of the ball’s travel, S is mapped to runs by a series of range checks (lines 6061–6078), giving 1, 2, 3, 4, or 6 runs.
Field Drawing Subroutine
The subroutine at line 8505 draws the fielding positions using pairs of “O” (head) and “A” (body) characters at fixed PRINT AT coordinates. It also sets three variables critical to the game: M=17 (bowler column), A=5 (stumps row), and B=15 (stumps column). The stumps are drawn at line 8525 as "II" at rows A and 21. This dual role — rendering and variable initialisation — is a common space-saving idiom.
Wicket-Fall Animation
Lines 8569–8620 handle a wicket animation: the bowler figure is shown with "O"/"X" at column M, then M is decremented 17 times in a loop, walking the figure across the screen. Variables I and U are assigned inside the loop (lines 8600 and 8607) but never used for any visible effect, suggesting leftover or placeholder code. The routine ends with STOP at line 8620, which appears to be a bug — execution should return to the caller after the animation, but instead halts the program.
Bugs and Anomalies
- Line 85 vs 5001: Line 140 jumps to
GOTO 85(no-shot leave), but line 150/155 jump toGOTO 5001for a valid shot. Line 5001 does not exist; execution falls through to line 5005. This is intentional fall-through, not a bug. - Line 85 missing:
GOTO 85at line 4510 targets a non-existent line. Execution falls through to line 95, resettingK=0— effectively restarting the delivery cycle. This is a deliberate technique. - Line 860 placement:
LET TT=2at line 860 sits inside the delivery animation loop between lines 155–1200 and is reached on every delivery.TTis supposed to track the innings number, but it is set to 2 unconditionally here — meaning the second-innings flag is set on the very first delivery, breaking the innings logic at line 31. - Line 8620 STOP: The wicket-fall subroutine ends with
STOPrather thanRETURN, halting the game after every dismissal. Combined with the missingGOSUB 8555targets (line 8555 does not exist), dismissal handling is effectively broken. - Line 8650 uses
Y(1): The win calculation referencesY(1), which is undefined —T(1)was clearly intended, giving the wrong result or a variable error. - Variable
Dreused:Dis used both for difficulty (lines 13–17) and for the ball’s column position during shot animation (line 5006 onwards), causing the difficulty value to be overwritten mid-game.
Variable Summary
| Variable | Purpose |
|---|---|
D | Difficulty level (1–3); also reused as ball column in shot animation |
P | Delay loop limit (speed control) |
T(O) | Score for each team (array of 2) |
H$(O) | Team names (2×12 string array) |
W | Wickets fallen |
R | Runs scored from last shot |
Z | Runs since last wicket (partnership) |
X,Y | Ball row/column during delivery animation |
C,D | Ball row/column during shot animation |
M | Bowler/mid-wicket column |
B | Stumps column (set by subroutine at 8505) |
S | Random shot distance, mapped to runs |
TT | Innings counter (1 or 2) |
O | Current batting team index (1 or 2) |
Content
Source Code
3 LET F=1
4 LET Z=0
5 PRINT AT 0,10;"CRICKET";AT 1,10;"\~~\~~\~~\~~\~~\~~\~~"
7 PRINT AT 4,0;"7...FOR NEXT DELIVERY"
8 PRINT AT 7,0;"5...TO STRIKE BALL ON OFF-SLIDE"
9 PRINT AT 10,0;"8...TO STRIKE BALL ON ON-SIDE"
12 PRINT AT 16,0;"LEVEL OF DIFFICULTY? (1-3)"
13 INPUT D
14 IF D<1 OR D>3 THEN GOTO 12
15 IF D=1 THEN LET P=3
16 IF D=2 THEN LET P=1
17 IF D=3 THEN LET P=-1
19 DIM T(2)
20 DIM H$(2,12)
21 LET TT=1
22 FOR O=1 TO 2
23 PRINT AT 16,0;" "
25 PRINT AT 16,0;"WHICH TEAMS DO YOU WANT TO PLAY?"
26 INPUT H$(O)
27 NEXT O
28 LET O=1
31 IF TT=2 THEN LET O=2
32 PRINT AT 18,0;"INNINGS OF ";H$(O)
40 PAUSE 25
50 CLS
65 GOSUB 8505
72 LET RR=0
73 LET SS=0
74 LET W=0
75 LET R=0
76 GOTO 4500
95 LET K=0
100 LET X=19
110 LET Y=15
115 FOR N=1 TO 20
117 PRINT AT X,Y;"*"
120 FOR G=1 TO P
122 NEXT G
125 PRINT AT X,Y;" "
127 LET X=X-1
130 IF N=10 THEN LET Q=INT (RND*5-3)
135 IF N=10 THEN LET Y=Y+Q
140 IF N<>12 AND INKEY$="0" THEN LET N=13
145 IF X<=3 THEN LET X=3
150 IF N=12 AND Y<=15 AND INKEY$="5" THEN GOTO 5001
155 IF N=12 AND Y>=16 AND INKEY$="8" THEN GOTO 5001
160 IF Y<=14 AND N=12 AND INKEY$="8" THEN GOTO 3000
170 IF Y>=16 AND N=12 AND INKEY$="5" THEN GOTO 3000
860 LET TT=2
\n1200 NEXT N
\n1210 IF Y=B THEN GOTO 1300
\n1220 IF Y=B+1 THEN GOTO 1300
\n1250 GOTO 4500
\n1300 PRINT AT 13,13;"BOWLED"
\n1303 GOSUB 8555
\n1305 PRINT AT 13,13;" "
\n1308 GOTO 6095
\n2000 LET K=INT (RND*2)+1
\n2010 IF K=1 THEN GOTO 2200
\n2020 IF K=2 THEN GOTO 2050
\n2050 GOSUB 8555
\n2060 PRINT AT 13,13;"DROPPED"
\n2070 PAUSE 25
\n2080 PRINT AT 13,13;" "
\n2090 GOTO 6095
\n2200 PRINT AT 13,13;"CAUGHT"
\n2210 GOSUB 8555
\n2220 PRINT AT 13,13;" "
\n2250 GOTO 6095
\n3000 PRINT AT 3,15;"*";AT 13,0;"CAUGHT BEHIND"
\n3010 GOSUB 8555
\n3020 PRINT AT 3,15;" ";AT 13,0;" "
\n3035 GOTO 6095
\n4410 GOTO 4500
\n4500 PRINT AT 10,8;" "
\n4501 LET C$=INKEY$
\n4505 INPUT C$
\n4510 IF C$="7" THEN GOTO 85
\n4520 IF C$<>"7" THEN GOTO 4500
\n5000 GOTO 4500
\n5005 LET C=X
\n5006 LET D=Y
\n5007 LET S=INT (RND*15)
\n5008 LET H=INT (RND*4)+1
\n5015 FOR N=1 TO 9
\n5020 IF H=1 THEN GOTO 5100
\n5030 IF H=2 THEN GOTO 5110
\n5040 IF H=3 THEN GOTO 5120
\n5050 IF H=4 THEN GOTO 5130
\n5100 LET D=D-1
\n5102 LET C=C-1
\n5105 GOTO 6000
\n5110 LET D=D-1
\n5112 LET C=C+1
\n5115 GOTO 6000
\n5120 LET D=D+1
\n5122 LET C=C-1
\n5125 GOTO 6000
\n5130 LET D=D+1
\n5135 LET C=C+1
\n6000 IF C=2 AND D=9 THEN GOTO 2000
\n6005 IF C=10 AND D=10 THEN GOTO 2000
\n6010 IF C=0 AND D=20 THEN GOTO 2000
\n6015 IF C=15 AND D=22 THEN GOTO 2000
\n6040 PRINT AT C,D;"*"
\n6045 FOR Q=1 TO 3
\n6046 NEXT Q
\n6047 IF C<=0 THEN LET N=S
\n6048 IF C>=20 THEN LET N=S
\n6049 IF D<=0 THEN LET N=S
\n6050 PRINT AT C,D;" "
\n6055 GOSUB 8525
\n6060 NEXT N
\n6061 IF S>=0 AND S<=3 THEN LET R=1
\n6062 IF S>=4 AND S<=7 THEN LET R=2
\n6063 IF S>=8 AND S<=10 THEN LET R=3
\n6064 IF S>=11 AND S<=13 THEN LET R=4
\n6078 IF S>=14 THEN LET R=6
\n6082 PRINT AT 10,B;R
\n6084 PAUSE 10
\n6086 LET T(O)=T(O)+R
\n6087 LET Z=Z+R
\n6088 LET RR=T(O)
\n6095 PRINT AT 0,1;H$(O)
\n6096 PRINT AT 1,2;T(O)
\n6097 PRINT AT 2,1;"FOR"
\n6098 PRINT AT 3,2;W
\n6099 PRINT AT 10,0;"NO.";R;AT 11,3;Z
\n7000 IF W=10 THEN GOTO 8200
\n7010 GOSUB 8505
\n8000 GOTO 4500
\n8200 CLS
\n8210 PRINT AT 5,5;"ALL OUT"
\n8220 PRINT AT 7,5;H$(O);" SCORED ";T(O)
\n8222 IF O=2 THEN GOTO 8630
\n8250 PRINT AT 10,0;"PRESS ANY KEY FOR NEXT INNINGS"
\n8255 INPUT C
\n8300 CLS
\n8500 GOTO 28
\n8505 PRINT AT 1,15;"O";AT 2,15;"A";AT 0,13;"O";AT 1,13;"A"
\n8510 PRINT AT 4,27;"O";AT 5,27;"A";AT 17,7;"O";AT 18,7;"A"
\n8515 PRINT AT 5,5;"O";AT 6,5;"A";AT 20,14;"O";AT 21,14;"A"
\n8520 LET M=17
\n8521 LET A=5
\n8522 LET B=15
\n8525 PRINT AT A,B;"II";AT 21,B;"II"
\n8530 PRINT AT 7,M;"O";AT 8,M;"7";AT 8,16;"/"
\n8535 PRINT AT 2,9;"O";AT 3,9;"A";AT 10,10;"O";AT 11,10;"A"
\n8540 PRINT AT 1,11;"O";AT 2,11;"A"
\n8545 PRINT AT 0,20;"O";AT 1,20;"A";AT 15,22;"O";AT 16,22;"A"
\n8550 RETURN
\n8569 IF K=2 THEN RETURN
\n8575 LET W=W+1
\n8576 LET F=F+1
\n8577 LET Z=0
\n8578 LET SS=T(O)
\n8579 PRINT AT 11,3;" "
\n8580 FOR V=1 TO 17
\n8585 PRINT AT 7,M;"O";AT 8,M;"X"
\n8600 LET I=10
\n8605 PRINT AT 7,M;" ";AT 8,M;" "
\n8607 LET U=10
\n8610 LET M=M-1
\n8615 NEXT V
\n8620 STOP
\n8630 PAUSE 20
\n8635 CLS
\n8640 IF T(1)>T(2) THEN GOTO 8650
\n8642 IF T(1)=T(2) THEN GOTO 8672
\n8645 IF T(1)<T(2) THEN GOTO 8665
\n8650 LET U=Y(1)-T(2)
\n8655 PRINT AT 10,0;H$(1);"WINS BY ";U;" RUNS"
\n8660 STOP
\n8665 LET U=T(2)-T(1)
\n8670 PRINT AT 10,0;H$(2);"WINS BY ";U;" RUNS"
\n8671 STOP
\n8672 PRINT AT 10,0;"MATCH DRAWN"
\n8675 STOP
\n8680 CLEAR
\n8690 SAVE "1028%1"
\n8700 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
