This text adventure is a translation from "old line numbered basic". My intention was to convert it to DBpro as part of a tutorial for introduction to text adventures. It seems I have worked myself into a dilemma.
The original code was complete spaghetti. I tried to do my best in the beginning to get some organization, and convert the game to a more modern game loop. Unfortunately some of the spaghetti code followed me.
Here's the code at current.
Rem Project: Tower Of Mystery
Rem Created: 5/13/2005 9:49:14 PM
Rem ***** Main Source File *****
`============================================================================================
` I N I T I A L I Z A T I O N
`============================================================================================
Set display mode 1024, 768, 32
backdrop off
sync on
sync rate 60
ink RGB(128,255,128),0
`CONSTANTS
NUMROOMS=14
NUMTHINGS=11
NUMPOBJ=11
NUMVERBS=29
NUMOBJ=NUMTHINGS+NUMPOBJ
`Dimension Arrays
dim Access(NUMROOMS,6)
dim Verb$(NUMVERBS)
dim Object$(NUMOBJ+20)
dim RoomDesc$(NUMROOMS)
dim ItemDesc$(NUMTHINGS)
dim VerbToken(NUMVERBS)
dim ItemLoc(NUMOBJ)
dim ItemFlag(NUMTHINGS)
`Initialize Variables and flags
global cmd$
global cmd1$
global cmd2$
CurrRoom=1
CompStartTime=0
CoinFound=0
RatsTrouble=-1
CompAct=0
ManualFound=0
CompDoa=0
RdRFlag=-1
LoggedIn=0
BatsTrouble=-1
verbfound=0
`Initialize Arrays
`Roomdesc$ array
for i=1 to NUMROOMS
read RoomDesc$(i)
next i
`Verb$, VerbToken arrays
for i=1 to NUMVERBS
read Verb$(i),VerbToken(i)
next i
`Object$ array
for i=1 to NUMOBJ
read Object$(i)
next i
`ItemDesc$, ItemLoc, ItemFlag
for i=1 to NUMTHINGS
read ItemDesc$(i), ItemLoc(i), ItemFlag(i)
next i
`Access array
for i =1 to NUMROOMS
for j =1 to 6
read Access(i,j)
next j
next i
`============================================================================================
` M A I N G A M E L O O P
`============================================================================================
do
if RdRFlag=0
ink RGB(255,255,255),0
print
print "> ";
gosub Command_Input
ILoc=ItemLoc(ObjTkn)
if verbfound = 0
ink RGB(255,0,0),0
print "I don't know the verb "; cmd1$
endif
If VerbTkn<>11 and ILoc<>CurrRoom and ILoc<>0
ink RGB(255,128,0),0
print "It isn't here!"
VerbTkn=25
endif
select VerbTkn
case 1: print " ": gosub Directions: endcase
case 2: print " ": gosub Directions: endcase
case 3: print " ": gosub Directions: endcase
case 4: print " ": gosub Directions: endcase
case 5: print " ": gosub Directions: endcase
case 6: print " ": gosub Directions: endcase
case 7: print " ": gosub Go: endcase
case 8: print " ": gosub Eat: endcase
case 9: print " ": gosub Kick: endcase
case 10: print " ": gosub Insert: endcase
case 11: print " ": gosub Types: endcase
case 12: print " ": gosub Take: endcase
case 13: print " ": gosub Drop: endcase
case 14: print " ": gosub Inventory: endcase
case 15: print " ": gosub Mount: endcase
case 16: print " ": gosub Reads: endcase
case 17: print " ": gosub Fight: endcase
case 18: print " ": gosub Start: endcase
case 19: print " ": gosub Open: endcase
case 20: print " ": gosub Quit: endcase
case 21: print " ": gosub Look: endcase
case 23: print " ": gosub Wind: endcase
case 24: Print " ": gosub Examine: endcase
case 25: endcase
endselect
else
RdRFlag=0
ink RGB(255,255,128),0
print RoomDesc$(CurrRoom)
k=0
for i=1 to NUMTHINGS
if ItemLoc(i)=CurrRoom
if k=0
k=1
ink rgb(255,255,255),0
print "You See:"
print ItemDesc$(i)
endif
endif
next i
ink RGB(0,255,128),0
print "Exits Are: "
ink RGB(128,255,255),0
for i=1 to 6
if Access(CurrRoom,i)<>0 then print verb$(i);" ";
next i
print
endif
sync
loop
end
`============================================================================================
` E N D M A I N G A M E L O O P
`============================================================================================
`================== S U B R O U T I N E S =======================
Command_Input:
`***** Command INPUT/PARSER
`c2
`space
input cmd$: rem Get user input
str_length = len(cmd$):rem Find the length (str_length) of input
cmd1$="": rem Init cmd1$
cmd2$="": rem Init cmd2$
rem Initialize variables
c1=0
c2=0
v2=0
v1=0
space=0:
verbfound=0:
VerbTkn=0
ObjTkn=0
for i=1 to str_length: rem Look at each character (a$) in the users input
a$=mid$(cmd$,i): rem
a=asc(a$)
if a>=97 and a<=122
a$=chr$(a-32): rem Make everything upper-case
endif
if a$<>" ": rem If the character is not a space
if space=0: rem If we have not encounterd a space,
cmd1$=cmd1$+a$: rem Add the character to the first word.
else
cmd2$=cmd2$+a$: rem add the character to the second word
endif
endif
if a$=" "
space=1: rem We have encountered a Space
endif
next i
cmd1$=left$(cmd1$,5): rem Truncate cmd1$ to 5 characters
cmd2$=left$(cmd2$,5): rem Truncate cmd2$ to 5 characters
for v1=1 to NUMVERBS: rem Search the verb array for match with cmd1$
if Verb$(v1)=cmd1$: rem If we find a match
VerbTkn=VerbToken(v1): rem get the verbtoken and store it in VerbTkn
verbfound=1: rem A match was found
c1=v1: rem Save contentes of v1 to c1
v1=NUMVERBS: rem No need to search anymore Verb is Found!
endif
next v1
for v2=1 to NUMOBJ: rem Search the object array for match with cmd2$
if Object$(v2)=cmd2$: rem If we find a match
ObjTkn=v2: rem Store contents of v2 in ObjTkn
v2=NUMOBJ: rem No need to searvh anymore Object is Found!
endif
next v2
return
Directions:
If Access(CurrRoom,VerbTkn)=0
print "You can't go that way!"
return
endif
If CurrRoom=4 and RatsTrouble<>0 and VerbTkn=3
print "The rats look too fierce."
gosub CompleteRoutines
return
endif
CurrRoom=Access(CurrRoom,VerbTkn)
RdRFlag=-1
sync
return
Go:
if ObjTkn=0
gosub Msg6
return
endif
VerbTkn=ObjTkn-16
gosub Directions
return
Eat:
if ObjTkn<>6
gosub Msg2
return
endif
If ItemLoc(ObjTkn)=-1
print "It tastes stale."
gosub CompleteRoutines
endif
return
Kick:
if ObjTkn=0
gosub Msg6
return
endif
if ObjTkn<>7 or CompDOA<>0
gosub CompleteRoutines
return
endif
if CompAct<>0
CompStartTime=9
gosub CompleteRoutines
return
endif
print "The Computer Starts Up!"
print "The Console Displays: `Please Log In`"
CompAct=-1
gosub CompleteRoutines
return
Insert:
if ObjTkn=0
gosub Msg6
return
endif
if ObjTkn<=16
gosub Msg5
return
endif
if ObjTkn<>5
gosub Msg2
return
endif
if CurrRoom<>6
gosub Msg4
return
endif
ItemLoc(5)=-1
ItemLoc(6)=CurrRoom
ink RGB(255,255,0),0
print "A candy bar comes out"
return
Types:
return
Take:
return
Drop:
return
Inventory:
return
Mount:
return
Reads:
return
Fight:
return
Start:
return
Open:
return
Look:
RdRFlag=-1
return
Wind:
return
Examine:
return
Quit:
end
return
Msg1:
Print "Ok."
gosub CompleteRoutines
return
Msg2:
ink Rgb(255,0,0),0
print "That's silly!"
return
Msg3:
ink Rgb(255,0,0),0
print "Nothing happens."
gosub CompleteRoutines
return
Msg4:
ink rgb(255,0,0),0
print "You can't do that now."
gosub Completeroutines
return
Msg5:
ink rgb (255,0,0),0
print "Whoz your 3ngl1sh te4cha?"
return
Msg6:
ink rgb (255,0,0),0
print "Please give an object."
return
CompleteRoutines:
if CompAct=0
return
endif
inc CompStartTime
if CompStarTime>10
If CurrRoom=10
print "The Computer Dies with a loud Pop."
endif
CompDoa=-1:CompAct=0:ItemDesc$(7)="Dead Computer"
endif
if CurrRoom=ItemLoc(8)
print "A horde of bats carries you out."
CurrRoom=1
RdRFlag=-1
endif
return
`=============== D A T A S E C T I O N ===============
`Room/Area Descriptions
data "You are in the front of an old factory with a clock tower."
data "You are at the bottom of a stairwell."
data "You are at the top of the basement steps."
data "You are in a damp cellar."
data "You are in a storeroom."
data "You're in the cafeteria."
data "You're at a landing on the stairs."
data "Around you is a manufacturing area."
data "You're at a landing on the third floor."
data "You are in the computer room."
data "You are inside the clock tower."
data "You are at the top of the stairs."
data "You are in a long corridor going East."
data "You're at the East end of the corridor."
`Verb,Verbtoken data
data "N",1,"S",2,"E",3,"W",4,"U",5,"D",6,"GO",7,"EAT",8,"KICK",9,"INSER",10,"DEPOS",10,"TYPE",11
data "TAKE",12,"GET",12,"DROP",13,"THROW",13,"INVEN",14,"I",14,"MOUNT",15,"READ",16
data "FIGHT",17,"KILL",17,"START",18,"POWER",18,"OPEN",19,"QUIT",20,"LOOK",21
data "WIND",22,"EXAM",23
`Object data
data "RATS","TAPE","MACHI","TERMI","COIN","CANDY","COMPU","BATS","DESK","MANUA","CLOCK","ROAD"
data "DIR","ADVEN","COPY","LOGOU","NORTH","SOUTH","EAST","WEST","UP","DOWN"
`Item data
data "HUNGRY RATS",4,0,"COMPUTER TAPE",5,1,"VENDING MACHINE",6,0
data "BROKEN-DOWN TERMINAL",8,1,"COIN",-1,1,"CANDY BAR",-1,1,"Computer",10,0
data "BATS",13,0,"DESK",14,0,"COMPUTER MANUAL",-1,1,"ELABORATE CLOCKWORK",11,0
`Access data: Interconnections between rooms
data 2,0,0,0,0,0
data 3,1,0,0,7,0
data 0,2,0,0,0,4
data 0,0,5,0,3,0
data 0,0,0,4,0,0
data 0,0,7,0,0,0
data 0,0,8,6,9,2
data 0,0,0,7,0,0
data 0,0,10,0,12,7
data 0,0,0,9,0,0
data 0,12,0,0,0,0
data 11,0,13,0,0,9
data 0,0,14,12,0,0
data 0,0,0,13,0,0
I don't know whether I should just continue as is and finish it; And then attempt to clean it up. It's obvious that using "User Define Types" ie. roomtype; would have kept things together more. So is this code salvageable? It's hard for me to be objective because I look at it with such disgust right now.
I fear that If I start over from the beginning, I won't have the drive to finish it.
At the time I began this, I was trying to help someone who had a questions about text adventures. I thought I could save myself some time by using this old resource that I had from my days with Commodore Basic. I now realize it would have been easier for me to design it from scratch.
note:
It's suppose to serve as a basic example. My real goal is to build an adventure building program that will make creation of these type of programs easier in DBpro.
If anyone has any advice I would really appreciate it. If you got this far, thanks for even looking at this.
~zenassem