Monster Pit

Developer(s): Jim Enness
Date: 1983
Type: Program
Platform(s): TS 2068
Tags: Game

You have fallen down a 150-foot pit and must climb back out, level by level, through a maze of caves. Each cave shows three ways on, to the left, forward and right: a passageway, a door, stairs up or down, a blank wall or the exit. At a door you can listen (L) or open it (O), and then go in, ask for help or leave. Monsters such as Salamanders, Beholders, Ettins, Gargoyles and Basilisks guard gold and spells. You fight them with your hit points, cast a spell or retreat. Hazards include crumbling walls, a floor that collapses into acid or onto spikes, and a screech bat that steals your gold. S shows your status, and the final score is worked out from gold, kills, spells and hit points, with the best score kept between games.

A REM says the game was originally written for the ZX81 by Jim Enness and appeared in ZX Computing, June/July 1983. The title screen credits Jim Enness.

Program Analysis

Structure

  • Lines 300–458: set-up and the main loop. Each cave’s three exits are drawn at random into b(1..3) and their contents into the rest of b(18).
  • Lines 500–572: display helpers and the status screen.
  • Lines 600–1120: walls, the end score, the screech bat, doors, listening, cave contents, help and the floor cave-in.
  • Lines 1300–1710: monster encounters, combat, spells and retreat.
  • Lines 1750–1764: title and instructions. Line 2000 saves the game with its word table.

The word table

All the room names, directions and monster names are in a 135-element string array a$(135,10). It is not built by the program but kept in the saved variables, so the game must be loaded with them. Line 2002 also saves it on its own as a DATA file.

Notable Techniques

  • POKE 23658,8 sets caps lock, so all the key tests compare against capital letters.
  • Key waits use the pair IF INKEY$<>"" THEN GO TO n / IF INKEY$="" THEN GO TO n+1, which waits for a fresh key press.
  • GO SUB c with c set to 1500, 1600 or 1700 dispatches combat, spell or retreat.

Potential Issues

  • Line 12 pokes the second byte of UDG a with USR "a"+f+1 instead of z+1, so the divider graphic is only half a checkerboard.
  • The spell message reads “The now spell blasted”.

This program came from an Oliger (JLO SAFE) disk, a copy of the SNUG library disk 13/14, and was converted to load from tape. The SAVE / in line 2000 became a plain SAVE; the game’s word table is kept in the saved variables. It was tested in ZEsarUX through the title, the instructions, the first cave and the status screen.

Related Content

Image Gallery

Source Code

    5 REM >>  MONSTER PIT  <<                                    Originally written for the ZX81 by Jim Enness, appeared         June/July 1983   in ZX COMPUTING 
   10 POKE 23658,8: PAPER 7: INK 0: BORDER 0: CLS 
   12 FOR z=0 TO 6 STEP 2: POKE USR "a"+z,85: POKE USR "a"+f+1,170: NEXT z
   15 LET p=0
   20 GO SUB 1750
  299 REM >>Set Up<<
  300 LET c=0
  302 LET e=6
  304 LET l=20
  306 LET k=c
  308 LET h=100
  310 LET f=c
  312 LET s=10
  314 LET g=c
  316 GO TO 403
  400 REM >>Main Program<<
  401 IF f=1 THEN GO TO 426
  402 IF INT (RND*200)<5 THEN GO SUB 1000
  403 DIM b(18)
  404 IF l=1 THEN LET e=7
  405 IF l<0 OR g>150 AND s>2 AND INT (RND*100)<8 THEN GO SUB 750
  406 FOR z=1 TO 3
  408 LET b(z)=INT (RND*e)+1
  410 IF b(z)<3 THEN GO SUB 1100
  412 NEXT z
  414 IF b(1)=3 AND b(2)=3 AND b(3)=3 THEN GO TO 406
  416 CLS 
  417 GO SUB 506
  418 GO SUB 500
  420 PRINT INVERSE 1;a$(b(1));"a";a$(b(2));"a";a$(b(3))
  422 GO SUB 500
  423 GO SUB 506
  424 PRINT INVERSE 1;a$(9);"a";a$(10);"a";a$(11)
  425 GO SUB 506
  426 PRINT 
  427 LET f=0
  428 PRINT "What Direction? ";
  430 LET z=0
  431 IF INKEY$<>"" THEN GO TO 431
  432 IF INKEY$="" THEN GO TO 432
  434 LET z$=INKEY$
  435 IF z$="A" THEN GO TO 2000
  436 IF z$="L" THEN LET z=1
  438 IF z$="F" THEN LET z=2
  440 IF z$="R" THEN LET z=3
  441 IF z$="S" THEN GO SUB 550
  442 IF z<1 THEN GO TO 432
  444 PRINT z$
  446 IF b(z)=6 THEN LET l=l+1
  448 IF b(z)=5 THEN LET l=l-1
  450 IF b(z)=3 THEN GO SUB 600
  452 IF b(z)=7 THEN GO SUB 700
  454 IF b(z)=2 THEN GO SUB 800
  456 IF b(z)=1 THEN GO SUB 900
  457 IF INT (RND*100)>90 THEN GO SUB 1300
  458 GO TO 400
  499 REM >>Set Display/RND #'s<<
  502 PRINT INVERSE 1;a$(8);"a";a$(8);"a";a$(8);a$(8);"a";a$(8);"a";a$(8): RETURN 
  506 PRINT INVERSE 1;"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa": RETURN 
  510 LET r=INT (RND*101)+12
  512 RETURN 
  514 PRINT 
  516 PRINT "The cave contains ";
  518 PRINT "a";
  520 IF a$(r,1)="I" THEN PRINT "n";
  522 PRINT " ";a$(r);
  524 RETURN 
  526 FOR x=11 TO 21
  528 PRINT AT x,0,,: NEXT x
  532 PRINT AT 11,0;" ": RETURN 
  536 LET w=INT (RND*101)+12: RETURN 
  540 LET w=(INT (RND*16)+1)*2: RETURN 
  549 REM >>Status<<
  550 PRINT "STATUS",
  552 GO SUB 526
  554 PRINT "YOU HAVE KILLED ";k;" MONSTERS"
  556 PRINT : PRINT "YOU ARE ON LEVEL ";l,,,
  560 PRINT "YOU HAVE ";h;" HIT POINTS",,,
  562 PRINT "YOU HAVE ";s;" SPELLS",,,
  564 PRINT "AND YOU HAVE ";g;" GOLD PIECES ";
  566 IF INKEY$<>"" THEN GO TO 566
  567 IF INKEY$="" THEN GO TO 567
  570 GO SUB 526
  571 PRINT AT 10,16;"       ";AT 10,16;
  572 RETURN 
  599 REM >>Wall<<
  600 GO SUB 526
  602 PRINT "NO-ENTRY....WALL UNSTABLE",,,
  604 LET f=1
  606 GO SUB 536
  608 IF w>50 THEN RETURN 
  610 PRINT "IT SHAKES..ROOF CRUMBLES..ROCKS",,,"FALL..KNOCK YOU TO THE GROUND",,,"TAKE ";w;" HIT POINTS DAMAGE."
  612 LET h=h-w
  614 RETURN 
  699 REM >>End Score<<
  700 CLS 
  702 PRINT "Well Done, you got out alive!"
  704 PRINT 
  706 PRINT "You killed ";k;" monsters.",,,
  708 PRINT "You have ";g;" gold coins",,,
  710 PRINT "You scored ";g*k+s+h;" points.",,,
  712 IF p<g*k+s+h THEN LET p=g*k+s+h
  714 PRINT "Best Score so far:";p,,,,,
  716 PRINT "Another Game?"
  718 IF INKEY$<>"" THEN GO TO 718
  719 IF INKEY$="" THEN GO TO 719
  720 GO TO 300
  749 REM >>Screech Bat<<
  750 CLS 
  752 PRINT 
  754 PRINT "  A SCREECH BAT DESCENDS ON YOU ",,"KNOCKS YOU TO THE FLOOR AND",,,"TAKES ALL YOUR GOLD,GIVING YOU",,,INT (h/2);" HIT POINTS DAMAGE:BREAKING"
  756 PRINT 
  758 PRINT INT (s/2);" OF YOUR SPELLS:LEAVING YOU",,,"ON LEVEL ";l+1;"."
  759 LET g=0
  760 LET h=h-INT (h/2)
  762 LET s=s-INT (s/2)
  768 LET l=l+1
  770 PRINT 
  772 PRINT "    (Hit ENTER to continue)     "
  773 IF INKEY$<>"" THEN GO TO 773
  774 IF INKEY$="" THEN GO TO 774
  776 RETURN 
  799 REM >>Door Entry<<
  800 GO SUB 526
  801 PRINT "Door...O-Open, L-Listen ";
  802 IF INKEY$<>"" THEN GO TO 802
  804 LET z$=INKEY$: IF z$="" THEN GO TO 804
  806 IF z$="L" THEN GO TO 811
  808 IF z$="O" THEN GO TO 898
  810 GO TO 802
  811 PRINT z$,,,
  812 PRINT "You hear ";
  814 IF b(z+3)>0 THEN PRINT a$(b(z+3));"s making",,,"noises";
  816 IF b(z+3)=0 THEN PRINT "nothing.";
  818 PRINT "...Now What?",,,"G-Go in,H-Help,L-Leave ";
  820 IF INKEY$<>"" THEN GO TO 820
  822 LET z$=INKEY$: IF z$="" THEN GO TO 822
  824 IF z$="G" THEN GO TO 850
  826 IF z$="H" THEN GO TO 950
  828 IF z$="L" THEN GO TO 832
  830 GO TO 820
  832 PRINT z$;"-CHICKEN",,
  838 LET f=1
  840 IF INT (RND*100)<10 THEN GO SUB 1000
  842 RETURN 
  849 REM >>Entry Contents<<
  850 GO SUB 526
  852 PRINT AT 10,0;
  854 IF b(z+3)>0 THEN LET r=b(z+3)
  856 IF b(z+3)>0 THEN GO SUB 516: PRINT 
  858 IF b(z+3)=0 THEN PRINT "A monster-less cavern"
  860 PRINT 
  862 IF b(z+6)>0 THEN PRINT "with ";b(z+6);" ";a$(113),,,
  864 IF b(z+9)>0 THEN PRINT a$(b(z+9)+100);a$(b(z+9)+101),,,
  866 IF b(z+12)>0 THEN PRINT a$(b(z+12)+100);a$(b(z+12)+101),,,
  868 IF b(z+15)>0 THEN PRINT a$(b(z+15)+100);a$(b(z+15)+101),,,
  869 PAUSE 0
  870 IF b(z+3)>0 THEN GO SUB 1314
  871 IF b(z+3)>0 AND c=1700 THEN GO TO 838
  872 LET g=g+b(z+6)
  874 FOR x=9 TO 15 STEP 3
  876 IF b(z+x)>0 AND b(z+x)<25 THEN LET h=h+30
  878 IF b(z+x)>23 THEN LET s=s+1
  880 NEXT x
  882 RETURN 
  897 REM >>Cave Contents<<
  898 PRINT z$
  900 GO SUB 526
  902 IF b(z+3)>0 THEN LET r=b(z+3)
  904 IF b(z+3)>0 THEN GO SUB 516
  905 LET w=0
  906 FOR x=6 TO 15 STEP 3
  908 IF b(z+3)>0 AND b(z+x)>0 THEN LET w=2
  910 IF b(z+3)=0 AND b(z+x)>0 THEN LET w=1
  912 NEXT x
  914 IF w=2 THEN PRINT ,,,"and treasure";
  916 IF w=1 THEN PRINT "The cave contains treasure",,,,
  918 IF b(z+3)=0 AND w=0 THEN PRINT "The cave is empty";
  919 IF b(z+3)>0 AND w=0 THEN PRINT ,,
  920 GO TO 818
  949 REM >>Help<<
  950 PRINT z$
  951 GO SUB 526
  952 IF b(z+3)>0 THEN PRINT "The ";a$(b(z+3));" has ";b(z+3)-12;" hit points"
  954 IF b(z+3)=0 THEN PRINT "NO MONSTERS?!?"
  956 PRINT ',
  958 GO TO 818
  999 REM >>Floor Cave-In<<
 1000 GO SUB 526
 1001 LET f=0
 1002 GO SUB 536
 1004 PRINT "THE FLOOR CAVES IN AND YOU FALL",,,"DOWN A ";INT (w/2);" FOOT PIT TO LEVEL",,,
 1006 LET l=l+INT (w/12)
 1008 PRINT """";l;""" ";
 1010 GO SUB 536
 1012 IF w>95 THEN PRINT " AND INTO A POOL OF ACID",,,"TAKE ";h;" HIT POINTS DAMAGE.",,,
 1014 IF w>95 THEN LET h=0
 1016 IF w<40 THEN PRINT " AND ON TO SOME SPIKES",,,"TAKE ";INT (h/2);" HIT POINTS DAMAGE",,,
 1018 IF w<40 THEN LET h=h-INT (h/2)
 1019 PAUSE 0
 1020 RETURN 
 1099 REM >>Set Room Contents<<
 1100 FOR x=3 TO 6 STEP 3
 1102 GO SUB 536
 1104 IF w>70 THEN LET b(z+x)=w
 1106 GO SUB 536
 1108 IF b(z+x)>1 THEN LET b(z+x)=w
 1109 NEXT x
 1110 FOR x=9 TO 15 STEP 3
 1112 GO SUB 536
 1113 IF w>75 THEN LET b(z+x)=w
 1114 GO SUB 540
 1116 IF b(z+x)>0 AND w>12 THEN LET b(z+x)=12
 1117 IF b(z+x)>0 AND w<13 THEN LET b(z+x)=0
 1118 NEXT x
 1120 RETURN 
 1299 REM >>Monster Appears<<
 1300 GO SUB 526
 1302 GO SUB 510
 1304 GO SUB 518
 1306 PRINT " arrives"
 1308 PRINT 
 1310 PRINT "What Now?"
 1312 PRINT 
 1314 PRINT "C-Combat,S-SPELL CAST, R-RETREAT"
 1316 LET c=0
 1317 IF INKEY$<>"" THEN GO TO 1317
 1318 IF INKEY$="" THEN GO TO 1318
 1320 LET z$=INKEY$
 1322 IF z$="C" THEN LET c=1500
 1324 IF z$="S" THEN LET c=1600
 1326 IF z$="R" THEN LET c=1700
 1328 IF c<1 THEN GO TO 1318
 1329 PRINT z$
 1330 GO SUB c
 1332 IF c<1 THEN GO TO 1316
 1334 RETURN 
 1499 REM >>Battle Results<<
 1500 GO SUB 526
 1502 PRINT "You had a terrific battle with"
 1504 PRINT 
 1506 PRINT "the ";a$(r);
 1508 IF h<(r-12) THEN PRINT " but he killed you",,"and took all your treasure.": PAUSE 0: GO TO 710
 1512 PRINT " and you killed",,,"him."
 1513 PAUSE 0
 1514 LET k=k+1
 1516 LET h=h+12-r
 1518 RETURN 
 1520 PRINT "ER..SORRY..YOU'RE OUT OF SPELLS."
 1522 PRINT 
 1524 PRINT "Now What?"
 1526 LET c=0
 1528 RETURN 
 1599 REM >>Spell Results<<
 1600 GO SUB 526
 1602 GO SUB 536
 1604 IF s<1 THEN GO TO 1520
 1606 LET s=s-1
 1608 IF w>r THEN PRINT "The now spell blasted",,,a$(r);" lies dead on the",,,"floor."
 1610 IF w>r THEN LET k=k+1: PAUSE 0: RETURN 
 1614 PRINT "The ";a$(r);" is angry he",,,"advances...";
 1616 IF w<27 THEN PRINT ".He Attacks!........."
 1618 IF w<27 THEN GO TO 1502
 1620 PRINT "What Now?"
 1622 LET c=0
 1624 RETURN 
 1700 GO SUB 536
 1701 GO SUB 526
 1702 IF w<40 THEN PRINT "Oh..Bad Luck. He attacks!",,,
 1704 IF w<40 THEN GO TO 1502
 1706 PRINT "..CHICKEN",,,
 1708 LET f=0
 1709 LET l=l+1
 1710 RETURN 
 1749 REM >>Intro.<<
 1750 CLS 
 1751 PRINT "          MONSTER PIT",,,,,,,,"BY Jim Enness"
 1752 PAUSE 0
 1754 CLS : PRINT "You fall down a 150 foot pit",,,"that contains treasure and many",,,"hazards. The object of the game",,,
 1755 PRINT "is to make your way up the steps",,"through the maze of caves to the",,"exit. Press key 's' when asked",,,
 1756 PRINT "What Direction? Will give your",,,"STATUS-Then ant key to continue.",,
 1758 PRINT "In combat you use hit points to",,,"kill monsters-SPELL CASTING is",,,"often successful(NOT ALWAYS)."
 1759 IF INKEY$<>"" THEN GO TO 1759
 1760 IF INKEY$="" THEN GO TO 1760
 1761 CLS 
 1762 PRINT "OH..BY THE WAY, BEST OF LUCK....",,".........YOU'LL NEED IT!"
 1763 PAUSE NOT PI
 1764 RETURN 
 2000 SAVE "MONSTER P." LINE 10
 2002 SAVE "Data-M.P." DATA a$()

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