Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Text Adventure (yes, yet again)

Author
Message
Evarcha
19
Years of Service
User Offline
Joined: 7th Jan 2005
Location: Preston, England
Posted: 10th May 2005 06:21
Hi all. I have been looking through the pages of the forums, also I have looked in the snippets too and yes, I have found some examples of a text based adventure and I know they're relatively easy to produce, I myself have made a very VERY simple text adventure but would like to add health and money etc in there, and also a decent text based combat system where you can buy or sell weapons. My problem is that although I am really trying to understand the structure of more advanced programs I keep stumbling on the same problems. Like, I want to make 10 different 'baddies' that you can stumble accross in the dungeons I am creating, but I have no idea how to randomize from a list of potential monsters, also, how frequent they might turn up, Goblins turn up frequently, dragons turn up very rarely.

Like I said, I can make a very simple text adventure, but I wondered if there was any examples out there that I could look at or if anyone has actually made a simple text adventure. I dunno if this happens to all programmers but my mind has literally gone blank. Thankyou to all that help.

Evarcha.
Evarcha
19
Years of Service
User Offline
Joined: 7th Jan 2005
Location: Preston, England
Posted: 10th May 2005 18:11
Please remove this thread as there is a good thread just above mine covering what I asked for.
sorry.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 10th May 2005 22:23 Edited at: 23rd May 2005 12:00
Evarcha,

Actually It may be better to leave this thread going and I'll post how to create a Sierra like adventure here.

Reason: I kind of stepped on Timesplitter's thread. And while I was posting my reply (which tooK a while) other posts came in. So I'm not sure if he was aiming for an actual Text Adventure.

So perhaps a mod can delete my post in Timesplitters thread, and I will move my Text Adventure stuff herE.

I'll follow up later with how the command parsing token system works

~zen
========


Tower Of Mystery (on-going code)
Last edit Sunday May 22,2005 @10:00pm EST
-Currently working on the Command Parser
-Parsed 1st word second word
-gets verb token and objec token



Evarcha
19
Years of Service
User Offline
Joined: 7th Jan 2005
Location: Preston, England
Posted: 10th May 2005 23:09
Ah yes, I have been reading your posts on other threads and find them very interesting. Cool, if people can add to this thread then please do! I for one will be keeping an eye out for any information that helps me learn. Thanks zenassem, I actually printed out the program structure bit that you wrote on the other thread, I was going to ask for someone to do that for me so I could understand more. My main trouble is understanding the process of a program and the introduction of new variables and functions etc. I find that whenever I get a chance to read your stuff I always learn something new.
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 13th May 2005 09:49 Edited at: 13th May 2005 09:51
How to code a Text Adventure:

I haven't written a text adventure since my days on the Commodore 64. I learned how to write them from the book "COMPUTE!'s Guide to Adventure Games" by Gary McGath (C)1984.

My approach in this thread will be to first translate the simple BASIC text adventure The Tower Of Mystery, from the book, to DB code. This will provide a foundation of text adventure principles.

Finally I will attempt to create a "Text Adventure Creator" that will make creating text adventures easier, and less tied down to hard code. For this we will need to build our own script code. It should be fun! So let's get started.

For those who may not be familiar with the genre, here is a list of some popular text adventure games from back in the day. I'm sure a Google search will turn up a lot of resources on these games.


Infocom Adventures
Zork I, II & III
Deadline
Starcross
Suspended
Witness
Planetfall
Enchanter
Sorcerer
Infidel


Scott Adams Adventures
Adventureland
Pirate's Adventure
Adventure #3
Vodoo Castle
The Count
Strange Odyssey
Mystery Fun House
Pyramid of Doom
Ghost Town
Savage Island
Golden Voyage


Sierra On-Line Adventures
Mystery House
The Wizard and the Princess (made an appearance in the movie BIG)
Cranston Manor
Ulysses and the Golden Fence
Time Zone
Dark Crystal


Misc.
Adventure; (DECUS) & Microsoft
Asylum, Asylum II; Med Systems Software
Bedlam; Radio Shack
Blade of Blackpoole; Sirius Software
Cyborg; Sentient Software
Dungeon; (DECUS)
Empire of the Over-Mind; Micro Computer Games
(div. Avalon Hill Game Co.)

Prisoner 2; Edu-Ware


Well that's enough examples for now.


zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 13th May 2005 10:07 Edited at: 13th May 2005 11:58
Following are the features we will need to code for our text adventure

- The command parser: Interprets the player’s commands.
- Output routines: Tell the player what is going on.
- Action routines: Cause things to happen in the game world as a direct result of the player’s commands.
- Automatic routines: Cause things to happen because of the passage of time or because of some event independent of the player’s actions.

We will also need to develop the following structures

- Vocabulary list: The words in the program’s vocabulary, grouped according to parts of speech.
- The internal map: Itemizes locations that your character can reach and the paths that allow access form one location to another.
- Object descriptors: Itemize various tools, treasures, and other objects available to you. The descriptors indicate where the objects are on the internal map, and they specify any distinctive characteristics the object may have.
- The character descriptor: Holds information about your character (such as location, inventory, and state of health)


The Parser

Our program will need to accept free-format input. Meaning; the user is can type in text (up to a certain limit), and from that we will need to interpret what the user’s intention is. To do that, we will need a command parser. To parse a command means to break it down into its word components and identify their syntactic relationship.

English Grammar Review: A sentence has two parts: a subject and a predicate. In a simple sentence like “I go,” I is the subject and go is the predicate. In an imperative sentence, which expresses a command, the subject is omitted. The sentence “Go!” is made up of only a predicate.

Commands in an adventure game are imperative sentences. This allows us to greatly simplify grammatical structure and means that the program has to analyze only the predicate.

For our purposes, the predicate can be considered to have three parts: the verb, the direct object, and the indirect object (or prepositional phrase). Take the sentence, “Give me your gun.” Give is the verb; gun is the direct object (the thing being given), and me is the indirect object (the recipient of the action).

One can also express the indirect object as a prepositional phrase; the preceding example could have been expressed as “Give your gun to me.” The preposition to relates me to give.

An object (direct or indirect) or a prepositional phrase consists of a noun, possibly modified by one or more adjectives. An adjective describes the thing named by the noun, and—what is important for adventures—it can specify which object, you are talking about. If you say, “Give me the smoking gun,” then you are referring to one gun in particular (and not the cold gun that might also be nearby).

There can be more than on object. Multiple objects can be listed explicitly, one at a time; for instance, “Take the bell, the book, and the candle.” The word all or every can imply multiple objects, as in “Take all the gems” or “Take everything.”

Just as a noun can be modified by adjectives, a verb can be modified by adverbs. If you’re afraid of being overheard, you might say (or whisper), “Give me the gun quietly.” In that case, quietly is the adverb modifying give.

Beyond this basic structure, the only other grammatical feature that an adventurer might encounter is a noun of address. This is just a noun added at the front to indicate whom you’re talking to; for instance, “Moderator, do not lock this thread.”

Phew! That’s enough grammar for us to get going.

"So what does the parser need to do?" Glad you asked. A parser operating on the command BURN RED BOOK, for example, would do the work necessary to determine that BURN is a verb, BOOK is the object of the verb, and RED is an adejective modifying BOOK. It is also responsible for reconizing meaningless input so that the program can disregard it or complain to the player.

The parser takes the words of the command and converts them to units of internal storage called tokens. The tokens are passed to the action dispatcher, which calls the appropriate action routines, depending on what tokens it sees. The parser might produce fewer tokens than the number of words it sees, since it can throw words out or combine two words (for instance, PICK UP) into one token.

The command parser is one of the most important parts of adventure program, since the player can get frustrated very quickly if he/she can't tell the program what to do. THe power of a command parser depends upon the size of its vocabulary, the number of letters it uses per word, and the complexity of the syntax it can handle.

Parsers can be written to recognize a certain number of letters per word and usually disregard the rest. Thus, if a particular program recognizes five-letter words, then INVENTORY, INVEN, and INVENTION will all be equivelaent.


zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 13th May 2005 12:28 Edited at: 13th May 2005 14:24
TOWER OF MYSTERY:

Overall Program flow Pseudocode


For our simple text adventure we will begin with a simple command parser that expects a verb and an object. So, it has to take a line of input and end up with two numbers, representing the verb and the object. These numbers, called verb token and the object token, will be used for dispatching action routines and indexing into arrays.

The first step is to get a line of input and extract two words from it. The next step is to convert the two words into tokens. To do this , the parser has to llok up each word in an array of recognized words. Will call these arrays verb array and object array. The parser starts going through the verb array and comparing each string in turn to the first word. If a match is found it yields an index. This index is then used as the index into another
array , called the verb token array, to get the number which is the verb token/

Several different elements of the verb token array could have the same value; this corresponds to having different verbs that are treated identically. For instance, GET and TAKE might lead to the same verb token. Suppose these are the sixth and tenth elements of the verb array. Then the sixth and tenth elements of the verb token array would have the same value. This allows the program to treat both verbs identically.

The same thing happens with the second word. Except now we have an object array and an object token array.

Parser Pseudocode


Getting two tokens from two words Pseudocode



Describing a World

Internal Map: Describes the rooms
Object Descriptors: Describes the objects found there.

ROOMS
Each room or area needs a number to identify it. Once you've drawn up a map for your adventure, number the rooms from 1 to however many rooms you have. Any order will do, but it's convenient to use 1 for the room the character will start in.

To describe the rooms, the program needs an array of room descriptions; room descriptions array

Another array is needed to describe thr interconnections among the rooms. This array will be called the access array. This array will be a 2 dimensional array. The first dimension is the number of rooms; the second dimension is the number of different directions in which the character can go.

In order to look up a direction in the access array, driections need to be translated into numbers (enumerated). ie north, south, east, west, up, and down are numbered respectively as 1,2,3,4,5, and 6. Then
Access_Array[6,4] would be the number of the room reached from room 6 by going west. If the charcter can't go west, then this element would be 0.


Objects
Once the rooms are taken care of, the other major set of data structures is the one that deals with objects. The structures here will be arrays indexed by object tokens.

Example types of objects:
-Objects that have a specific location and can be carried
-Objects that have a specific location but are normally immovable.
-Objects that have a specific location and can't be carried, but may move on their own. These include Non Player Characters (NPC's) and monsters.
-Objects that can be Entered or climbed to get to another room


Skeletor
20
Years of Service
User Offline
Joined: 21st Jun 2004
Location: florida
Posted: 13th May 2005 14:35
@ Evarcha
Heya I just replied to your email.

@ Zenassem
Make sure you dont stress your self out buddy , Im not trying to be sarcastic or anything either. Its cool to have ya back and I would hate to see you take another big break from DB forums.


zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 13th May 2005 15:00 Edited at: 13th May 2005 15:02
<I'll edit in The description Section, Automatic Routines, Action Routines, Prefiltering, Dispatching to Action Routines as I go along.
So check the top of this post for the in-depth descriptions of those processes>

====================================================================

But I would like to start building our Text Adventure

Variables and Arrays
The following variables and arrays will be needed

Constants
NUMROOMS : Number of rooms
NUMTHINGS : Number of things or items
NUMPOBJ : Number of pseudo-objects (all other things)
NUMOBJ : Number of objects of all kinds
NUMVERBS : Number of verbs

Flags
CompAct : Computer is active
CompDoa : Computer is dead
LoggedIn : Character is logged in to computer
CopyProg : Copy program is running on computer
ManualFound : Computer Manual has been found
CoinFound : Coin has been found
RdRFlag: Room description Request Flag
RatsTrouble : Rats are troublesome
BatsTrouble : Bats are troublesome
CompStartTime : Time since computer has been started

General Variables
cmd$ : Command Input
cmd1$ : First word command
cmd2$ : Second word command
VerbTkn : Verb Token
ObjTkn : Object Token
CurrRoom : Room currently occupied

Arrays
Access[NUMROOMS,6] : Access Array
Verb$[NUMVERBS] : Verb Array
Object$[NUMOBJ] : Object Array
RoomDesc$[NUMROOMS] : Room Description array
ItemDesc$[NUMTHINGS] : Item Description array
VerbToken[NUMVERBS] : Verb Token Array
ItemLoc[NUMTHINGS] : Item Location Array
ItemFlag[NUMTHINGS] : Item flag array (can item be carried or not)

@skeletor, Thanx! Your right. I think I'll call it wuits for tonight. Better to get some rest.


IBOL
Retired Moderator
20
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 13th May 2005 15:16
wow,
now I want to make a text game. i played these a long time ago...
bob

http://astrumgames.com
completed games: Astrum Erus, Centipoid, Hero Of Garaven, WarpFlight, Higher Ground , Circular Breakout
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 13th May 2005 19:19
Agreed, I loved text adventures, ever since my uncle introduced me to colossal adventure on the C64, that and Hobbit on the Spectrum. I started coding so I could make my own adventure games, quite tricky when you don't know how to write a parser (I was only wee) - I think my first game was 100% hard-coded, like every item and room was coded by hand rather than having a real inventory or movement system. As soon as I discovered arrays and learned to use them with data statements I was in heaven .

Nowadays I still play them on my little Palm Tungsten, there's a great infocom and magnetic-scrolls parser for it that plays these games, with all the cool graphics from the 'scrolls games too. It was all free, even the game downloads were free. I'll have to check out Asylum/Asylum2 if I can find them as well, I remember hearing about these games 10 years ago but never got to play them.


Van-B

zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th May 2005 12:46 Edited at: 16th May 2005 03:34
Here is the map for our Simple Text adventure.




Description of the game:
The setting is an old factory building. The overall goal is to obtain a treasure in the form of a program from a computer. There are three main obstacles the player must solve.

1.Getting Media to copy the program onto.
2.Turning on the computer.
3.Logging onto the system.

Each of these tasks is creates a chain of puzzles.

Rats make getting the media difficult.
The vending machine provides candy to feed the rats.
A hidden coin makes it possible to use the vending machine.
Logging on requires finding a computer manual. (RTFM!)
The manual is guarded by bats. (the flying kind)
A noisy clock tower provides a way to scare off the bats.
To Start up the computer the player has to try different actions. (kicking the darn thing seemed appropriate)
=============

So now all we have left to do is code... Ummm.. Everything!

@Van B
Here's and old review of Asylum & Asylum II

Asylum, by David C. Willen

You have been put away in the asylum. Can you get out? Perspective graphics, good command handling, and a large map combine to make this an intriguing game. The going isn't easy, and it may be a long time before you can even get out of your cell. You do have a hand grenade that someone slipped into your cell, but how can you use it in a small room without blowing yourself to bits?

Once you get out, you find yourself roaming through corridors and trying doors in hope of escaping before the guards catch you. If you do meet a guard, you may still be able to outwit him. Patients might be able to help you if you think you can trust them.

Graphic adventures often sacrafice command handling for picture, but Asylum is better with commands than many all-text adventures. Its vocabulary (which can be displayed on request) is over 200 words. You can enter commands as complex as GIVE COAT TO GUARD and OPEN DOOR WITH SILVER KEY.

There are some oddities, though. Objects that aren't being carried are always in "boxes." If you drop an object, a box magically appears to hold it. To see what is in the room, you have to OPEN BOX. You can also put an object under something else. For instance, you can PUT CAN
UNDER BED. Once you do this, no amount of searching will reveal its presence. Only if you remember where it is and type TAKE CAN UNDER BED can you get it back.

As you make your attempt to escape, a clock keeps ticking whether you move or not. You have only 12 hours of gameplay (about 6 hours of real time) to flee before the more competent day shift comes to lock you safely away. Fortunately, you don't have to do the 6 hours at one sitting; you can suspend or save the game at any time.

Asylum II
Pretty much like Asylum I. I believe this version was released to make the game a little easier. As many peopled had trouble completing Asylum I.

ie. There are no gurads roaming the halls, A player can map out a large area of the Asylum very early on.


RiiDii
19
Years of Service
User Offline
Joined: 20th Jan 2005
Location: Inatincan
Posted: 14th May 2005 13:37
Ummmm.... WOW!!!

Going for a sticky now!

"Droids don't rip your arms off when they lose." -H. Solo
REALITY II
Skeletor
20
Years of Service
User Offline
Joined: 21st Jun 2004
Location: florida
Posted: 14th May 2005 14:28 Edited at: 14th May 2005 14:33
Zenassem, whens your first book coming out?

Man I gotta say, you write one hell of a tutorial! Keep up the great work.


zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 14th May 2005 14:56 Edited at: 14th May 2005 16:37
Here's the beginning of the code. I'll try to keep each line to a minimum to make the code easy to read and comment.

If you can follow this, you should have no trouble following the rest of the game code. If you are unsure about something at this point, please ask so that it can be clarified.

Remember:
"There is no such thing as a dumb question; except for the question that is not asked."




Perokreco
19
Years of Service
User Offline
Joined: 5th Apr 2005
Location: Bosnia and Herzegovina
Posted: 14th May 2005 21:54
If you are making a text adventure you could use special programs designed for that like Quest
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 15th May 2005 11:52
@Perokreco,

Yeah, You could. But then you wouldn't have all the fun of figuring out how to code them yourself; or how to make your own adventure creator.

~zen


zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 16th May 2005 00:50 Edited at: 16th May 2005 01:04
The actual program Source Code will be located in the code snippet in my first post in this thread. I will update it regularly; providing the date and time of the changes. This will make it easier to grab the entire source as we add things.

I hope that makes sense.

I will still continue to discuss the code and have snippets throughout the thread.
======================================================================


-Currently working on the command parser.

~zen


zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 16th May 2005 13:16 Edited at: 17th May 2005 23:28
Edit:Removed - skeletor responded to my question regardin hotmail purposely blocking gmail attachments claiming they had a virus. What B.S.

....

I'll edit this out the after you post.


Skeletor
20
Years of Service
User Offline
Joined: 21st Jun 2004
Location: florida
Posted: 17th May 2005 10:28 Edited at: 18th May 2005 11:37
removed


zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 17th May 2005 23:26 Edited at: 23rd May 2005 12:09
[edit]removed Response to skeletor :same reason as above post


zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 23rd May 2005 12:05
Ok I just started getting back to work on this:

I know that this is a text adventure, and that many people aren't going to be interested in these type of games. But I hope that it will serve as a study in arrays and logic flags.

======
I added a simple ASCII art titlescreen

The parser gets two words from the command line
searches for the Verb Token and the Object Token

Prints the results using a test stub of some values in the Parser Subroutine

-Currently working on item location and Action Dispatch code

~zen


Computer Nerd
19
Years of Service
User Offline
Joined: 25th Jan 2005
Location: What do you care?
Posted: 25th May 2005 09:55
@zen
Can I use arrays like dim instead of data? That's what I've been
doing with my text rpg or adventure.

DarkBasic Classic Owner
zenassem
21
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 25th May 2005 12:05
@jono,
Quote: "Can I use arrays like dim instead of data? That's what I've been
doing with my text rpg or adventure."


I'm not sure I fully understand the question. Perhaps you could post a sample code snippet of what you mean.

I am also using Arrays. I just decide to fill them by reading the info in from data statements. I could also read the data from a file.

~zen


Login to post a reply

Server time is: 2024-09-23 21:23:32
Your offset time is: 2024-09-23 21:23:32