Hot answers tagged text-based
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 ...
8
The %attacker% approach can be extended to include some information other than just the names of the objects:
The verb may be singular or plural. This depends on the subject. "You attack X" (singular 2nd person subject) vs. "Extrakun attacks X" (singular 3rd person subject) vs. "The goblins attack X" (plural 3rd person subject). Most verbs just need an -s ...
8
You could build the entire game in JavaScript for sure. Be aware that the source-code will be visible to the user. So if you're concerned about cheating (probably a non-issue if it's just a single-player game), then you should have your game logic on the server.
JavaScript and PHP is definitely going to work.
If I were creating such a game, I would do the ...
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 ...
7
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 ...
7
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
7
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 ...
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 ...
4
Instead of having a single string, and trying to substitute into it properly, you could have a whole set of them. Start with the objects. You know, when creating the mob, what to refer to it as. You can give it a specific property, separate from it's name, for substituting into attack strings. Weapons can have multiple strings for variety, and can substitute ...
4
There is a set of modules for Perl starting with Lingua::EN::Inflect that deals with these issues. Even if you're using a different language, the API choices made might help you frame your own design.
4
The common answer you'll get is "with components". There are lots of questions with that phrase in them that you can search through.
In particular, here's a good article that has been linked to several times that's worth a read: http://cowboyprogramming.com/2007/01/05/evolve-your-heirachy/
4
That is the standard way of getting the time from C#. And using a BackgroundWorker I think is better than multi threading it in this particular scenario.
Though I think the above comments are a bit confused as with most games, there is no waiting around for inputs its always updating.
It will be hard to perform time based actions when you aren't using a ...
4
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 ...
4
Most game loops I've encountered like to check an input state of some kind (not wait around for input, instead have it buffered).
I'm assuming your making some game with the Command Prompt in C#. You'll probably want to buffer input via ReadLine() in a thread safe queue. You should then implement a more normal game loop in a separate thread that checks this ...
4
The state of the art for making text adventures today is using Inform 7. Inform 7 source reads "like English," in the same way that Inform-based games let you "write English." For example, from Emily Short's Bronze:
A thing has some text called scent. The scent of a thing is usually "nothing".
The block smelling rule is not listed in any rulebook.
...
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
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
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
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. ...
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
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
If you'd like to see what one approach to this looks like far down the evolutionary path, take a look at the MudOS parser. This is a complex, powerful mechanism for defining pattern-based parsing, meant to be able to intelligently route command handling for targets with multiple nouns and adjectives, and handle cases like put ITEM in CONTAINER vs. put on ...
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
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 ...
3
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
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
...
2
The way I handle this is through a large set of systemry that, among other things, involves modeling the message as a data structure rather than a string. The values for the attacker and the defender are their actual objects; the verb ("inflict" in your message) is marked as such, and knows the object for the person performing it, so that the message ...
2
If you really want to use XNA and graphics along with your text adventure, you should build your own interface; this should be the least of your challenges since you already seem to know how to display and manipulate graphics with XNA.
The question is, do you want to write a text adventure, or a text adventure engine?
If what you really want is to write a ...
2
If your goal is a text based game your better off making it with regular Form based program, or my favourite WPF. XNA has no built in support for handling typing, that is, quick presses of keys in sequence. It focuses entirely on detecting keys being held over time (which is more likely the case in an action style game). If you really need XNA to display the ...
Only top voted, non community-wiki answers of a minimum length are eligible