Need help W/ a text game

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Captain

Need help W/ a text game

Post by Captain »

OK I'm working on a text game and this is what i got. But when i play it it messes up. I use a string for a passibility. A n for not passible but a y for passible but...it isn't working right and i have no idea why. heres the existing code

Code: Select all


DECLARE SUB loadrooms () 
DECLARE SUB display () 
DECLARE SUB move () 
DECLARE SUB createroom () 
DECLARE SUB checkwalls () 
DECLARE SUB parse (line$) 

TYPE actor 
        x AS INTEGER 
        y AS INTEGER 
        hp AS INTEGER 
        maxhp AS INTEGER 
        mp AS INTEGER 
        maxmp AS INTEGER 
        att AS INTEGER 
        dfn AS INTEGER 
        expr AS INTEGER 
        lvl AS INTEGER 
        money AS INTEGER 
        weapon AS STRING * 15 
END TYPE 

TYPE object 
        title AS STRING * 15 
        description AS STRING * 50 
        equipable AS SINGLE 
        equiped AS SINGLE 
        mapnum AS INTEGER 
        location AS STRING * 4 
        owned AS SINGLE 
        attrib AS INTEGER 
        use AS STRING * 6 
        founddisc AS STRING * 25 
        hidden AS SINGLE 
END TYPE 

TYPE room 
        title AS STRING * 30 
        description AS STRING * 100 
        description2 AS STRING * 100 
        NSEW AS STRING * 4 
        nextmap AS INTEGER 
END TYPE 

DIM SHARED player AS actor 
DIM SHARED inventory(10) AS object 
DIM SHARED currentroom(4, 4) AS room, maxx, maxy 
DIM SHARED word$(9) 
DIM SHARED line$ 

CONST true = 0, false = NOT true 
SCREEN 13 

maxx = 4 
maxy = 4 
player.x = 0 
player.y = 2 

CLS 

loadrooms 

DO 

display 
LOCATE 4, 1: PRINT "                                    " 
LOCATE 4, 1: INPUT "do what?"; phrase$ 
LINE (0, 0)-(319, 199), 0, BF 
parse phrase$ 
move 

LOOP UNTIL word$(0) = "q" 

SUB checkwalls 

cant = false 

IF player.x > maxx THEN 
        player.x = player.x - 1 
        PRINT "Can't Wall" 
        EXIT SUB 
END IF 

IF player.x < 0 THEN 
        player.x = player.x + 1 
        PRINT "Can't Wall" 
        EXIT SUB 
END IF 

IF player.y > maxy THEN 
        player.x = player.x - 1 
        PRINT "Can't Wall" 
        EXIT SUB 
END IF 

IF player.y < 0 THEN 
        player.y = player.x + 1 
        PRINT "Can't Wall" 
        EXIT SUB 
END IF 

IF word$(0) = "north" THEN x = 1 
IF word$(0) = "south" THEN x = 2 
IF word$(0) = "east" THEN x = 3 
IF word$(0) = "west" THEN x = 4 


PRINT currentroom(player.x, player.y).NSEW 
DO: LOOP UNTIL INKEY$ <> "" 
IF MID$(currentroom(player.x, player.y).NSEW, x, 1) = "n" THEN 
        PRINT "Wall" 
        cant = true 
END IF 

IF word$(0) = "north" AND cant = true THEN 
        player.x = player.x + 1 
END IF 

IF word$(0) = "south" AND cant = true THEN 
        player.x = player.x - 1 
END IF 

IF word$(0) = "east" AND cant = true THEN 
        player.y = player.y - 1 
END IF 

IF word$(0) = "west" AND cant = true THEN 
        player.y = player.y + 1 
END IF 

END SUB 

SUB createroom 

FOR x = 0 TO 4 
        FOR y = 0 TO 4 
                currentroom(x, y).title = "big room" 
                currentroom(x, y).description = "X:" + STR$(x) + " Y:" + STR$(y) 
        NEXT y 
NEXT x 

END SUB 

SUB display 

LOCATE 1, 1: PRINT currentroom(player.x, player.y).title 
LOCATE 1, 2: PRINT currentroom(player.x, player.y).description 

END SUB 

SUB loadrooms 
OPEN "rooms.dat" FOR INPUT AS #1 
FOR x = 0 TO maxx 
        FOR y = 0 TO maxy 
                LINE INPUT #1, roomnumber$ 
                LINE INPUT #1, roomname$ 
                LINE INPUT #1, roomdes$ 
                LINE INPUT #1, roompass$ 
                currentroom(x, y).title = roomname$ + " " + roomnumber$ + " " + roompass$ 
                currentroom(x, y).description = roomdes$ 
                currentroom(x, y).NSEW = roompass$ 
        NEXT y 
NEXT x 

END SUB 

SUB move 

IF word$(0) = "east" THEN 
        player.y = player.y + 1 
        checkwalls 
END IF 

IF word$(0) = "west" THEN 
        player.y = player.y - 1 
        checkwalls 
END IF 

IF word$(0) = "south" THEN 
        player.x = player.x + 1 
        checkwalls 
END IF 

IF word$(0) = "north" THEN 
        player.x = player.x - 1 
        checkwalls 
END IF 

END SUB 

SUB parse (line$) 
wordnum = -1 
DO 

wordnum = wordnum + 1 
spce = INSTR(line$, " ") 
char = 0 

IF wordnum > 0 THEN 
        line$ = RIGHT$(line$, LEN(line$) - spce) 
END IF 

DO 

char = char + 1 

IF MID$(line$, char, 1) = "" THEN 
        sentenceover = 1 
        char = char - 1 
        EXIT DO 
END IF 

IF MID$(line$, char, 1) = " " THEN 
        char = char - 1 
        EXIT DO 
END IF 

LOOP 

word$(wordnum) = LCASE$(LEFT$(line$, char)) 

LOOP UNTIL sentenceover = 1 

END SUB 

 
and this is an example of the room file


Code: Select all

0101---the x,y location 
Big Room----name 
Really big---description 
ynny---passability(NSEW)
 



thanx for the help...i just don't get it

Captain Squirrely
Chaotic Harmony

Post by Chaotic Harmony »

I may be way off here, as I haven't taken a detailed look at the code, but are you accidently using player.x when you should be using player.y?

This code doesn't look right...

Code: Select all


IF player.y > maxy THEN
        player.x = player.x - 1
        PRINT "Can't Wall"
        EXIT SUB
END IF

IF player.y < 0 THEN
        player.y = player.x + 1
        PRINT "Can't Wall"
        EXIT SUB
END IF 

Like I said though, perhaps a more careful reading would give a better explaination.

Are you entering Nek's text adventure compo?
Captain

Not the problem

Post by Captain »

I saw that, but it's not the problem heres the rooms.dat file

Code: Select all

0000
Room of Silence
This room is pitch black
nynn
0001
Room of Happy Clowns
This room is full of clowns
nynn
0002
Castle Enterance
A Huge Lobby
nynn
0003
Bathroom
A Small bathroom
nynn
0004
Closet
Full of junk
nynn
0100
End of Hallway
Rooms on both sides
yyyn 
0101
Hall of Mirrors
Sould be able to into any room around you
yyyy
0102
Lobby
Can go any direction
yyyy
0103
Hallway of light
light coming through all the doors  
yyyy
0104
End of Hallway
Rooms on both sides
yyny
0200
room
empty
ynnn  
0201
room
empty
ynnn
0202
Hallway
Narrow Hallway
yynn
0203
room
empty
ynnn
0204
room
empty
ynnn
0300
Big Room
Empty
nyyn
0301
Big Room
Empty
nyyy
0302
Big Room
Empty
yyyy
0303
Big Room
Empty
nyyy
0304
Big Room
Empty
nyny
0400
Big Room
Empty
ynyn
0401
Big Room
Empty
ynyy
0402
Big Room
Empty
ynyy
0403
Big Room
Empty
ynyy
0404
Big Room
Empty
ynny

i start in 0002 go south to 0102 east to 0103. Once in that room i can go west back out of the room, but if i try any other direction i get "Wall". Since i use the warning "wall" only in the passibility( the "yyyy") I can't figure out what is wrong.

Whats this adventure text compitition?
Mitth'raaw'nuruodo

Post by Mitth'raaw'nuruodo »

Well I guess that the ovious answer to
the constest question is a No.
Um...Captian, at my first glace I couldn't
find anything wrong but I don't have a feel
for your coding techniques either yet.
So instead of a solution I will give you some debugging advice.
Sometimes just looking at the end result and the code
is just not enough to find an error. Its like a car,
If it doesn't start and the ignition doesn't start what do you do?
You take a volt tester/meter thing to see where the good(or favourable)
circuit begins and the bad begins. Same is true for variables,
What you want to do is pause the game and PRINT a key variable
from the start that will affect all variables under that.
So in this case you will start with the string inputs, set up a Variable PRINT/Pause(DO: LOOP WHILE INKEY$ = "" to pause) where
you input all of the strings from your file and see if all of that is
favourable. Then you fix it or move on to put another one where
you check the variables. Then another where you pass the variables
between the check sub, and eventually to the output itself. Where
you start to have a non-favourable variable then an error is between
that and the last "good" variable. This technique can give you a valueable
insite on what is wrong, and usually it an easy-to-miss error.
Also check your calculations.

-Mit

P.S. If anyone would like to clear my debugging technique
up, please go right a head.
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

Debugging? You could also do like professionals do it (or like the ones on the old PSX or PSone games that you can open with cheat codes) that gives you a constant read out on all the major varibles.

And what I'm getting from your case, you want to be looking into your varibles operating you barrier engine (passible, and not passible) When that's operating, look for any mistakes in varibles like Mit was on about.

I would look over for any (greater than) & (less than) in the code, you turn one backward or the wrong way the code will mess up, more so on your barriers. :wink:

Hope you solve the problem :!:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Mitth'raw'nuruodo

Post by Mitth'raw'nuruodo »

Ya Rattrapmax6 that's exactly what I ment.
Also Comments help too, ya know the REM statement,
:shock: Wait! I said it again(Another Time, Another Place for that).

But anyway, That technique was helpful to me a lot of times, but
there's no debugging software that I know of for QB so you have
to rigg it yourself. I miss C++ where at anytime you can break
the program and know what variable has what value.... :cry:

But anyway, I have a feeling that you are a good and innovative
programmer, Captin, and can rigg something up. :)

-Mit
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

Oh, sorry, bit hard to read w/o the vertical spacing. Your last post was easier 2 read tho! :wink: But in the case of doubling ideas, we leave the impression their gd ones, but If I realized what you was on, I'd have just put, hay, what Mit said.

I thought you could breakpoint QB, its in their lil debug menu, I've never used it tho, so I might be off, oh well, :)
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Mitth'raw'nuruodo

Post by Mitth'raw'nuruodo »

Thanks.

Your right it was a little harder to read, but no more. :D

Your right about the breakpoint thing, but then you couldn't
get the value of your variables, intsead use a Do:Loop inkey$ thing
and PRINT statement for the variables above it.

By the way how do you indent in this forum? :?

-Mit
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

___Like this I guess, really I don't think it was set up 4 it tho. Kinda sucks, just got to learn to live with it I guess. :wink:

I just use a vertical space. :) .. When you're typing in a code box it indents tho, if thats what you want? Cept it might look silly if you put your message in there tho, lol, :P
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Guest

Post by Guest »

Ok.

I have a quick question, I can HTML, does the typeage area when you type your message support direct HTML code?

Notice the lack of saying => "I can PROGRAM in HTML" because
I really don't consider HTML a programming language, just a
Hyper-Text Markup Language....LOL :lol: .

-Mit[/quote]
Mitth'raw'nuruodo

Post by Mitth'raw'nuruodo »

BTW, that ^ was me.

Of couse you knew that though, I think its the "-Mit"
at the end that gives it away... :D

-Mit
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

:wink: No, sorry, I'm clueless on HTMLs, maybe someone else here knows, or just try what you know in c if it works, just hit Preveiw.. :roll:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Post Reply