Older Version Newer Version

ChrisIverson ChrisIverson Jan 30, 2008 - "The tags hate me."

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