Hello everyone!
I've posted a couple of times before, about a few different things. Thanks for any help there with those problems. I've been fooling around with a bunch of programming (text based stuff only, so far), and I've learved a few things.
I made a small program that allows you to move around in a text based area. There aren't any real descriptions yet, but it does what is necessary. I know that there are a few things I am doing the long way, but I'm still too new to realize it. I was wondering if someone here would be willing to go through the code and tell me what I could do different/better than what i'm doing now. Any help would be greatly appreciated!
The code:
SYNC RATE 60
SYNC ON
DIM rooms$(7,8)
REMSTART This reads the text file into the proper array field.
This was, the file doesn't have to be continually read
and the array already has every room loaded. I didn't use
a function because then the array wouldn't be available to the main
loop.
REMEND
GOSUB ReadArray
location$=rooms$(1,2)
location=VAL(rooms$(1,1))
`Main loop
DO
CLS
PRINT rooms$(location,2)
`Shows the exits of the room that you are in.
GOSUB Exits
INPUT ">", command$
`For now, this changes the location according to the command.
`That will change when I develope a full fledged command function
`for different abilities and other commands, aside from directions.
location=Command(command$,location)
SYNC
LOOP
FUNCTION Command(command$,location)
`I couldn't find another way to get the rooms$(x,y) array to be globally read.
`This reads the file back into the array on this level, only one time.
`I'm sure that there has to be an easier way; I just haven't found one, yet.
IF count3=0
SET DIR "C:\Documents and Settings\Calliahs\Desktop\db\db\Text"
OPEN TO READ 1, "rooms.txt"
FOR count1=1 TO 7
FOR count2=1 TO 8
READ STRING 1, rooms$(count1,count2)
NEXT count2
NEXT count1
CLOSE FILE 1
count3=1
ENDIF
`This block of code just evaluates the command (direction) that was input
`and acts accordingly. The true variable is there so that the Error()
`function wouldn't be read every time the commands didn't match up.
IF command$="north" AND VAL(rooms$(location,3))>0
location=VAL(rooms$(location,3))
true=1
ENDIF
IF command$="south" AND VAL(rooms$(location,4))>0
location=VAL(rooms$(location,4))
true=1
ENDIF
IF command$="east" AND VAL(rooms$(location,5))>0
location=VAL(rooms$(location,5))
true=1
ENDIF
IF command$="west" AND VAL(rooms$(location,6))>0
location=VAL(rooms$(location,6))
true=1
ENDIF
IF command$="up" AND VAL(rooms$(location,7))>0
location=VAL(rooms$(location,7))
true=1
ENDIF
IF command$="down" AND VAL(rooms$(location,8))>0
location=VAL(rooms$(location,8))
true=1
ENDIF
IF true=0 THEN Error()
true=0
ENDFUNCTION location
`The error function, for if you try to run into a wall.
FUNCTION Error()
PRINT "Alas, you cannot go that way!"
WAIT 500
ENDFUNCTION
`Explained above as the label that takes care of reading the text file.
ReadArray:
SET DIR "C:\Documents and Settings\Calliahs\Desktop\db\db\Text"
OPEN TO READ 1, "rooms.txt"
FOR count1=1 TO 7
FOR count2=1 TO 8
READ STRING 1, rooms$(count1,count2)
NEXT count2
NEXT count1
CLOSE FILE 1
RETURN
`Explained above as the label that displays the exits of the room that you are in.
`It still doesn't look right. I'll figure out why tomorrow.
Exits:
TEXT 30,400,"EXITS:"
IF VAL(rooms$(location,3))>0
width=width+TEXT WIDTH(" |North| ")
TEXT (width),420,"|North|"
ENDIF
IF VAL(rooms$(location,4))>0
width=width+TEXT WIDTH(" |South| ")
TEXT (width),420,"|South|"
ENDIF
IF VAL(rooms$(location,5))>0
width=width+TEXT WIDTH(" |East| ")
TEXT (width),420,"|East|"
ENDIF
IF VAL(rooms$(location,6))>0
width=width+TEXT WIDTH(" |West| ")
TEXT (width),420,"|West|"
ENDIF
IF VAL(rooms$(location,7))>0
width=width+TEXT WIDTH(" |Up| ")
TEXT (width),420,"|Up|"
ENDIF
IF VAL(rooms$(location,8))>0
width=width+TEXT WIDTH(" |Down| ")
TEXT (width),420,"|Down|"
ENDIF
width=0
RETURN
The text file:
1
This is room number one.
2
5
3
4
6
7
2
This is room number two.
0
1
0
0
0
0
3
This is room number three.
0
0
0
1
0
0
4
This is room number four.
0
0
1
0
0
0
5
This is room number five.
1
0
0
0
0
0
6
This is room number six.
0
0
0
0
0
1
7
This is room number seven.
0
0
0
0
1
0
The text file reads like this: room number, description, north link, south link, east link, west link, up link, and down link. The array in the program takes care of sorting them into their own spots.
Thanks again,
Calliah