Sign in to follow this  
bunni

Text-Adventure Help

Recommended Posts

bunni    122
Im a beginning C++ programmer and am having a little trouble with making text-adventures. Basically, I want it to work like a simplified ZORK. And, if possible could someone sketch out how to do a (C++ please) text-adventure.
Bunni can do pi look: 3.14159265358979323846... 

Share this post


Link to post
Share on other sites
furby100    102
Set up a file containing the map, divided into rooms. For each room list the exits, descriptions of the room, and items present and other stuff. Then in the program you load this file, store the rooms in the data structure of your choice and the player's current room, and the items on the player's inventory (you also need to keep track of whether the items in the rooms have been picked up or not obviously). Then you set up a loop allowing the player to enter commands, and then parsing the commands, typically taking the first word as the verb (you might just do this all hard coded, or make a file containing all the verbs and some sort of scripting description of what they do, although that might be too complicated for a first attempt) and the following words, if any as the object, and then performing the appropriate action.

It's all pretty elementary really. Is there anything specific you need help on, because in full detail one could write a book.

Share this post


Link to post
Share on other sites
bunni    122
How about help with making it w/ classes... The problem is how to structure them and how they interact. Like knowing if the player is in thier and stuff.

If someone could point me to a nice tutorial of some sort that would be great as well!

Share this post


Link to post
Share on other sites
krewekomedi    122
Create classes based on the "things" in your game. Good candidates for classes are rooms, objects, monsters, and possibly the player's character.

Since this is a text adventure, you don't really need a user-interface class, use a simple loop which accepts commands, processes them, and then outputs text back to the player.

I don't know of any published books for a Zork-style game, but you might find something with a Google search such as "text adventure c++".

Share this post


Link to post
Share on other sites
furby100    102
One way of doing it was to have the player object have a pointer to the current room object. To move between rooms, you can change it to one of the exits stored in the room. You can have rooms describe themselves (i.e. have a member function that prints out a little description), and the player object can interrogate the room object about the other objects it's got (do something like have a function that gets a vector of items).

The best idea would probably be to just sketch out a basic plan of how you think it could work on paper and then try to code it. If you come to an impasse with your coding, change the design a little so that it works better.

Share this post


Link to post
Share on other sites
daviangel    604
Quote:
Original post by krewekomedi
Create classes based on the "things" in your game. Good candidates for classes are rooms, objects, monsters, and possibly the player's character.

Since this is a text adventure, you don't really need a user-interface class, use a simple loop which accepts commands, processes them, and then outputs text back to the player.

I don't know of any published books for a Zork-style game, but you might find something with a Google search such as "text adventure c++".

Actuallly "Sam's Teach Yourself Game Programming with DirectX in 21 Days" teaches you how to build your own zork sytle game using directx. Although there is alot of directx stuff in there the underlying game engine is in c++ and covers pretty much what you need.
Also all of andre lamothe's books seem to cover a zork-style text based game. He uses C mainly instead of C++ so his language parser is actually easier to understand for a beginner anyways.

Share this post


Link to post
Share on other sites
Drew_Benton    1861
Quote:
Original post by bunni
Basically, I want it to work like a simplified ZORK. And, if possible could someone sketch out how to do a (C++ please) text-adventure.


I thought this bookmark would never come in handy [lol]. Make sure to thank him if you can use it. [wink]

Share this post


Link to post
Share on other sites
krewekomedi    122
If you aren't ready for vectors, then linked lists probably aren't a good idea either - these are both important tools, but it may be a little early to learn them.

I would suggest a fixed-size array of objects. It's a good concept to learn. You could assume that a character or a room can only hold a certain number of objects and set your arrays at that size. This is not an optimal solution, but it might be a good concept for you to start with.

There are plenty of references online and in print on vectors, linked lists, and arrays. If you have a generl programming c++ book, arrays should be in there.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this