Sign in to follow this  

[c++] text adventure

This topic is 4405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have learned all the way to structuring. And I was wondering what knowledge is nessasry to make a text based adventure. I know there isnt completley a set thing but from everyones opinion? And if I do know everything i need to where do I start?

Share this post


Link to post
Share on other sites
I'm gonna assume that by text adventure you mean something like a game written in Inform or one of the old Zork games or some such. If I were to write a text adventure I'd most likely choose Inform, but that's irrelevant here.

Text adventures (like all other games too, I guess) have a lot of data to process, so maybe you should start by thinking about how you are going to organize it. There's rooms, with short and long descriptions, multiple exits, and such. Rooms can contain objects, or actors, either of which can contain more objects, and then there's still the player to think about. So at the minimum you'll need structures to represent a room, an object, and an actor. You need to organize this stuff internally, but also make it so that you are actually reading it in from external files in order not to hardcode the game data in the program - so you'll have to deal with reading and parsing a file format (most likely your own homebrew variant).

Assuming you've got all that figured out, you'll still need to write a parser to process and validate player input (aka what to do when player types "wait, wait, go east, exit south, attack bear with sledgehammer, take key from under plant, put key in lock"). Making the parser understand near-natural language input is a daunting task, most probably quite beyound your capabilities, but you could boil it down to some simple forms like "<action> <object/actor>" or "go <direction>".

Another thing I would consider is whether time flows naturally (like in a MUD, but also in some text games) or round-based (player won't get eaten while he struggles with your interface).

Nothing interesting is gonna happen with just that though, so you'll then need to think about adding actions or events triggered upon the objects (turning the arm of the statue slides back the secret bookcase in the previous room). Some of the actors probably have their own agenda and might not be very friendly to the player.

I've mentioned Inform above. If you haven't yet, you might want to look at how inform source files are written, that might give you a better idea about the kinds of structures you might wish to support in your game: Inform homepage

Share this post


Link to post
Share on other sites
question
Parse??

answers

turn based.. its gonna be like what do you wanna do? and then list possible actions.
I have tried this in the past without knowledge of pointers etc. and I must be missing something cause im not seeing how understanding pointers is gonna help me, unless i store all the room info into a txt doc.??



Death

Share this post


Link to post
Share on other sites
I've posted some more stuff above. I didn't mean c++ pointers specifically, and actually I can't even find my own passage where I wrote that before. Talk about carelessness lol.

Parse -> break down a sentence into tokens (and then figure out what the tokens are and what they mean when put together in that order)

For your simplistic approach, just presenting the player with a list of choices, you won't need much in the way of parsing input (still have to deal with data files though!). I was making some general statements about how these games are usually done.

For instance, in Inform, you write a definition file (which is written in a language that is somewhat similar to C or pascal, iirc), in notepad or some such, which describes everything about your little adventure world, and then compile it to bytecode that runs on a Z machine which is just a VM (like the Java VM). This goes to show that writing data for a text game can be as intimidating as writing a whole new programming language (and a new emulated "hardware" to run it, too). You won't need this much functionality, but still figuring out a file format to keep your data in might be nice.

Share this post


Link to post
Share on other sites
Quote:
Original post by lightbringer
You won't need this much functionality, but still figuring out a file format to keep your data in might be nice.



not following you here.. file format for what? the code? the text?

Share this post


Link to post
Share on other sites
Quote:
Original post by DeathsBargin
not following you here.. file format for what? the code? the text?

That actually depends. Your data (ie room data, object data, etc) could be text (very likely) or it could be code that you write your own compiler for (if you can pull _that_ off, then you don't need my advice ^_^).

You can either:
1) Hardcode all data into the program. (You'll have to recompile every time you fix a spelling mistake :S)
2) Put it all into files (probably plain text files) and have the program read those files and create the internal structure from them (fill in a room object for every room in the file, store it somewhere, etc etc)
3) Write your own programming language and compiler and interpreter specifically for running text games. (forget about that for now)
4) Write your text adventure in a language specifically designed for text adventures (but what's the point then, you're not learning anything)

You probably want to do #2. Figure out how you're gonna store objects and their event code in memory first, then design a file format to suit that.
Ie:
START ROOM "a_dark_room"
desc "A Dark Room"
long_desc "You're standing in a dark room"
EXIT N "an_even_darker_room"
END ROOM

... or something like that. I've never done this before so I'm improvising here, sorry. Here's another idea: You could use XML to store the data. XML is well suited for this kind of structural data. Then use some simple library like TinyXML to parse it into internal structures.

Edit: Seeing as it's 5 AM here, I'm going to bed. Maybe someone else will be able to offer more c++ specific advice, it's not my expertise so I was trying to keep it general. But looking over your replies I'll venture the guess that you're not quite ready yet to take on the project, or at least should do it with a good c++ book in hand ^_^. In any case, good luck.

Share this post


Link to post
Share on other sites
i have decide to go with one. (Im willing to do it this way its simpler)
i plan to give every room its own variable and it reads off what it has to when the variable is true (when they enter the room its true)

now i know this is far from the effecciant way to do this. But (even though i have learned about it) using pointers and stuff just dont seem to benifit me any here..
I have decided to make this a test game. expand after i have figured out everything I have to.

[code coming soon]

Share this post


Link to post
Share on other sites

This topic is 4405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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