Text based game?

Started by
9 comments, last by Ravuya 16 years, 5 months ago
how do i make a text based game, with a text based database?
Advertisement
TextBasedGame* textbasedgame = new TextBasedGame("database!1");


Seriously, though, we need more information. What type of text-based game are you wanting to make? Is it an adventure game of some kind, a guess-the-number game, or what?

The question you originally asked is about as vague as it can possibly get, I'm afraid.
well a text based game is a game minus graphics so thats simple. as far as a text based database it sounds like you want a .txt file for all the data. in that case you will need a few good string splicing functions to get all the data out of the file and string lines.
Look into maze generation algorithms, or alternatively load the maze from file.
If your rooms are square, there are 16 kinds of room, one for each hex digit. -   -|     ||     ||     | -----This is a room with one north door. (0001) -   -|     |     |     | -   -This is a room with four doors. (1111)0000 could be a blank space.To make the levels you need a file which looks like this:00000004000000000000000500000000000000050000700000000005000050000000000500005000000000050000500000000003AAAA9000It could be binary if you like, but ascii would be easier.



Generate a maze, and write the code to describe each room and move the the next room. Write some code to draw the maze using ascii graphics.
(e.g. when the player types a certain command the maze screen displays.

Then add a system for random monsters appearing in each room. Monsters should spawn in the room when the player enters. A turn based fight scene should ensue. Monsters could be hard coded or loaded from a file of monsters and stats.

When you get this working, you need a system of pass or no pass. For example, a door could be blocked by a character who needs an item. Or, the door could need a key of a certain shape. A seperate block of data can describe the items and characters in the maze.

I haven't seen a new, good text based game for years.
I just wanted to see if he would actually do it. Also, this test will rule out any problems with system services.
The simplest way I found to implement these kinds of games is to create a database of objects. Each object has a list of associated verbs. Then you do some rudimentary parsing on a sentence, searching primarily by the verbs of objects currently in an "active list".

Most objects get moved to the active list when you move into the room they're in, or when you put them into your inventory. You remove them from the active list when you leave the room, or when you don't want the player to interact with them anymore.

The most complex sentences you're looking to parse with these are short, one-verb sentences with up to two objects like...

take the wrench
go north
give apple to pauper
use screwdriver on machine
attach the lamp to a battery

This kind of parsing is usually more than sufficient. It won't let you easily parse sentences like...

tell bob to get the generator from the shed

But there are ways to parse those using this structure, by checking for "tell/ask/order/etc" and a person on the active list and then doing the normal parse on the remainder.

Lastly, by encoding basic directions like "north" or "n" as verbs of the current "room", not as nouns like you might expect them to be, they parse easily using this style.

Anyways. From the top...

1. Take all current "active" objects, and collect their verbs.
2. Check the first word in the input sentence against the verbs.
3. Run through the objects who accept that verb, and find one that appears earliest in the sentence.
4a. Give that object's script for that verb the sentence to work with. A small library accessible from the scripting system for looking for other active nouns in the sentence and examining all the words in the sentence is advisable.
4b. When the sentence is just a single word, the object providing the verb should mark the verb as having itself as a "default" noun. This is used for things like "north" being navigation.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Ok sorry I think I might have worded this wrong I need a text database for my game, I have no clue how to make a text database. Do you guys have tutorial links or something? Thanks
What language are you planning to use? If you've never written a text based game before, I recommend hard coding the messages.

If you do wish to use a text database, try the following code: (assuming your language is C. You didn't say otherwise after all, and C is the first language in alphabetical order that I know.

Disclaimer: Coded from memory. Not fully tested. May cause a slight case of spontaneous human combustion and it won't be my fault.

#include <stdio.h>#include <stdlib.h>#include <string.h>FILE * tt;int open_file(){        tt = fopen("trash.txt", "r");         // Open File for read only        if(tt == NULL){                printf("Error: could not open file\n");                return 0;        }else{                return 1;        };};int close_file(){        fclose(tt); // Close File};void messages(){    char trash[50];        while (!feof(tt))        {            fgets(trash, 50, tt); // Read line into trash              fputs(trash,stdout);        }};int main(){        open_file();        messages();        close_file();return 0;};


This is the text file I've tested it with:

You see a dog.Your face suddenly catches on fireYou crap your pants. You smell.The dog bites your face.You are bleeding.Enter a command : clean pantsGood idea. What with? Enter a command : clean pants with dogThe dog Bites you. You die....End of lines.Bye


The code is very simple and should act as a tutorial for you.

[Edited by - shotgunnutter on November 5, 2007 11:10:34 PM]
I just wanted to see if he would actually do it. Also, this test will rule out any problems with system services.
Thank you, I am making a text database to hold user accounts for my game and I thought a text database was made with .txt files is that correct at all?
'k, you need to first decide what you'll be storing, and how you'll be storing it.

I don't know what you're calling a "text database", but all storage mechanisms are, on one level, essentially the same. What you need to figure out first is what you want to do. Then, it's a matter of choice. You can encode your data in a Lua script, "hard" code it into your source, or store it in a SQL-lite database. It's all the same, once you actually get started.
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
Quote:Original post by Sfulk
Thank you, I am making a text database to hold user accounts for my game and I thought a text database was made with .txt files is that correct at all?


erm, I don't want to crush your dreams, but .txt files are possibly the worst method of storing user accounts. A relational database is far more popular. Integrating MySQL into a C application is far easier than writing a brand new database system from scratch. For a multiplayer game you would need to have a server running somewhere, and let the clients connect to this server and log in.

Are you referring to profiles on a local machine instead? I would recommend SQLlite for this purpose. I trust you have made several simple games already or else you would not be considering something this complex.

guess the number
text based adventure
pong
pac-man
2d top down shooter <--where you should be before contemplating network multiplayer games

3d shooter
multiplayer RPG


[Edited by - shotgunnutter on November 5, 2007 11:04:37 PM]
I just wanted to see if he would actually do it. Also, this test will rule out any problems with system services.

This topic is closed to new replies.

Advertisement