ChrisIverson
Jan 30, 2008
- "Code debugging."
This is actually Noble D. Bell's Text Adventure Engine, with slight modifications by me. I am posting it here for accessibility purposes.
' ********************************************************************************************************************** [[code format="vb"]]'
' * TEXT ADVENTURE ENGINE *
' * RELEASE 1.0.0 - FREEWARE *
' * BY NOBLE D. BELL(http://www.noblebell.com) ( http://www.noblebell.com ) *
' * *
' * NOTICE: *
' * You are free to use this text game engine for any use. The author, Noble D. Bell, is not responsible in any way *
' * for the use or misuse of this engine. If you do make changes or modifications to the code I require that you email *
' * me the revised code. *
'**********************************************************************************************************************
' REVISIONS:
' * February 5, 2006 - OFFICIAL RELEASE 1.0.0
' TO DO:
' * Add: LIGHT / EXTINGUISH commands for using a light source
' * Program: LEARN / CAST for magic spells
' ======================================================================================================================
' PROGRAM STARTS HERE
' ======================================================================================================================
' Every LB'er should know what this is for.
NOMAINWIN
' Setup the Window that will be used to play the game.
GOSUB [Setup.GUI]
' Setup global variables for True/False
GLOBAL TRUE,FALSE
TRUE = 1
FALSE = 0
' Setup global variables that will be used throughout the game.
' score - the current score for the player, turns - the number of turns the player has taken
' rm - the current room the player is in, maxinventory - the total number of items the player can pack
' inventorycount - the total number of items the player is carrying, OK - used as a flag
' maxhits - the max number of damage a player can take, hits - the total points of damage the player has taken
' defense - the number needed to hit a player, offense - the amount of damage a player can inflict
' gold - the amount of money the player has, maxmp - the total amount of magic the player can wield
' mp - the total amount of magic the player has left, armor$ - the type of armor the player is wearing
' weapon$ - the type of weapon the player is wielding, encounter - flag indicating a current battle
' lantern - a flag indicating if the lantern is on or off, needlight - a flag indicating if an area is dark or not
' noun - the number of the selected noun, verb - the number of the selected verb
' gametitle$ - the title of your game, gamedescription - the description of your game, crlf$ - carriage return/linefeed
GLOBAL score,turns,maxscore,rm,maxinventory,inventorycount,OK
GLOBAL maxhits,hits,defense,offense,gold,maxmp,mp,armor$,weapon$
GLOBAL encounter,lantern,needlight,noun,verb
GLOBAL gametitle$,gamedescription$,crlf$
' Special game variables and arrays
' rooms$(100) - This contains the description for each room in the game upto 100 rooms.
' roomProperties(100, 2) - Determines if the room is available for teleporting.
' exits(100,15) - This contains the visible exits in each room
' help$(100) - This contains some help or a clue for a particular room in the game.
' objects$(100) - Contains a list of objects the player can interact with in the game upto 100.
' objectproperties(100,7) - Contains a list of different properties about an object in the game.
' commands$(24) - Contains a list of commands (verbs) that are used in the game.
' objectdescriptions$(100) - Contains a list of descriptions about each object in the game.
'
' exits parameters:
' 1 - North, 2 - East, 3 - South, 4 - West, 5 - Up, 6 - Down : Holds connecting room number. Has 0 if not an exit.
' 7 - 12 are flags for each exit. (See example for use)
' 13 - 15 are not used at present time
'
' object properties parameters:
' 1 - the room location the object resides in.
' 2 - tells if the object is takeable (TRUE,FALSE)
' 3 - if the object is a monster tells how many hitpoints it has
' 4 - if the object is a monster tells how hard it is to hit it (1-20)
' 5 - if the object is a monster tells how much damage it can inflict (4,6,8,10,12,20)
' 6 - special flag
' 7 - Object is a source of Light(lantern, e.g.)
' room properties:
' 1 - Room can be teleported to. Values: 0 - Not Visited 1 - Visted, able to TP 2 - Never TP
' 2 - Room needs light
DIM rooms$(100),exits(100,15),help$(100),commands$(27)
DIM objects$(100),objectproperties(100,7),objectdescriptions$(100)
DIM roomProperties(100, 2)
' Assign the crlf$ with the ascii characters that represent a carriage return and a linefeed.
crlf$ = chr$(13)+chr$(10)
' Initialize everything and begin
GOSUB [Setup.General]
GOSUB [Setup.Rooms]
GOSUB [Setup.Objects]
GOSUB [Begin]
GOSUB [FleshRoom]
GOTO [Display]
'**********************************************************************************************************************
' * WAIT FOR THE USER TO DO SOMETHING. *
'**********************************************************************************************************************
[EventLoop]
#m.txtCommand,"" ""
#m.txtCommand,"!setfocus" "!setfocus"
Wait
'**********************************************************************************************************************
' * THE PARSER - BREAKS DOWN THE COMMAND INTO A VERB + NOUN COMBINATION. *
'**********************************************************************************************************************
[Parser]
turns = turns + 1 ' add one to the turns variable.
#m.txtCommand,"!contents? command$"; "!contents? command$"; ' get what the user typed into the command text box.
command$ = upper$(command$) ' convert what the user typed to upper case text.
verb$ ="" "" ' clear the noun and verb strings to nil.
noun$ ="" ""
verb$ = WORD$(command$,1) ' using lb's word$ get the verb part of the command and put it in verb$.
noun$ = WORD$(command$,2) ' using lb's word$ get the noun part of the command and put it in noun$.
verb = 0 ' set the verb and noun id's to 0.
noun = 0
Gosub [Parser.Verb] ' check to see if the verb the user typed is one that we understand.
Return ' return to calling module.
[Parser.Verb] ' see if the verb the user typed is one that we understand and if it is
for x = 1 to 27 ' then assign it it's action value (place in the array). if it is not then
if verb$ = commands$(x) then ' set the verb id to 0 meaning not known.
verb=x
exit for
end if
next x
if verb = 0 then ' the verb is not known so tell the user to try again.
txt$ ="I "I don't understand that command. Try saying it a different way please." please."
Return
end if
select case verb ' the verb is known so let's act on it and see what we need to do with it.
case 1 ' North
if exits(rm,1)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,1)
GOSUB [FleshRoom]
end if
else
txt$ ="You "You cannot go that direction." direction."
end if
case 2 ' East
if exits(rm,2)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,2)
GOSUB [FleshRoom]
end if
else
txt$ ="You "You cannot go that direction." direction."
end if
case 3 ' South
if exits(rm,3)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,3)
GOSUB [FleshRoom]
end if
else
txt$ ="You "You cannot go that direction." direction."
end if
case 4 ' West
if exits(rm,4)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,4)
GOSUB [FleshRoom]
end if
else
txt$ ="You "You cannot go that direction." direction."
end if
case 5 ' Up
if exits(rm,5)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,5)
GOSUB [FleshRoom]
end if
else
txt$ ="You "You cannot go that direction." direction."
end if
case 6 ' Down
if exits(rm,6)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,6)
GOSUB [FleshRoom]
end if
else
txt$ ="You "You cannot go that direction." direction."
end if
case 7 ' Save
if encounter = TRUE then
txt$ ="You "You cannot save a game during an encounter." encounter."
else
open"gamedata.dat" "gamedata.dat" for output as #1
print #1,score
print #1,turns
print #1,rm
print #1,inventorycount
print #1,hits
print #1,defense
print #1,offense
print #1,gold
print #1,mp
print #1,armor$
print #1,weapon$
for x=1 to 100
for y=1 to 7
print #1,objectproperties(x,y)
next y
next x
for x=1 to 100
for y=1 to 15
print #1,exits(x,y)
next y
next x
for x=1 to 100
for y = 1 to 2
print #1,room(x) roomProperties(x, y)
next y
next x
print #1,lantern
close #1
txt$ ="Game saved." "Game saved."
end if
case 8 ' Load
if encounter = TRUE then
txt$ ="You "You cannot load a game during an encounter." encounter."
else
dim info$(10, 10)
if fileExists(DefaultDir$,"gamedata.dat") "gamedata.dat") then
open"gamedata.dat" "gamedata.dat" for input as #1
input #1,score
input #1,turns
input #1,rm
input #1,inventorycount
input #1,hits
input #1,defense
input #1,offense
input #1,gold
input #1,mp
input #1,armor$
input #1,weapon$
for x=1 to 100
for y=1 to 7
input #1,objectproperties(x,y)
next y
next x
for x=1 to 100
for y=1 to 15
input #1,exits(x,y)
next y
next x
for x=1 to 100
for y = 1 to 2
input #1,room(x) roomProperties(x, y)
next y
next x
input #1,lantern
close #1
txt$ ="Game loaded." "Game loaded."
else
txt$ ="You "You don't have a game saved. Save one first." first."
end if
end if
case 9 ' Look
#m.txtView,"" ""
GOSUB [FleshRoom]
case 10 ' Inventory
txt$ ="You "You are carrying the following items:"+chr$(13)+chr$(10) items:"+chr$(13)+chr$(10)
tmp = 0
for x = 1 to 100
if objectproperties(x,1)=0 then
ifobjects$(x)<>"" objects$(x)<>"" then
txt$ = txt$ + objects$(x)+chr$(13)+chr$(10)
tmp = 1
end if
end if
next x
if tmp = 0 then txt$ = txt$ +"Nothing." "Nothing."
case 11 ' Score
txt$ ="Your "Your score is " " + str$(score) + " " out of " " + str$(maxscore) + " " in " " + str$(turns) + " turns."+chr$(13)+chr$(10) txt$ = txt$ + "You " turns."+chr$(13)+chr$(10)
txt$ = txt$ + "You have" " + str$(hits) + "/" "/" + str$(maxhits) + " " hit points." points." + chr$(13)+chr$(10)
txt$ = txt$ +"You "You have " " + str$(mp) + "/" "/" + str$(maxmp) + " " magic points." points." + chr$(13)+chr$(10)
txt$ = txt$ +"You "You can inflict upto " " + str$(offense) + " " points of damage."+chr$(13)+chr$(10) txt$ = txt$ + "Your damage."+chr$(13)+chr$(10)
txt$ = txt$ + "Your defense is" " + str$(defense) + "."+chr$(13)+chr$(10) txt$ = txt$ + "You "."+chr$(13)+chr$(10)
txt$ = txt$ + "You have" " + str$(gold) + " gold."+chr$(13)+chr$(10) txt$ = txt$ + "You " gold."+chr$(13)+chr$(10)
txt$ = txt$ + "You are wearing" " + armor$ + " armor."+chr$(13)+chr$(10) txt$ = txt$ + "You " armor."+chr$(13)+chr$(10)
txt$ = txt$ + "You are wielding" " + weapon$ + "." "."
case 12 ' Inspect
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)=0 or objectproperties(noun,1)=rm then
txt$ = objectdescriptions$(noun)
GOSUB [Logic]
else
txt$ ="You "You don't see that here." here."
end if
end if
case 13 ' Use
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>0 then
txt$ ="You "You don't have that." that."
else
GOSUB [Logic]
end if
end if
case 14 ' Take
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>rm then
txt$ ="You "You don't see that here." here."
return
end if
if objectproperties(noun,1)=0 then
txt$ ="You "You already have that." that."
return
end if
if objectproperties(noun,2)=FALSE then
txt$ ="You "You cannot take that." that."
return
end if
if inventorycount+1 > maxinventory then
txt$ ="You "You cannot carry that, you are too heavy." heavy."
return
end if
objectproperties(noun,1)=0
txt$ ="Taken." "Taken."
inventorycount = inventorycount + 1
end if
case 15 ' Drop
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)=0 then
objectproperties(noun,1)=rm
txt$ ="Dropped." "Dropped."
inventorycount = inventorycount - 1
else
txt$ ="You "You don't have that." that."
end if
end if
case 16 ' Fight
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)=rm then
if objectproperties(noun,3)=0 then
txt$ ="That "That is harmless. Why would you want to fight that?" that?"
else
GOSUB [Battle]
end if
else
txt$ ="You "You don't see that here." here."
end if
end if
case 17 ' Quit
GOTO [Quit]
case 18 ' Help
txt$ = help$(rm)
case 19 ' Arm
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>0 then
txt$="You txt$="You don't have that." that."
return
end if
if objects$(noun)=weapon$ then
txt$="You txt$="You are already wielding that." that."
return
end if
weapon$ = objects$(noun)
offense = objectproperties(noun,5)
txt$ ="You "You are now wielding a " " + weapon$ + "." "."
end if
case 20 ' UnArm
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>0 then
txt$="You txt$="You don't have that." that."
return
end if
if objects$(noun)<>weapon$ then
txt$="You txt$="You are not wielding that." that."
return
end if
weapon$ ="hands" "hands"
offense=4
txt$ ="You "You are now wielding " " + weapon$ + "." "."
end if
case 21 ' Wear
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>0 then
txt$="You txt$="You don't have that." that."
return
end if
if objects$(noun)=armor$ then
txt$="You txt$="You are already wearing that." that."
return
end if
armor$ = objects$(noun)
defense = objectproperties(noun,4)
txt$ ="You "You are now wearing " " + armor$ + " armor." " armor."
end if
case 22 ' Remove
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>0 then
txt$="You txt$="You don't have that." that."
return
end if
if objects$(noun)<>armor$ then
txt$="You txt$="You are not wearing that." that."
return
end if
armor$ ="Cloth" "Cloth"
defense = 9
txt$ ="You "You are now wearing " " + armor$ + " armor." " armor."
end if
case 23 ' Learn
txt$ ="Not "Not used in this adventure." adventure."
case 24 ' Cast
txt$ ="Not "Not used in this adventure." adventure."
case 25 'Teleport
GOSUB [Logic]
If OK=TRUE and TOK = TRUE then
rm = val(noun$)
gosub [FleshRoom]
Else
txt$ ="Cannot "Cannot TELEPORT there." there."
End If
case 26 'Light
GOSUB [Parser.Noun]
If objectproperties(x, 7) = 1 then
If lantern then
txt$ ="You "You already have something lit!" lit!"
Else
lantern = 1
txt$ ="You "You have lit the ";objects$(x) ";objects$(x)
End If
Else
txt$ ="That "That cannot be lit." lit."
End If
case 27 'Extinguish
GOSUB [Parser.Noun]
If objectproperties(x, 7) = 1 then
If lantern then
lantern = 0
txt$ ="The ";objects$(x);" "The ";objects$(x);" was put out." out."
Else
txt$ ="The ";objects$(x);" "The ";objects$(x);" is not lit." lit."
End If
Else
txt$ ="That "That cannot be extinguished." extinguished."
End If
End Select
Return
[Parser.Noun] ' look to see if we understand what the object or noun is that the
for x = 1 to 18 ' user entered. if we do understand it then assign it it's action
if noun$ = objects$(x) then ' id (place in the array) otherwise assign the noun id a 0 meaning
noun=x ' we did not know that object.
exit for
end if
next x
if noun = 0 then
txt$ ="I "I don't know what that is." is."
Return
end if
Return
'**********************************************************************************************************************
' * USER TAPS OK OR HITS ENTER, ACT ON THEIR COMMANDS. *
'**********************************************************************************************************************
[Okay]
GOSUB [Parser]
GOTO [Display]
'**********************************************************************************************************************
' * DISPLAY ACTION *
'**********************************************************************************************************************
[Display]
#m.txtView,"!contents? tmpTxt$"; "!contents? tmpTxt$";
#m.txtView,"" 'tmpTxt$="" ""
'tmpTxt$=""
tmpTxt$ = tmpTxt$ + chr$(13) + chr$(10)
tmpTxt$ = tmpTxt$ +"> " "> " + command$ + chr$(13) + chr$(10) + chr$(13) + chr$(10)
tmpTxt$ = tmpTxt$ + txt$ + chr$(13) + chr$(10)
if needlight = TRUE and lantern = FALSE then
tmpTxt$ ="You "You cannot see anything. It is pitch black here."+chr$(13)+chr$(10) here."+chr$(13)+chr$(10)
end if
#m.txtView,"!setfocus" "!setfocus"
#m.txtView, tmpTxt$
Call VerticalScroll hWnd(#m.txtView), _SB_BOTTOM ' Thanks Janet!!!
' Call VerticalScroll hWnd(#main.textbox), _SB_TOP
' Call VerticalScroll hWnd(#main.textbox), _SB_PAGEDOWN
' Call VerticalScroll hWnd(#main.textbox), _SB_PAGEUP
GOTO [EventLoop]
'**********************************************************************************************************************
' * DESCRIBE ROOM FOR DISPLAY ROUTINE *
'**********************************************************************************************************************
[FleshRoom]
If roomProperties(rm, 1) = 0 then roomProperties(rm, 1) = 1 ' Allows TELEPORTING
If not(lantern) AND roomProperties(rm, 2) then
txt$ ="The "The darkness is so blinding you can't see your hand in front of your face." face."
txt$ = txt$ + chr$(13) + chr$(10) +"If "If only you had a light source..." source..." + chr$(13)+chr$(10)+chr$(13)+chr$(10)
Else
txt$=rooms$(rm)+chr$(13)+chr$(10)+chr$(13)+chr$(10) ' Let the program display the room's contents and it's
End If
txt$ = txt$ +"Exits: " "Exits: " ' visible exits along with the description.
tmp = 0
if exits(rm,1)<>0 then
txt$ = txt$ +"North," "North,"
tmp=1
end if
if exits(rm,2)<>0 then
txt$ = txt$ +"East," "East,"
tmp=1
end if
if exits(rm,3)<>0 then
txt$ = txt$ +"South," "South,"
tmp=1
end if
if exits(rm,4)<>0 then
txt$ = txt$ +"West," "West,"
tmp=1
end if
if exits(rm,5)<>0 then
txt$ = txt$ +"Up," "Up,"
tmp=1
end if
if exits(rm,6)<>0 then
txt$ = txt$ +"Down," "Down,"
tmp=1
end if
ifright$(txt$,1)="," right$(txt$,1)="," then
txt$ = left$(txt$,len(txt$)-1)
end if
if tmp = 0 then txt$ = txt$ +"None" "None"
txt$ = txt$ + chr$(13)+chr$(10)+chr$(13)+chr$(10)
txt$ = txt$ +"You "You also see: " " +chr$(13)+chr$(10)
tmp = 0
for x=1 to 100
if objectproperties(x,1)=rm then
txt$ = txt$ + objects$(x)+chr$(13)+chr$(10)
tmp=1
end if
next x
if tmp = 0 thentxt$=txt$+"Nothing" txt$=txt$+"Nothing"
txt$ = txt$+chr$(13)+chr$(10)
Return
'**********************************************************************************************************************
' * QUIT THE GAME *
'**********************************************************************************************************************
[Quit]
CONFIRMgametitle$+chr$(13)+"Are gametitle$+chr$(13)+"Are you sure you really want to quit?";answer$ if answer$="no" quit?";answer$
if answer$="no" then GOTO [EventLoop]
txt$ ="Thank "Thank you for playing. I really hope that you had a wonderful and entertaining experience."+chr$(13)+chr$(10) txt$ = txt$ + "If experience."+chr$(13)+chr$(10)
txt$ = txt$ + "If you have any comments or questions then please visit my website at thefollowing"+chr$(13)+chr$(10) txt$ = txt$ + "location: http://www.noblebell.com"+chr$(13)+chr$(10)+chr$(13)+chr$(10) following"+chr$(13)+chr$(10)
txt$ = txt$ + "location: http://www.noblebell.com "+chr$(13)+chr$(10)+chr$(13)+chr$(10)
NOTICE gametitle$+chr$(13)+txt$
Close #m
END
'**********************************************************************************************************************
' * FUNCTIONS *
'**********************************************************************************************************************
' Specify the number of sides on the die and the number of times to roll and the result will be returned.
FUNCTION RollDice(sides,times)
tmp = 0
FOR x = 1 to times
tmp = tmp + int(rnd(1)*sides)+1
NEXT x
RollDice = tmp
END FUNCTION
' Checks to see if a file that is passed actually exists on the users directory path specified.
FUNCTION fileExists(path$, filename$)
files path$, filename$, info$()
fileExists = val(info$(0, 0)) 'non zero is true
END FUNCTION
' Used to scroll to the bottom of the screen in the textbox.
SUB VerticalScroll handle, ScrollAmount
Calldll #user32,"SendMessageA", "SendMessageA", _
handle as Ulong, _
_WM_VSCROLL as Long, _
ScrollAmount as Long, _
0 as Long, _
result as Long
END SUB
'**********************************************************************************************************************
' * GUI SETUP *
'**********************************************************************************************************************
[Setup.GUI]
ForegroundColor$ ="black" "black"
BackgroundColor$ ="buttonface" "buttonface"
TextboxColor$ ="white" "white"
TexteditorColor$ ="white" "white"
ComboboxColor$ ="white" "white"
ListboxColor$ ="white" "white"
WindowWidth = 792 : WindowHeight = 595
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
textbox #m.txtView, 8, 10, 768, 515
textbox #m.txtCommand, 8, 530, 672, 25
stylebits #m.btnGo, _BS_MULTILINE, 0, 0, 0
button #m.default,"GO", "GO", [Okay], UL, 688, 530, 88, 25
stylebits #m.txtView, _ES_MULTILINE or _ES_READONLY or _WS_VSCROLL, _ES_AUTOHSCROLL , 0, 0
open"TEXT ADVENTURE" "TEXT ADVENTURE" for dialog as #m
#m.txtView"!font "!font arial 11" 11"
#m.txtCommand"!font "!font arial 11 bold" bold"
#m.default"!font "!font arial 11 bold" bold"
#m"trapclose [Quit]" "trapclose [Quit]"
#m.txtCommand,"!setfocus" "!setfocus"
Return
'**********************************************************************************************************************
' * GENERAL *
'**********************************************************************************************************************
[Setup.General]
' assign starting values to certain variables
score = 0 : maxscore = 500 ' current score is 0 and the maximim score can be only 500
turns = 0 : rm = 1 ' total turns taken is 0 and the starting room location is 1
maxinventory = 10 : inventorycount = 0 ' total items that can be carried at once is 10 and they are carrying 0
maxhits = 25 ' the total number of hits you can take before you die.
hits = 25 ' you have 25 hits left before you die.
defense = 9 ' (1-20) : 20-Easy to hit, 1-Near impossible to hit, 0-Can't hit!
offense = 4 ' the amount of damage that can be caused (4,8,10,12,20)
gold = 50 ' starting about of money the player has
maxmp = 15 ' total magic points the player can spend
mp = 15 ' total magic points the player has left to spend
encounter = FALSE ' tells if the player is engaged in a battle (TRUE/FALSE)
lantern = FALSE ' tells if the player's lantern is lit or not (TRUE/FALSE)
needlight = FALSE ' tells if the room needs to have a light or not (TRUE/FALSE)
noun = 0 ' noun action id
verb = 0 ' verb action id
OK = FALSE ' flag (TRUE/FALSE)
' Using anything different from the items below they must be listed as a game object that the user can interact with.
' If the object is to be armor then you need to set the objectproperties defense parameter to the value you want.
' If the object is to be a weapon then you need to set the objectproperties damage parameter to the value you want.
armor$="CLOTH" armor$="CLOTH" ' Starting armor the player is wearing.
weapon$="HANDS" weapon$="HANDS" ' Starting weapon the player is using.
' Add the known commands to the commands$ array. Currently there are 24 known commands. The commands must be
' in UPPER case and only one word. You can add new commands by adding another element to the commands$ array
' with the command and then you will have to add the new element to the [Parser.Verb] module and also to the
' [Logic] module if needed.
commands$(1)="NORTH":commands$(2)="EAST":commands$(3)="SOUTH":commands$(4)="WEST":commands$(5)="UP":commands$(6)="DOWN" commands$(7)="SAVE":commands$(8)="LOAD":commands$(9)="LOOK":commands$(10)="INVENTORY":commands$(11)="SCORE" commands$(12)="INSPECT":commands$(13)="USE":commands$(14)="TAKE":commands$(15)="DROP":commands$(16)="FIGHT" commands$(17)="QUIT":commands$(18)="HELP":commands$(19)="ARM":commands$(20)="UNARM":commands$(21)="WEAR":commands$(22)="REMOVE" commands$(23)="LEARN":commands$(24)="CAST":commands$(25)="TELEPORT":commands$(26)="LIGHT":commands$(27)="EXTINGUISH" commands$(1)="NORTH":commands$(2)="EAST":commands$(3)="SOUTH":commands$(4)="WEST":commands$(5)="UP":commands$(6)="DOWN"
commands$(7)="SAVE":commands$(8)="LOAD":commands$(9)="LOOK":commands$(10)="INVENTORY":commands$(11)="SCORE"
commands$(12)="INSPECT":commands$(13)="USE":commands$(14)="TAKE":commands$(15)="DROP":commands$(16)="FIGHT"
commands$(17)="QUIT":commands$(18)="HELP":commands$(19)="ARM":commands$(20)="UNARM":commands$(21)="WEAR":commands$(22)="REMOVE"
commands$(23)="LEARN":commands$(24)="CAST":commands$(25)="TELEPORT":commands$(26)="LIGHT":commands$(27)="EXTINGUISH"
Return
'**********************************************************************************************************************
' * ROOM DESCRIPTIONS, EXITS, ETC. *
'**********************************************************************************************************************
[Setup.Rooms]
for x=1 to 100
help$(x) ="Try "Try working it out yourself a little longer." longer."
next x
for x=1 to 100
for y = 1 to 15
exits(x,y)=0
next y
next x
for x=1 to 100
rooms$(x)="" rooms$(x)=""
next x
rooms$(1) ="BOTTOM "BOTTOM OF MOUNTAIN"+crlf$+crlf$ MOUNTAIN"+crlf$+crlf$
rooms$(1) = rooms$(1) +"You "You are standing at the foot of what appears to be a really large mountain."+crlf$ mountain."+crlf$
rooms$(1) = rooms$(1) +"The "The rocks are to steep and slimey to climb. There is however a little winding trail"+crlf$ trail"+crlf$
rooms$(1) = rooms$(1) +"that "that appears to be leading up into the mountain. There is a heavy mist in the air." air."
rooms$(2) ="GAP "GAP IN THE PATH"+crlf$+crlf$ PATH"+crlf$+crlf$
rooms$(2) = rooms$(2) +"There "There is a small gap in the pathway here. It appears to be man-made. The air is starting"+crlf$ starting"+crlf$
rooms$(2) = rooms$(2) +"to "to become more chilled and thin. The mist from earlier has all but disapated." disapated."
rooms$(3) ="MOUNTAIN PASS"+crlf$+crlf$ "MOUNTAIN PASS"+crlf$+crlf$
rooms$(3) = rooms$(3) +"This "This is a leveled out area that looks to be a simple camp site. There is nothing useful here though." though."
rooms$(4) ="HOLE "HOLE IN MOUNTAIN SIDE"+crlf$+crlf$ SIDE"+crlf$+crlf$
rooms$(4) = rooms$(4) +"There "There is an opening inside one of the large rocks here. It appears to be large enough"+crlf$ enough"+crlf$
rooms$(4) = rooms$(4) +"for "for a person to get inside. It is aweful dark looking in there and you can hear faint"+crlf$ faint"+crlf$
rooms$(4) = rooms$(4) +"sounds "sounds of dripping water in the distance." distance."
rooms$(5) ="SPLIT "SPLIT IN THE PATH"+crlf$+crlf$ PATH"+crlf$+crlf$
rooms$(5) = rooms$(5) +"The "The cavern that you are in seems to split into two different directions here."+crlf$ here."+crlf$
rooms$(5) = rooms$(5) +"There "There is a strange wooden door on the north side of this passage and an opening"+crlf$ opening"+crlf$
rooms$(5) = rooms$(5) +"leading "leading off into darkness toward the south." south."
rooms$(6) ="LOST TOMB"+crlf$+crlf$ "LOST TOMB"+crlf$+crlf$
rooms$(6) = rooms$(6) +"This "This is an oblong chamber where someone or something burries others. Everything is a mess"+crlf$ mess"+crlf$
rooms$(6) = rooms$(6) +"and "and all the tombs are open with nothing inside. Almost as if the contents were stolen." stolen."
rooms$(7) ="WEST "WEST TOMB CHAMBER"+crlf$+crlf$ CHAMBER"+crlf$+crlf$
rooms$(7) = rooms$(7) +"This "This area of the tomb is scattered with shrouds and busted open tombs." tombs."
rooms$(8) ="EAST "EAST TOMB CHAMBER"+crlf$+crlf$ CHAMBER"+crlf$+crlf$
rooms$(8) = rooms$(8) +"This "This area of the elongated tomb is covered with busted open tombs." tombs."
rooms$(9) ="WEST "WEST OF RAVINE"+crlf$+crlf$ RAVINE"+crlf$+crlf$
rooms$(9) = rooms$(9) +"You "You are standing just to the west of a very large and deep ravine carved into the mountain"+crlf$ mountain"+crlf$
rooms$(9) = rooms$(9) +"surface. "surface. It kind of looks like this is where bad things have taken place in the past." past."
rooms$(10) ="EAST "EAST OF RAVINE"+crlf$+crlf$ RAVINE"+crlf$+crlf$
rooms$(10) = rooms$(10) +"The "The ravine is to the west of you. Things seem oddly different here. More so than normal." normal."
rooms$(11) ="BONE CHAMBER"+crlf$+crlf$ "BONE CHAMBER"+crlf$+crlf$
rooms$(11) = rooms$(11) +"The "The floor in this area is completely covered in unidentifiable bones of all shapes and sizes." sizes."
rooms$(12) ="SWIRLING POOL"+crlf$+crlf$ "SWIRLING POOL"+crlf$+crlf$
rooms$(12) = rooms$(12) +"Standing "Standing in the center of this odd and fowl-smelling pool of liquid stands a very unique"+crlf$ unique"+crlf$
rooms$(12) = rooms$(12) +"statue. "statue. There is a magical disturbance in the air. Some spells may be affected." affected."
exits(1,1) = 2
exits(2,1) = 3
exits(2,3) = 1
exits(2,2) = 4
exits(3,3) = 2
exits(4,4) = 2
exits(4,2) = 5
exits(5,4) = 4
exits(5,3) = 6
exits(5,1) = 9
exits(5,7) = 1 'locked
exits(6,1) = 5
exits(6,2) = 8
exits(6,4) = 7
exits(7,2) = 6
exits(8,4) = 6
exits(9,2) = 10
exits(9,3) = 5
exits(9,8) = 1 ' ravine
exits(10,1) = 12
exits(10,3) = 11
exits(10,4) = 9
exits(11,1) = 10
exits(12,3) = 10
roomProperties(12, 1) = 2 'Can't TP to or from room 12
roomProperties(12, 2) = 1 'Need light
Return
'**********************************************************************************************************************
' * OBJECTS, OBJECT PROPERTIES, OBJECT DESCRIPTIONS *
'**********************************************************************************************************************
[Setup.Objects]
for x = 1 to 100
objects$(x)="" objects$(x)=""
next x
objects$(1) ="ORC" "ORC"
objectproperties(1,1)=3
objectproperties(1,2)=FALSE
objectproperties(1,3)=6
objectproperties(1,4)=8
objectproperties(1,5)=4
objectdescriptions$(1) ="A "A massive frame, pig-like head, pale green. Very unfriendly looking." looking."
objects$(2) ="SKELETON" "SKELETON"
objectproperties(2,1)=6
objectproperties(2,2)=FALSE
objectproperties(2,3)=4
objectproperties(2,4)=9
objectproperties(2,5)=4
objectdescriptions$(2) ="An "An animated corpse of bones wielding a dagger." dagger."
objects$(3) ="SWORD" "SWORD"
objectproperties(3,1)=7
objectproperties(3,2)=TRUE
objectproperties(3,5)= 8
objectdescriptions$(3) ="A "A short sword made of finely crafted steel with a jewel-enlaid hilt." hilt."
objects$(4) ="ROPE" "ROPE"
objectproperties(4,1)=7
objectproperties(4,2)=TRUE
objectdescriptions$(4) ="50' "50' of coiled rope" rope"
objects$(5) ="KEY" "KEY"
objectproperties(5,1)=8
objectproperties(5,2)=TRUE
objectdescriptions$(5) ="A "A rusted-metal skeleton key. It might be used to unlock more than one door." door."
objects$(6) ="STATUE" "STATUE"
objectproperties(6,1)=12
objectproperties(6,2)=FALSE
objectdescriptions$(6) ="This "This is just a simple stone statue .. Wait! You feel funny and appear to be feeling better." better."
objects$(7) ="LANTERN" "LANTERN"
objectproperties(7, 1) = 1
objectproperties(7, 2) = TRUE
objectproperties(7, 7) = TRUE
objectdescriptions$(7) ="A "A rather old lantern, but appears to work." ' ********************************************************************************************************************** work."
'
' * GAME LOGIC BELOW *
'**********************************************************************************************************************
[Logic]
OK = TRUE
TOK = TRUE
' Once a fight starts you cannot run from it. You must finish it.
if encounter = TRUE then
if verb=1 or verb=2 or verb=3 or verb=4 or verb=5 or verb=6 then
txt$ ="You "You cannot run!" run!"
OK = FALSE
return
end if
end if
'Checks if you can TELEPORT to a room
roomnum = val(noun$)
If roomnum > 12 or roomnum < 1 then TOK = FALSE
If roomProperties(roomnum, 1) = 0 or roomProperties(roomnum, 1) = 2 then TOK = FALSE
If roomProperties(rm, 1) = 2 then TOK = FALSE
' Special things that happen in selected rooms.
select case rm
case 12
if verb = 12 and noun = 6 then
txt$ = objectdescriptions$(6)+crlf$
txt$ = txt$ +"Poof! "Poof! All your damage has been healed, and your magic restored." restored."
hits = maxhits
mp = maxmp
end if
case 5
if verb = 1 and exits(5,7)=1 then
txt$ ="That "That doorway appears to be locked or something." something."
OK=FALSE
end if
if verb = 1 and exits(5,7)=0 then
OK=TRUE
end if
if verb = 13 and noun = 5 then
exits(5,7)=0
txt$ ="The "The door has been unlocked." unlocked."
else
txt$ ="The "The door is locked." locked."
end if
case 9
if verb = 2 and exits(9,8)=1 then
txt$ ="You "You can't jump that ravine. It is too wide." wide."
OK=FALSE
end if
if verb = 2 and exits(9,8)=0 then
OK=TRUE
end if
if verb=13 and noun=4 then
txt$ ="You "You string the rope through a hole in the ceiling so that you can swing across." across."
exits(9,8)=0
else
txt$ ="You "You can't get across that way." way."
end if
end select
Return
'**********************************************************************************************************************
' * THE BATTLE ENGINE *
'**********************************************************************************************************************
[Battle]
' We are in a battle so we cannot load or save a game.
encounter = TRUE
txt$ ="" txt$ = txt$ + "You ""
txt$ = txt$ + "You attack the" " + objects$(noun) + " " using your " " + weapon$ + "..."+crlf$ "..."+crlf$
' Player attacks the monster
toHit = RollDice(20,1)
if toHit <= objectproperties(noun,4) then
toDamage = RollDice(offense,1)
txt$ = txt$ +"You "You inflict " " + str$(toDamage) + " " points of damage on the " + objects$(noun)+"."+crlf$ " + objects$(noun)+"."+crlf$
objectproperties(noun,3)=objectproperties(noun,3)-toDamage
if objectproperties(noun,3) <= 0 then
txt$ = txt$ +"You "You have slain the " " + objects$(noun)+crlf$
objectproperties(noun,1) = -1
gp = RollDice(6,1) * 10
txt$ = txt$ +"You "You have found " " + str$(gp) + " " gold coins."+crlf$+crlf$ coins."+crlf$+crlf$
gold=gold+gp
score = score + 5
encounter = FALSE
Return
end if
else
txt$ = txt$ +"You "You miss the " + objects$(noun)+"!!"+crlf$ " + objects$(noun)+"!!"+crlf$
end if
' Monster attacks the player
txt$ = txt$ +"The " "The " + objects$(noun) + " " attacks you..."+crlf$ you..."+crlf$
toHit = RollDice(20,1)
if toHit <= defense then
toDamage = RollDice(objectproperties(noun,5),1)
txt$=txt$+"The " + objects$(noun)+" txt$=txt$+"The " + objects$(noun)+" inflicts " " + str$(toDamage) + " " points of damage on you."+crlf$ you."+crlf$
hits=hits-toDamage
if hits <=0 then
txt$ = txt$ +"You "You have been slain!"+crlf$ slain!"+crlf$
close #m
end
end if
else
txt$ = txt$ +"The " "The " + objects$(noun) + ", ", misses you."+crlf$ you."+crlf$
end if
Return
'**********************************************************************************************************************
' * DISPLAY TITLE, INTRODUCTION, INSTRUCTIONS *
'**********************************************************************************************************************
[Begin]
gametitle$ ="Mysterious "Mysterious Caverns 1.00" 1.00"
gamedescription$ ="" txt$="" ""
txt$=""
txt$ = txt$ + gametitle$+crlf$
txt$ = txt$ +"By: "By: Noble D. Bell"+crlf$+crlf$ Bell"+crlf$+crlf$
txt$ = txt$ + gamedescription$+crlf$+crlf$
txt$ = txt$ +"To "To play this game you use text commands. The commands must be in the form of [verb][noun]. The"+crlf$ txt$ = txt$ + "game The"+crlf$
txt$ = txt$ + "game understands 24 different commands and quite possibly several differentnouns."+crlf$+crlf$ txt$ = txt$ + "Here nouns."+crlf$+crlf$
txt$ = txt$ + "Here are the commands that can be used in thisgame:"+crlf$+crlf$ game:"+crlf$+crlf$
for x=1 to 24
txt$=txt$+commands$(x)+"," txt$=txt$+commands$(x)+","
next x
txt$=left$(txt$,len(txt$)-1)
txt$ = txt$+crlf$+crlf$
txt$ = txt$ +"Just "Just press [ENTER] to begin." begin."
'notice gametitle$+crlf$+txt$
#m.txtView txt$
#m.txtCommand"LOOK" "LOOK"
wait
Return
' ======================================================================================================================
' PROGRAM ENDS HERE
' ======================================================================================================================
code
-
thedarkfreak Jan 27, 2008 (Chris Iverson)
' * TEXT ADVENTURE ENGINE *
' * RELEASE 1.0.0 - FREEWARE *
' * BY NOBLE D. BELL
' * *
' * NOTICE: *
' * You are free to use this text game engine for any use. The author, Noble D. Bell, is not responsible in any way *
' * for the use or misuse of this engine. If you do make changes or modifications to the code I require that you email *
' * me the revised code. *
'
' REVISIONS:
' * February 5, 2006 - OFFICIAL RELEASE 1.0.0
' TO DO:
' * Add: LIGHT / EXTINGUISH commands for using a light source
' * Program: LEARN / CAST for magic spells
' ======================================================================================================================
' PROGRAM STARTS HERE
' ======================================================================================================================
' Every LB'er should know what this is for.
NOMAINWIN
' Setup the Window that will be used to play the game.
GOSUB [Setup.GUI]
' Setup global variables for True/False
GLOBAL TRUE,FALSE
TRUE = 1
FALSE = 0
' Setup global variables that will be used throughout the game.
' score - the current score for the player, turns - the number of turns the player has taken
' rm - the current room the player is in, maxinventory - the total number of items the player can pack
' inventorycount - the total number of items the player is carrying, OK - used as a flag
' maxhits - the max number of damage a player can take, hits - the total points of damage the player has taken
' defense - the number needed to hit a player, offense - the amount of damage a player can inflict
' gold - the amount of money the player has, maxmp - the total amount of magic the player can wield
' mp - the total amount of magic the player has left, armor$ - the type of armor the player is wearing
' weapon$ - the type of weapon the player is wielding, encounter - flag indicating a current battle
' lantern - a flag indicating if the lantern is on or off, needlight - a flag indicating if an area is dark or not
' noun - the number of the selected noun, verb - the number of the selected verb
' gametitle$ - the title of your game, gamedescription - the description of your game, crlf$ - carriage return/linefeed
GLOBAL score,turns,maxscore,rm,maxinventory,inventorycount,OK
GLOBAL maxhits,hits,defense,offense,gold,maxmp,mp,armor$,weapon$
GLOBAL encounter,lantern,needlight,noun,verb
GLOBAL gametitle$,gamedescription$,crlf$
' Special game variables and arrays
' rooms$(100) - This contains the description for each room in the game upto 100 rooms.
' roomProperties(100, 2) - Determines if the room is available for teleporting.
' exits(100,15) - This contains the visible exits in each room
' help$(100) - This contains some help or a clue for a particular room in the game.
' objects$(100) - Contains a list of objects the player can interact with in the game upto 100.
' objectproperties(100,7) - Contains a list of different properties about an object in the game.
' commands$(24) - Contains a list of commands (verbs) that are used in the game.
' objectdescriptions$(100) - Contains a list of descriptions about each object in the game.
'
' exits parameters:
' 1 - North, 2 - East, 3 - South, 4 - West, 5 - Up, 6 - Down : Holds connecting room number. Has 0 if not an exit.
' 7 - 12 are flags for each exit. (See example for use)
' 13 - 15 are not used at present time
'
' object properties parameters:
' 1 - the room location the object resides in.
' 2 - tells if the object is takeable (TRUE,FALSE)
' 3 - if the object is a monster tells how many hitpoints it has
' 4 - if the object is a monster tells how hard it is to hit it (1-20)
' 5 - if the object is a monster tells how much damage it can inflict (4,6,8,10,12,20)
' 6 - special flag
' 7 - Object is a source of Light(lantern, e.g.)
' room properties:
' 1 - Room can be teleported to. Values: 0 - Not Visited 1 - Visted, able to TP 2 - Never TP
' 2 - Room needs light
DIM rooms$(100),exits(100,15),help$(100),commands$(27)
DIM objects$(100),objectproperties(100,7),objectdescriptions$(100)
DIM roomProperties(100, 2)
' Assign the crlf$ with the ascii characters that represent a carriage return and a linefeed.
crlf$ = chr$(13)+chr$(10)
' Initialize everything and begin
GOSUB [Setup.General]
GOSUB [Setup.Rooms]
GOSUB [Setup.Objects]
GOSUB [Begin]
GOSUB [FleshRoom]
GOTO [Display]
'
' * WAIT FOR THE USER TO DO SOMETHING. *
'
[EventLoop]
#m.txtCommand,
#m.txtCommand,
Wait
'
' * THE PARSER - BREAKS DOWN THE COMMAND INTO A VERB + NOUN COMBINATION. *
'
[Parser]
turns = turns + 1 ' add one to the turns variable.
#m.txtCommand,
command$ = upper$(command$) ' convert what the user typed to upper case text.
verb$ =
noun$ =
verb$ = WORD$(command$,1) ' using lb's word$ get the verb part of the command and put it in verb$.
noun$ = WORD$(command$,2) ' using lb's word$ get the noun part of the command and put it in noun$.
verb = 0 ' set the verb and noun id's to 0.
noun = 0
Gosub [Parser.Verb] ' check to see if the verb the user typed is one that we understand.
Return ' return to calling module.
[Parser.Verb] ' see if the verb the user typed is one that we understand and if it is
for x = 1 to 27 ' then assign it it's action value (place in the array). if it is not then
if verb$ = commands$(x) then ' set the verb id to 0 meaning not known.
verb=x
exit for
end if
next x
if verb = 0 then ' the verb is not known so tell the user to try again.
txt$ =
Return
end if
select case verb ' the verb is known so let's act on it and see what we need to do with it.
case 1 ' North
if exits(rm,1)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,1)
GOSUB [FleshRoom]
end if
else
txt$ =
end if
case 2 ' East
if exits(rm,2)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,2)
GOSUB [FleshRoom]
end if
else
txt$ =
end if
case 3 ' South
if exits(rm,3)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,3)
GOSUB [FleshRoom]
end if
else
txt$ =
end if
case 4 ' West
if exits(rm,4)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,4)
GOSUB [FleshRoom]
end if
else
txt$ =
end if
case 5 ' Up
if exits(rm,5)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,5)
GOSUB [FleshRoom]
end if
else
txt$ =
end if
case 6 ' Down
if exits(rm,6)<>0 then
GOSUB [Logic]
if OK=TRUE then
rm=exits(rm,6)
GOSUB [FleshRoom]
end if
else
txt$ =
end if
case 7 ' Save
if encounter = TRUE then
txt$ =
else
open
print #1,score
print #1,turns
print #1,rm
print #1,inventorycount
print #1,hits
print #1,defense
print #1,offense
print #1,gold
print #1,mp
print #1,armor$
print #1,weapon$
for x=1 to 100
for y=1 to 7
print #1,objectproperties(x,y)
next y
next x
for x=1 to 100
for y=1 to 15
print #1,exits(x,y)
next y
next x
for x=1 to 100
for y = 1 to 2
print #1,
next y
next x
print #1,lantern
close #1
txt$ =
end if
case 8 ' Load
if encounter = TRUE then
txt$ =
else
dim info$(10, 10)
if fileExists(DefaultDir$,
open
input #1,score
input #1,turns
input #1,rm
input #1,inventorycount
input #1,hits
input #1,defense
input #1,offense
input #1,gold
input #1,mp
input #1,armor$
input #1,weapon$
for x=1 to 100
for y=1 to 7
input #1,objectproperties(x,y)
next y
next x
for x=1 to 100
for y=1 to 15
input #1,exits(x,y)
next y
next x
for x=1 to 100
for y = 1 to 2
input #1,
next y
next x
input #1,lantern
close #1
txt$ =
else
txt$ =
end if
end if
case 9 ' Look
#m.txtView,
GOSUB [FleshRoom]
case 10 ' Inventory
txt$ =
tmp = 0
for x = 1 to 100
if objectproperties(x,1)=0 then
if
txt$ = txt$ + objects$(x)+chr$(13)+chr$(10)
tmp = 1
end if
end if
next x
if tmp = 0 then txt$ = txt$ +
case 11 ' Score
txt$ =
txt$ = txt$ + "You have
txt$ = txt$ +
txt$ = txt$ +
txt$ = txt$ + "Your defense is
txt$ = txt$ + "You have
txt$ = txt$ + "You are wearing
txt$ = txt$ + "You are wielding
case 12 ' Inspect
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)=0 or objectproperties(noun,1)=rm then
txt$ = objectdescriptions$(noun)
GOSUB [Logic]
else
txt$ =
end if
end if
case 13 ' Use
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>0 then
txt$ =
else
GOSUB [Logic]
end if
end if
case 14 ' Take
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>rm then
txt$ =
return
end if
if objectproperties(noun,1)=0 then
txt$ =
return
end if
if objectproperties(noun,2)=FALSE then
txt$ =
return
end if
if inventorycount+1 > maxinventory then
txt$ =
return
end if
objectproperties(noun,1)=0
txt$ =
inventorycount = inventorycount + 1
end if
case 15 ' Drop
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)=0 then
objectproperties(noun,1)=rm
txt$ =
inventorycount = inventorycount - 1
else
txt$ =
end if
end if
case 16 ' Fight
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)=rm then
if objectproperties(noun,3)=0 then
txt$ =
else
GOSUB [Battle]
end if
else
txt$ =
end if
end if
case 17 ' Quit
GOTO [Quit]
case 18 ' Help
txt$ = help$(rm)
case 19 ' Arm
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>0 then
return
end if
if objects$(noun)=weapon$ then
return
end if
weapon$ = objects$(noun)
offense = objectproperties(noun,5)
txt$ =
end if
case 20 ' UnArm
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>0 then
return
end if
if objects$(noun)<>weapon$ then
return
end if
weapon$ =
offense=4
txt$ =
end if
case 21 ' Wear
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>0 then
return
end if
if objects$(noun)=armor$ then
return
end if
armor$ = objects$(noun)
defense = objectproperties(noun,4)
txt$ =
end if
case 22 ' Remove
GOSUB [Parser.Noun]
if noun <> 0 then
if objectproperties(noun,1)<>0 then
return
end if
if objects$(noun)<>armor$ then
return
end if
armor$ =
defense = 9
txt$ =
end if
case 23 ' Learn
txt$ =
case 24 ' Cast
txt$ =
case 25 'Teleport
GOSUB [Logic]
If OK=TRUE and TOK = TRUE then
rm = val(noun$)
gosub [FleshRoom]
Else
txt$ =
End If
case 26 'Light
GOSUB [Parser.Noun]
If objectproperties(x, 7) = 1 then
If lantern then
txt$ =
Else
lantern = 1
txt$ =
End If
Else
txt$ =
End If
case 27 'Extinguish
GOSUB [Parser.Noun]
If objectproperties(x, 7) = 1 then
If lantern then
lantern = 0
txt$ =
Else
txt$ =
End If
Else
txt$ =
End If
End Select
Return
[Parser.Noun] ' look to see if we understand what the object or noun is that the
for x = 1 to 18 ' user entered. if we do understand it then assign it it's action
if noun$ = objects$(x) then ' id (place in the array) otherwise assign the noun id a 0 meaning
noun=x ' we did not know that object.
exit for
end if
next x
if noun = 0 then
txt$ =
Return
end if
Return
'
' * USER TAPS OK OR HITS ENTER, ACT ON THEIR COMMANDS. *
'
[Okay]
GOSUB [Parser]
GOTO [Display]
'
' * DISPLAY ACTION *
'
[Display]
#m.txtView,
#m.txtView,
'tmpTxt$=""
tmpTxt$ = tmpTxt$ + chr$(13) + chr$(10)
tmpTxt$ = tmpTxt$ +
tmpTxt$ = tmpTxt$ + txt$ + chr$(13) + chr$(10)
if needlight = TRUE and lantern = FALSE then
tmpTxt$ =
end if
#m.txtView,
#m.txtView, tmpTxt$
Call VerticalScroll hWnd(#m.txtView), _SB_BOTTOM ' Thanks Janet!!!
' Call VerticalScroll hWnd(#main.textbox), _SB_TOP
' Call VerticalScroll hWnd(#main.textbox), _SB_PAGEDOWN
' Call VerticalScroll hWnd(#main.textbox), _SB_PAGEUP
GOTO [EventLoop]
'
' * DESCRIBE ROOM FOR DISPLAY ROUTINE *
'
[FleshRoom]
If roomProperties(rm, 1) = 0 then roomProperties(rm, 1) = 1 ' Allows TELEPORTING
If not(lantern) AND roomProperties(rm, 2) then
txt$ =
txt$ = txt$ + chr$(13) + chr$(10) +
Else
txt$=rooms$(rm)+chr$(13)+chr$(10)+chr$(13)+chr$(10) ' Let the program display the room's contents and it's
End If
txt$ = txt$ +
tmp = 0
if exits(rm,1)<>0 then
txt$ = txt$ +
tmp=1
end if
if exits(rm,2)<>0 then
txt$ = txt$ +
tmp=1
end if
if exits(rm,3)<>0 then
txt$ = txt$ +
tmp=1
end if
if exits(rm,4)<>0 then
txt$ = txt$ +
tmp=1
end if
if exits(rm,5)<>0 then
txt$ = txt$ +
tmp=1
end if
if exits(rm,6)<>0 then
txt$ = txt$ +
tmp=1
end if
if
txt$ = left$(txt$,len(txt$)-1)
end if
if tmp = 0 then txt$ = txt$ +
txt$ = txt$ + chr$(13)+chr$(10)+chr$(13)+chr$(10)
txt$ = txt$ +
tmp = 0
for x=1 to 100
if objectproperties(x,1)=rm then
txt$ = txt$ + objects$(x)+chr$(13)+chr$(10)
tmp=1
end if
next x
if tmp = 0 then
txt$ = txt$+chr$(13)+chr$(10)
Return
'
' * QUIT THE GAME *
'
[Quit]
CONFIRM
if answer$="no" then GOTO [EventLoop]
txt$ =
txt$ = txt$ + "If you have any comments or questions then please visit my website at the
txt$ = txt$ + "location: http://www.noblebell.com "+chr$(13)+chr$(10)+chr$(13)+chr$(10)
NOTICE gametitle$+chr$(13)+txt$
Close #m
END
'
' * FUNCTIONS *
'
' Specify the number of sides on the die and the number of times to roll and the result will be returned.
FUNCTION RollDice(sides,times)
tmp = 0
FOR x = 1 to times
tmp = tmp + int(rnd(1)*sides)+1
NEXT x
RollDice = tmp
END FUNCTION
' Checks to see if a file that is passed actually exists on the users directory path specified.
FUNCTION fileExists(path$, filename$)
files path$, filename$, info$()
fileExists = val(info$(0, 0)) 'non zero is true
END FUNCTION
' Used to scroll to the bottom of the screen in the textbox.
SUB VerticalScroll handle, ScrollAmount
Calldll #user32,
handle as Ulong, _
_WM_VSCROLL as Long, _
ScrollAmount as Long, _
0 as Long, _
result as Long
END SUB
'
' * GUI SETUP *
'
[Setup.GUI]
ForegroundColor$ =
BackgroundColor$ =
TextboxColor$ =
TexteditorColor$ =
ComboboxColor$ =
ListboxColor$ =
WindowWidth = 792 : WindowHeight = 595
UpperLeftX=int((DisplayWidth-WindowWidth)/2)
UpperLeftY=int((DisplayHeight-WindowHeight)/2)
textbox #m.txtView, 8, 10, 768, 515
textbox #m.txtCommand, 8, 530, 672, 25
stylebits #m.btnGo, _BS_MULTILINE, 0, 0, 0
button #m.default,
stylebits #m.txtView, _ES_MULTILINE or _ES_READONLY or _WS_VSCROLL, _ES_AUTOHSCROLL , 0, 0
open
#m.txtView
#m.txtCommand
#m.default
#m
#m.txtCommand,
Return
'
' * GENERAL *
'
[Setup.General]
' assign starting values to certain variables
score = 0 : maxscore = 500 ' current score is 0 and the maximim score can be only 500
turns = 0 : rm = 1 ' total turns taken is 0 and the starting room location is 1
maxinventory = 10 : inventorycount = 0 ' total items that can be carried at once is 10 and they are carrying 0
maxhits = 25 ' the total number of hits you can take before you die.
hits = 25 ' you have 25 hits left before you die.
defense = 9 ' (1-20) : 20-Easy to hit, 1-Near impossible to hit, 0-Can't hit!
offense = 4 ' the amount of damage that can be caused (4,8,10,12,20)
gold = 50 ' starting about of money the player has
maxmp = 15 ' total magic points the player can spend
mp = 15 ' total magic points the player has left to spend
encounter = FALSE ' tells if the player is engaged in a battle (TRUE/FALSE)
lantern = FALSE ' tells if the player's lantern is lit or not (TRUE/FALSE)
needlight = FALSE ' tells if the room needs to have a light or not (TRUE/FALSE)
noun = 0 ' noun action id
verb = 0 ' verb action id
OK = FALSE ' flag (TRUE/FALSE)
' Using anything different from the items below they must be listed as a game object that the user can interact with.
' If the object is to be armor then you need to set the objectproperties defense parameter to the value you want.
' If the object is to be a weapon then you need to set the objectproperties damage parameter to the value you want.
' Add the known commands to the commands$ array. Currently there are 24 known commands. The commands must be
' in UPPER case and only one word. You can add new commands by adding another element to the commands$ array
' with the command and then you will have to add the new element to the [Parser.Verb] module and also to the
' [Logic] module if needed.
commands$(7)="SAVE":commands$(8)="LOAD":commands$(9)="LOOK":commands$(10)="INVENTORY":commands$(11)="SCORE"
commands$(12)="INSPECT":commands$(13)="USE":commands$(14)="TAKE":commands$(15)="DROP":commands$(16)="FIGHT"
commands$(17)="QUIT":commands$(18)="HELP":commands$(19)="ARM":commands$(20)="UNARM":commands$(21)="WEAR":commands$(22)="REMOVE"
commands$(23)="LEARN":commands$(24)="CAST":commands$(25)="TELEPORT":commands$(26)="LIGHT":commands$(27)="EXTINGUISH"
Return
'
' * ROOM DESCRIPTIONS, EXITS, ETC. *
'
[Setup.Rooms]
for x=1 to 100
help$(x) =
next x
for x=1 to 100
for y = 1 to 15
exits(x,y)=0
next y
next x
for x=1 to 100
next x
rooms$(1) =
rooms$(1) = rooms$(1) +
rooms$(1) = rooms$(1) +
rooms$(1) = rooms$(1) +
rooms$(2) =
rooms$(2) = rooms$(2) +
rooms$(2) = rooms$(2) +
rooms$(3) =
rooms$(3) = rooms$(3) +
rooms$(4) =
rooms$(4) = rooms$(4) +
rooms$(4) = rooms$(4) +
rooms$(4) = rooms$(4) +
rooms$(5) =
rooms$(5) = rooms$(5) +
rooms$(5) = rooms$(5) +
rooms$(5) = rooms$(5) +
rooms$(6) =
rooms$(6) = rooms$(6) +
rooms$(6) = rooms$(6) +
rooms$(7) =
rooms$(7) = rooms$(7) +
rooms$(8) =
rooms$(8) = rooms$(8) +
rooms$(9) =
rooms$(9) = rooms$(9) +
rooms$(9) = rooms$(9) +
rooms$(10) =
rooms$(10) = rooms$(10) +
rooms$(11) =
rooms$(11) = rooms$(11) +
rooms$(12) =
rooms$(12) = rooms$(12) +
rooms$(12) = rooms$(12) +
exits(1,1) = 2
exits(2,1) = 3
exits(2,3) = 1
exits(2,2) = 4
exits(3,3) = 2
exits(4,4) = 2
exits(4,2) = 5
exits(5,4) = 4
exits(5,3) = 6
exits(5,1) = 9
exits(5,7) = 1 'locked
exits(6,1) = 5
exits(6,2) = 8
exits(6,4) = 7
exits(7,2) = 6
exits(8,4) = 6
exits(9,2) = 10
exits(9,3) = 5
exits(9,8) = 1 ' ravine
exits(10,1) = 12
exits(10,3) = 11
exits(10,4) = 9
exits(11,1) = 10
exits(12,3) = 10
roomProperties(12, 1) = 2 'Can't TP to or from room 12
roomProperties(12, 2) = 1 'Need light
Return
'
' * OBJECTS, OBJECT PROPERTIES, OBJECT DESCRIPTIONS *
'
[Setup.Objects]
for x = 1 to 100
next x
objects$(1) =
objectproperties(1,1)=3
objectproperties(1,2)=FALSE
objectproperties(1,3)=6
objectproperties(1,4)=8
objectproperties(1,5)=4
objectdescriptions$(1) =
objects$(2) =
objectproperties(2,1)=6
objectproperties(2,2)=FALSE
objectproperties(2,3)=4
objectproperties(2,4)=9
objectproperties(2,5)=4
objectdescriptions$(2) =
objects$(3) =
objectproperties(3,1)=7
objectproperties(3,2)=TRUE
objectproperties(3,5)= 8
objectdescriptions$(3) =
objects$(4) =
objectproperties(4,1)=7
objectproperties(4,2)=TRUE
objectdescriptions$(4) =
objects$(5) =
objectproperties(5,1)=8
objectproperties(5,2)=TRUE
objectdescriptions$(5) =
objects$(6) =
objectproperties(6,1)=12
objectproperties(6,2)=FALSE
objectdescriptions$(6) =
objects$(7) =
objectproperties(7, 1) = 1
objectproperties(7, 2) = TRUE
objectproperties(7, 7) = TRUE
objectdescriptions$(7) =
'
' * GAME LOGIC BELOW *
'
[Logic]
OK = TRUE
TOK = TRUE
' Once a fight starts you cannot run from it. You must finish it.
if encounter = TRUE then
if verb=1 or verb=2 or verb=3 or verb=4 or verb=5 or verb=6 then
txt$ =
OK = FALSE
return
end if
end if
'Checks if you can TELEPORT to a room
roomnum = val(noun$)
If roomnum > 12 or roomnum < 1 then TOK = FALSE
If roomProperties(roomnum, 1) = 0 or roomProperties(roomnum, 1) = 2 then TOK = FALSE
If roomProperties(rm, 1) = 2 then TOK = FALSE
' Special things that happen in selected rooms.
select case rm
case 12
if verb = 12 and noun = 6 then
txt$ = objectdescriptions$(6)+crlf$
txt$ = txt$ +
hits = maxhits
mp = maxmp
end if
case 5
if verb = 1 and exits(5,7)=1 then
txt$ =
OK=FALSE
end if
if verb = 1 and exits(5,7)=0 then
OK=TRUE
end if
if verb = 13 and noun = 5 then
exits(5,7)=0
txt$ =
else
txt$ =
end if
case 9
if verb = 2 and exits(9,8)=1 then
txt$ =
OK=FALSE
end if
if verb = 2 and exits(9,8)=0 then
OK=TRUE
end if
if verb=13 and noun=4 then
txt$ =
exits(9,8)=0
else
txt$ =
end if
end select
Return
'
' * THE BATTLE ENGINE *
'
[Battle]
' We are in a battle so we cannot load or save a game.
encounter = TRUE
txt$ =
txt$ = txt$ + "You attack the
' Player attacks the monster
toHit = RollDice(20,1)
if toHit <= objectproperties(noun,4) then
toDamage = RollDice(offense,1)
txt$ = txt$ +
objectproperties(noun,3)=objectproperties(noun,3)-toDamage
if objectproperties(noun,3) <= 0 then
txt$ = txt$ +
objectproperties(noun,1) = -1
gp = RollDice(6,1) * 10
txt$ = txt$ +
gold=gold+gp
score = score + 5
encounter = FALSE
Return
end if
else
txt$ = txt$ +
end if
' Monster attacks the player
txt$ = txt$ +
toHit = RollDice(20,1)
if toHit <= defense then
toDamage = RollDice(objectproperties(noun,5),1)
hits=hits-toDamage
if hits <=0 then
txt$ = txt$ +
close #m
end
end if
else
txt$ = txt$ +
end if
Return
'
' * DISPLAY TITLE, INTRODUCTION, INSTRUCTIONS *
'
[Begin]
gametitle$ =
gamedescription$ =
txt$=""
txt$ = txt$ + gametitle$+crlf$
txt$ = txt$ +
txt$ = txt$ + gamedescription$+crlf$+crlf$
txt$ = txt$ +
txt$ = txt$ + "game understands 24 different commands and quite possibly several different
txt$ = txt$ + "Here are the commands that can be used in this
for x=1 to 24
next x
txt$=left$(txt$,len(txt$)-1)
txt$ = txt$+crlf$+crlf$
txt$ = txt$ +
'notice gametitle$+crlf$+txt$
#m.txtView txt$
#m.txtCommand
wait
Return
' ======================================================================================================================
' PROGRAM ENDS HERE
' ======================================================================================================================
code
-