LordDario,
Escuse me for my overriding, but below is code which is a very, very efficient and editable way to create text adventures. I worked on this most of the night tonight, and figured it was good show I would introduce it to you.
The first code snippet is the 'engine' of the game. The second is a 'formatted' text file, which includes grid data. Let me explain. Essentially, a text adventure can be laid out into an imaginable grid. This grid is the basis of the way I have written this program.
Save the code snippets into the same folder, saving the second snippet as
txtadventure.txt. Study the program, which is heavily commented for your convienience. Also, within it, notice the variable named
grid. This is the variable you should save into a file when the user wishes to save his current game location. The program, at its top, can be slightly changed to include code to load its value, plus values of what the character has gained throughout his journey.
Let me explain the format of the .txt file, starting from line 1 to line 9.
1.) Grid number - the program will compare this to the grid number needing to be found. Once found, the group of lines underneath it, all the way to the next grid number, will be extracted for use as the current grid data
2.) The next four lines is the text that will be displayed on the screen for that current grid. The program is setup to print as many lines of text as needed for that grid. Feel free to add more lines to this point in the text file
3.) The next four lines are the values that are filled into the direction array, referencing, in order to, north, south, east and then west. A 1 stands for 'enabled', a 0 for 'disabled', and allows the player to only travel in specific directions for that grid. In the program, if an array slot is enabled, and its corresponding arrow key is pressed(up arrow for north, down arrow for south, etc), then the grid will be changed, if so be the direction is enabled.
Program:
set display mode 800,600,32
sync on
sync rate 60
REM << array which will hold the boolean variables specifying which direction the player can currently travel
dim direction(4)
REM << set current grid number(this is the number you will load, which was previously saved on last game)
REM << debugger
if file exist("txtadventure.txt") = 0 then errormessage(1)
REM << get data for current grid
finddata(1)
REM <<<<<<<< main loop >>>>>>>>>>
repeat
REM << use arrow keys to move about grid
if direction(1) = 1 and upkey() = 1
inc grid,3
finddata(grid)
endif
if direction(2) = 1 and downkey() = 1
dec grid,3
finddata(grid)
endif
if direction(3) = 1 and rightkey() = 1
inc grid
finddata(grid)
endif
if direction(4) = 1 and leftkey() = 1
dec grid
finddata(grid)
endif
sync
until endgame = 1
end
REM <<<<<<<< functions >>>>>>>>>
REM << search out formmated data file for next grid data,print grid text to screen;fill array with direction data
function finddata(grid)
wait 500
REM << open file to read data from it
open to read 1,"txtadventure.txt"
cls
REM << read formatted data file
REM << first, match grid numbers('grid' to #number)
repeat
read string 1,string$
REM << debugger
if string$ = "/end" then errormessage(2)
REM << end this loop if the first symbol is a # sign, and the numbers proceeding it match the value in 'grid'
until asc(string$) = 35 and val(right$(string$,len(string$) - 1)) = grid
REM << extract and print lines of text to screen
repeat
read string 1,string$
REM << ascII # 58 = : character;if statement is true then print sentence without the colon
if asc(string$) = 58 then print right$(string$,len(string$) - 1)
REM << continue this loop until the first character is not a colon
until asc(string$) <> 58
REM << fill first array slot with value of current string, which should be a 0 or 1 for north
direction(1) = val(string$)
REM << use a FOR NEXT loop to extract and fill array with boolean direction values
for t = 2 to 4
read string 1,string$
direction(t) = val(string$)
next t
close file 1
sync
endfunction
REM << print specific error messages
function errormessage(num)
cls
if num = 1 then print "File Not Found!"
if num = 2 then print "Grid Not Found!"
sync
wait 3000
end
endfunction
Text file:save as
txtadventure.txt:
#1
:You are in your house.
:You smell the sweet smell of pancakes,
:because it is early in the morning.
:You can go north or east.
1
0
1
0
#2
:You are on your front porch.
:You can go north, east or west.
1
0
1
1
#3
:You are in your front yard.
:You can go north or west
1
0
0
1
#4
:You are at the west edge of the forrest
:You can go south or east
0
1
1
0
#5
:You are in the forrest.
:You hear strange noises and see a bit of light
:entering through the midst of the trees south of you.
:You can go south, east or west.
0
1
1
1
#6
:You are at the east edge of the forrest.
:You can go south or west
0
1
0
1
/end
The program is simply a game engine for this type of game. Therefore, all you have to do to make a new game or new grid, is add to or edit the .txt file. Enjoy!

+NanoBrain+