Jump to content
IGNORED

Help Programming Text Adventure in BASIC


bluejay

Recommended Posts

Update: Thought again, about what I wrote earlier.

Found a way to store adventure game locations in a 2D array. Here in Python:


#!/usr/bin/python
# coding: utf-8

directions = ("n", "e", "s", "w")

locations = ((2, 0, 0, 0),
             (0, 3, 1, 0),
             (4, 0, 0, 2),
             (0, 0, 3, 0))

rooms = ("cave", "hall", "pit", "lake")

roomnumber = 1

while True:
    u = raw_input("You are in a " + rooms[roomnumber - 1] + ": ")
    if u == "q":
        print "Bye."
        break
    if u in directions:
        newroom = locations[roomnumber-1][directions.index(u)]
        if newroom == 0:
            print "Can't go there."
        else:
            roomnumber = newroom

That's actually something, that  could help the OP with an adventure game on an 8 bit machine.

Edited by Pokeypy
Link to comment
Share on other sites

Could finally make some sense of that gibberish (do you say that? :) )

#!/usr/bin/python
# coding: utf-8

locationnr = 1
chest_open = False
item       = None

texts = ("Cannot do", "You walk", "Opened", "Closed", "a sword", "a key",
         "Nothing", "a chest", "a dragon", "a corpse", "taken", "you died", "you won")

locations = ("cave", "pit", "hall", "lake")

textnr = 0
while textnr < 11:
    userinput = raw_input("You are in a " + locations[locationnr - 1] + " ")
    if locationnr < 3 and userinput == "north":
        movement = 2
    else:
        movement = 0
    if locationnr > 2 and userinput == "south":
        movement -= 2
    if locationnr == 2 and userinput == "west":
        movement += 1
    if locationnr == 3 and userinput == "east":
        movement -= 1
    if locationnr == 2 and userinput == "look chest":
        textnr = 3
        if chest_open:
            textnr += 1
        if item == "sword":
            textnr += 2
    else:
        textnr = 0
    if locationnr == 3 and userinput == "kill dragon":
        textnr += 11
        if item == "sword":
            textnr += 1
    if movement != 0:
        textnr += 1

    if userinput == "look":
        textnr += 5 + locationnr

    if userinput == "inventory":
        textnr += 6
        if item == "key":
            textnr -= 1
        if item == "sword":
            textnr -= 1

    if locationnr == 4 and userinput == "look corpse":
        textnr += 6
        if item == None:
            textnr -= 1

    if locationnr == 4 and not chest_open and not item and userinput == "get key":
        textnr += 10
    if locationnr == 2 and not chest_open and item == "key" and userinput == "open chest":
        textnr += 2
    if locationnr == 2 and chest_open and item == "key" and userinput == "get sword":
        textnr += 10
    locationnr += movement

    if texts[textnr] == "Opened":
        chest_open = True

    if texts[textnr] == "taken":
        if item == None:
            item = "key"
        elif item == "key":
            item = "sword"

    # print item
    # print chest_open
    print texts[textnr]

He turned all the if-conditions into expressions (that get evaluated), probably to safe memory.

But it's much more comprehendable with if-conditions.

Link to comment
Share on other sites

6 minutes ago, The Usotsuki said:

I used to write text adventures in Inform, but very few 8-bit systems can run Z5 games.

Nice! Did you try Inform 7? It's supposed to work almost like English, they say. Haven't tried it yet. I still may prefer writing code, lol.

In the 80s, I had "Hitchhiker's Guide to the Galaxy" on the A8. Was Infocom, I think. Wasn't it Z5?

Edited by Pokeypy
Link to comment
Share on other sites

14 hours ago, Pokeypy said:

Nice! Did you try Inform 7? It's supposed to work almost like English, they say. Haven't tried it yet. I still may prefer writing code, lol.

In the 80s, I had "Hitchhiker's Guide to the Galaxy" on the A8. Was Infocom, I think. Wasn't it Z5?

It was too clumsy for me. 6 was more natural, ironically.

 

There is a Z5 version of H2G2, but most versions are Z3. The Z5 version was the one with the InvisiClues, called the "Solid Gold" version.

  • Like 1
Link to comment
Share on other sites

21 hours ago, Pokeypy said:

Found a way to store adventure game locations in a 2D array.

That is essentially the same thing I did with my strings ####$H etc. Obviously you can store DATA statements as a series of numbers instead, which brings more clarity but takes up quite a bit more space in the listing.

 

In any case, regardless how your data structures look like, many of those examples have in common that they have a data driven engine instead of a story line full of IF blocks that would have to get repeated for every location.

 

I dug up another listing yesterday for the unexpanded VIC-20 that is more brief and slightly different from the one I posted but also serves as an example how you can do it. Some explanations:

 

w$="gotadrop" means the verbs go, take, drop, open.

t$="bikeflpawewidonosoeaweupdo" means the objects/locations big key, key, fly feet, painting, well, window, door, north, south, east, west, up, down.

 

The data statements on line 9070 obviously connect each location. The objects are listed on line 9080 with location -1 for those not directly in play.

 

This very brief adventure ends once you have picked up the big key (to the castle doors) and are located at the courtyard. There is a sequel to this adventure, just as short but one of this kind is enough.

aventyr1-en.bas aventyr1-en.prg

  • Like 1
Link to comment
Share on other sites

Aye, I forgot about this thread. Got a lot of catching up to do!

 

I have a mission now: create a better text adventure than carlsson at the age of 15. 

 

Oh boy, it contains string functions and arrays, the two things I don't understand in BASIC. (P.S. Yes, I am aware that these are essential to most BASIC games, it's just that the approximate location where every computer manual seems to put string functions and arrays is the point where I get bored and go do something else.)

Edited by bluejay
Link to comment
Share on other sites

I have a feeling that a 15 year old today is more mature and generally more knowledgeable (if nothing else so due to Internet) than in 1990.

 

Actually I begun sketching on a map for an even bigger game, though I never got around to finish it and the notes probably are lost. Not that the quality of an adventure game lies in how many locations or items you can stuff into it, but how your clues are created and how the game lets you solve them. Also sometime around then I got access to the Graphic Adventure Creator (GAC) which would provide me with a quality parser, big lists of verbs, items, locations and interactions between elements. Unfortunately the graphic part of the program was extremely crash prone, at least on my C64 though I seem to recall having read others had the same problem. GAC on other systems worked better, and you could definitely make a text only game that wouldn't crash out in the making process, but it felt pointless to make a non-graphic text adventure when you in theory had access to a hires graphics editor. Not that I ever have been any good in drawing graphics anyway.

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...