Qbasicnews.com

Full Version: Need help w/ a text game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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:
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:
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
Well, I haven't really looked through your code too deeply, but the first thing I notice that doesn't look right is this:

[syntax="qbasic"]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[/syntax]

player.X=player.X-1 should be player.Y=player.Y-1

and

player.y = player.X+1 should be player.y = player.Y+1

Lemme know if it still doesn't work.

*peace*

Meg.
that didn't fix that problem. Here's the room.dat file

Code:
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

OK, i start in 0002, go south to 0102 go west to 0101. In this room i have the passibility at "yyyy", but it will only let me go east, back out of the room, any other direction i try it says "Wall". Since i only use the term "wall" in the passibility check it has to be something with that. I'm just so confused, i don't see whats wrong.
Alright, next thing I see is that you use maxx and maxy in your loadrooms subroutine, but these variables aren't passed to this routine.

You can either pass them as arguments:

Code:
CALL NameOfSubroutine (Var1, Var2, Var3, ...)

or you can define them globally

Code:
COMMON SHARED maxx, maxy

*peace*

Meg.
I have it shared...
Code:
DIM SHARED currentroom(4, 4) AS room, maxx, maxy


so thats not the problem...that part works fine...it just when i try to go throught the loaded passibility