I made one long ago in Quickbasic and modified it to help somebody back when I programmed in Darkbasic Classic. I just updated it again for Darkbasic Pro using a few of IanMs commands. This version hardcodes the adventure to make it stand alone without external files.
The adventures "pages" are SELECT/CASE statements with multiple choice commands with new "page" numbers and the key you have to press to go to that new "page".
` Make a UDT for the command data
type CommandData
Tex as string ` Command text shown to user
Key as string ` Key user must press (must be uppercase)
Page as integer ` CASE number the command goes to
endtype
` Dimensionalize the temporary arrays
dim Tex$(99) ` 100 Lines of text
dim Command(9) as CommandData ` 10 Possible Commands
` Make Score variable global (works in functions)
global Score
` Hide the mouse
hide mouse
do
` Call the Story() function with the current page
CPage=Story(CPage)
loop
` Choose Your Own Adventure Function
`
` Tex$() holds the text for the story
` Command().Tex="20|A|(A)ttack Bear"
` The |'s are there to separate the number, letter, and actual
` text that'll be viewable to the user
` The number is the case used to select the next page to
` pick in the SELECT/CASE in this case it's "20"
` The letter after the number is the key to be pressed "A"
` Note: Using "~" represents "any key"
function Story(Page)
` Clear the text array and command array (IanMs command)
clear array Tex$()
clear array Command()
cls
` Find the newest page in the adventure
select Page
` Title
case 0
Tex$(0)="Welcome to sherwood forest, you are Robin Hood."
Command(0).Tex="1|~|Press any key to start"
` Reset Score to zero
Score=0
endcase
` Fair maiden in distress
case 1
Tex$(0)="You see a fair maiden being attacked by huge cannibal monkeys!!! "
Tex$(1)="Do you wish to help her?"
Command(0).Tex="2|Y|(Y)es"
Command(1).Tex="3|N|(N)o"
endcase
` Saving fair maiden
case 2
Tex$(0)="You charge forward and deafeat the monkeys!"
Tex$(1)="The maiden rewards you with a kiss"
Command(0).Tex="4|T|(T)ake off her clothing"
Command(1).Tex="5|R|(R)un away embarassed"
` Increase players score by 10
inc Score,10
endcase
` Not saving fair maiden
case 3
Tex$(0)="You have ignored a good deed!"
Tex$(1)="After the monkies kill her they throw rocks at you."
Tex$(2)="One of the rocks hits your head killing you instantly."
Command(0).Tex="0|R|(R)estart"
Command(1).Tex="50|Q|(Q)uit"
endcase
` Strip fair maiden
case 4
Tex$(0)="You accidently on pourpose cut the straps of her dress."
Tex$(1)="The dress falls to the ground revealing a hideous creature."
Tex$(2)="You die of fright."
Command(0).Tex="0|R|(R)estart"
Command(1).Tex="50|Q|(Q)uit"
endcase
` Embarassed
case 5
Tex$(0)="Your face turns red and run away with your hands over your eyes."
Tex$(1)="Soon you fall off a cliff to your death."
Command(0).Tex="0|R|(R)estart"
Command(1).Tex="50|Q|(Q)uit"
endcase
` Quit game
case 50
print "Thank you for playing."
print ""
` Check the score
if Score>0
print "You actually accomplished something!!"
print ""
print "Total Score: "+str$(Score)
endif
wait key
end
endcase
endselect
` Show all the text
for t=0 to array count(Tex$(0))
` Make sure there's something to actually show (to make blank lines have at least a space)
if Tex$(t)>"" then print Tex$(t)
next t
print ""
` Separate each command
for t=0 to array count(Command(0))
` Check if there's actually a command
if Command(t).Tex>""
` Split the string by |'s (IanMs command)
split string Command(t).Tex,"|"
` Grab the page number (IanMs command)
Command(t).Page=val(get split word$(1))
` Grab the key (IanMs command)
Command(t).Key=get split word$(2)
` Grab the text to be viewed (IanMs command)
Command(t).Tex=get split word$(3)
` Show the command text to the user
print Command(t).Tex
endif
next t
do
` Wait till the user presses a key
while inkey$()="":endwhile
` Make a$ equal the current key being pressed by the user
a$=inkey$()
` Change the keypress to uppercase
a$=upper$(a$)
` Check all command keys
for t=0 to array count(Command(0))
` Check for the keypress or the any key code ~
if Command(t).Key="~" or a$=Command(t).Key
` Make the page number the commands page number
Page=Command(t).Page
` Wait till the user lets go of the key
while scancode()>0:endwhile
` Leave the function with the page number
exitfunction Page
endif
next t
loop
endfunction 0
If you don't have IanMs Matrix 1 Utilities Plugin click on his signature above and download it.