We’re rewarding the question askers & reputations are being recalculated! Read more.
85

There are several reasons for that. I'm just gonna touch on a few: It makes your source code a mess. If you have a lot of dialog (trees), a huge part of your codebase is just text that has nothing to do with your actual game code. You'd need to recompile every time you change so much as a single character. The dialog itself is hard to navigate. I imagine ...


30

Putting game content data in code means that to see any potential change or iteration of that game content data, you have to recompile the game itself. This is bad for two reasons: Many languages that games are written in have long compile times. C++ is particular can be very bad in this respect, and C++ is a very common language for large commercial games. ...


13

std::vector is a fine way to store "dynamic" (as you call them) things like items, but the real benefit of the vector is not that the thing you are storing can change, but that the number of items in the vector can change without minimal effort on your part. To illustrate, were you to have store your Item objects as an array, you'd have to fix the size of ...


13

If you're not completely wedded to C#, then the "more standard" way of doing this is to use one of the many text adventure creation tools which already exist to help people make exactly this kind of game. These tools give you an already-functioning parser, handling for death, save/restore/undo, character interaction, and other similar standard bits of text ...


10

Did you search in the interactive fiction community? They still write parsers and some try to push the envelope by implementing new techniques such as natural language processing. See for example this link for articles describing approaches used: http://ifwiki.org/index.php/Past_raif_topics:_Development:_part_2#Parsing


9

The term you want is 'natural language processing', or NLP. However, bear in mind that formal methods are designed to try and understand real world texts, whereas you only usually need something that works for a limited subset of your natural language. Typically you can start out with a simple grammar and vocabulary, then write a parser for it. A grammar ...


8

You could think of individual places as "rooms" with "doors" connecting them: To implement this, you could create a struct Room to hold a room, with fields for a set of items currently in it and what directions its exits lie in. Then simply keep an array of all rooms and have a pointer to the one the player is currently in. There are ways of getting extra ...


8

If you never return from functions, you may risk running out of stack space, but practically speaking it sounds like your case may be subject to tail call optimization. It's not an optimization I'd rely on, though; you may want to consider passing some concept of "current state" around or storing it, and letting a "main loop" (literally a loop in your main()...


8

Philipp's answer already shows the right direction. I just think the data structure is needlessly verbose. Shorter texts would be easier to write and read. Even if shorter texts would make the algorithm a bit more complex, that's worth doing, because you only write the algorithm once, but most of your time will be spent writing and maintaining the story. ...


7

As always, as always, it depends. But first, I would like to argue that hard coding is not bad by itself. I have hard coded content, specifically dialog text, in some simple games, and the world didn't end. We programmers love abstracting things, but remember that each layer of abstraction you make will make your program more complex and more difficult to ...


6

EDIT: After a comment by @ChristianIvicevic I felt compelled to reword my answer to emphasise that the Article link I provided is a far better alternative to using a system call as it is more secure and does not risk producing false positives with anti-virus software. Try and use this Microsoft solution: Performing Clear Screen (CLS) in a Console ...


6

Take a look at the game state pattern. The basic idea is that you have a class for every state. All classes inherit a interface that ensures basic functionality like entering the state, leaving the state, updating and rendering. Each specific state implementation holds (or has references to) all necessary resources and performs what you want to do. At some ...


5

Rather than making a separate function for every combination of nouns and verbs, you should setup an architecture where there is one common interface that all the objects in the game implement. One approach off the top of my head would be to define an Entity object that all the specific objects in your game extend. Each Entity will have a table (whatever ...


5

You have what I feel are two distinct problems. One is a design problem: how to deal with multiple distinct objects that have no distinct visualizable characteristics. The second problem is a technical problem, which is how to make it easy to identify individual objects out of a group via commands. Technical Solution Back in my MUD programming days, I ...


5

The two best current sources for learning to create a text adventure parser are (as was mentioned) the IF community and the mud community. If you search the major forums for those (Intfiction.org/forum, the newsgroup rec.arts.int-fiction, Mud Connector, Mudbytes, Mudlab, Top Mud Sites) you'll find some answers, but if you're just looking for articles I would ...


5

I would recommend you to create an array of dialog events. Each event is an object containing the text the NPC says and an array of possible player responses, which in turn are objects with a response text and the index of the event which follows on this response. var event = []; // create empty array // create event objects and store them in the array ...


5

I'd be tempted to write this as a lexer-parser pair, like a script interpreter / compiler front-end. The lexer reads the string, cuts out the next "token" to handle, skipping over whitespace or irrelevant punctuation, and standardizing the vocabulary of tokens (say, flattening to lowercase or merging synonyms/spelling variants/permitted typos). The parser ...


4

This is a tricky question. It's possible to extract the text parsing functionality from one of a number of IF engines written in general-purpose programming languages (i.e. not something like Inform). Some possibilities might be Pyf, and the Aunt and Butler's engine. If you expand your search to muds you'll have an order of magnitude more choices (here are ...


4

In my first-year at university we made an adventure game in Prolog, and for the user input we had to use definite clause grammar or DCG. See http://www.amzi.com/manuals/amzi/pro/ref_dcg.htm#DCGCommandLanguage for an example of using it as a command language. It seemed like a principled (it was uni after all) and flexible approach at the time.


4

Ok, let's go at this in a multi-stage fashion: Room representation Before we can do anything else, we need to consider how to represent the rooms internally. This is just a rough thumbnail sketch, refine as necessary: @interface TARoom : NSObject { NSDictionary *_links; // Contains neighbouring rooms. NSString *_identifier; // This will become ...


4

In case you ever need it in the future: For even more control of the display in consoles and cross platform support take a look at the ncurses library: https://en.wikipedia.org/wiki/Ncurses It is a bit of an overkill for just clearing the screen, though to my knowledge it is currently the only portable way, but it also allows for colors, menus etc. ...


4

Editline library (and GNU readline) works only with terminal capabilities. To use these libraries with your in-game console, you would first need to implement a terminal emulator (TTY). Instead (since doing that for a game would be crazy), I would recommend you to implement cursor movements and editing yourself. I once wrote a C++ class to handle this for ...


3

Instead of distinguishing them by different names or colors you could give the player a variety of commands with the power to distinguish. For example, if "five goblins attack you", you could invent either numbered or named commands like - "attack first goblin" or - "attach goblin 1" This approach is almost like you already suggested, but instead of naming ...


3

When you watch a race, it unfolds sequentially, until by the end there is a history of that race that you could tell someone as a story. Some research like watching races with your buddies might show off what the most exciting parts are, or how the story tends to divide itself up. In the "race" part of the game, you could randomise a story like this, having ...


3

You can find a good list of commands in many places in the IF community. You could try downloading Inform 7, TADS 3, ADRIFT, QUEST, and so on and looking at their default commands. There's a less comprehensive list in this guide, http://inform7.com/if/anth/IntroductionToIF.pdf . Your second question is much less clear-cut. Some IF games successfully ...


3

Short answer: JavaScript is a perfectly suitable choice for this. Ultimately you want it to be browser based, browsers run JavaScript. You want it to be able to be single player and store player choices, JavaScript has local storage up to ~5MB that you can use. If you want player choices to be stored on your server and not their machine, there is a light-...


3

Short answer Asking how to make a text-based game is essentially asking how to program. Learn to program. Long version Learn programming Writing text-based games is a good way to learn. This is the hard part. This is going to take time. The first thing any game needs is a loop, input, output and something that converts input to output. This is what ...


3

Go with classic VT100 dimensions. It's the kind of terminal that such things would be run on when it was actually a game you played on a terminal. From http://www.columbia.edu/cu/computinghistory/vt100.html I see that the display is 80x24 or 132x14 character cells, optional 132x24. I don't recall playing it at the 132 resolutions, but 80x24 is "classic"


3

I think it is too easy to be the 'wither-than-white' guy and recommend warmly using an external text resource file. Why? Because there's a choice here that's about balancing each solution's cost/issues/advantages. When using an external file... Well, I guess the other answers explain the benefits well enough. But what about the costs? You have to define a ...


Only top voted, non community-wiki answers of a minimum length are eligible