Before all those buttons, joysticks, controllers, mouse peripherals, and these 3D games with high graphics, textures, effects, reflections, animations, and sounds; in the first times of computers there were text-based games which you move your character by commands and it tells you (prints out) what is happening or what you should do.
A text game, also called a text-based game, is a game application that uses texts as input and output instead of bitmaps or 3D graphics. If you think these games started with computers you are wrong because Text-based games have been well played since at least the 1960s when teleprinters were interlaced with mainframe computers as a form of input, where the output was printed on paper. Text games having reached their peak popularity in that decade and the 1980s and continued as early online games into the mid-1990s. More details about Text games and the history of text-based games are well explained in Wikipedia here.
If you think Text-Based Games are old but still some players love to play them. For example one of the biggest gaming communities, Steam, has many text-based games, and also there is a good http://textadventures.co.uk/ web site which runs text adventure games as a web application.
Text games also show how scenarios and texting are important in a game. I listen to a lot of people who read the Lord of The Ring series and when they have watched the movie series, they didn’t feel the same, they found the book they read was better than all the million-dollar values of effects, scenario acts in that movie. Because books (texts) allow you to imagine by yourself, so your imagination with a simple text may give you a different pleasure. So a text game may have the same
Text games also easy to develop by a Single developer, you don’t need 3D artists, sound editors, huge investment with a high risk. You just need a good story and a simplified user interface. You may also use some UI elements like Buttons to move, examine, etc. Note that a high percentage of Text games are written in English which means there is a big missing part in other languages.
In this post, we will explain how you can build a simple Text Adventure Game. Text Adventure Games, (known as interactive fiction) are text-based games where characters, objects, places are described in the text form and the player submits simple text commands to interact with this world.
A good game should have a good scenario and a good map plan. In professional gaming games also have map generators and other tools to help game development. We can create simple maps as below with PowerPoint, Excel, paint, etc. First, we need to decide how our world will have a grid system, spaces, and objects. This map example below is generated with PowerPoint,
In this example, we will use grids with spaces and each grid will have 5 spaces, east, west, north, south, and a center. Each space will have objects like doors, windows, tables and the user will able to examine these. There will be an info text about that grid (maybe a room or a space on the outside). User will move by text commands like “Move East” or “Move to West”- User will examine with “Look East” etc.. There may be many commands but we try to as simple as possible here.
So, first, we need to define the world. You can uses classes or simply structures. In this simple example, we will use structure definition for objects to explain their name, color, material like this,
1 2 3 4 5 6 7 |
struct st_object { String name, color, material, status; struct st_object *next; }; |
You may add more features, or these features may be listed by text strings or by numbers. We will use this feature as a linked list, so we need *next object pointer address.
We need a structure definition for spaces, you can call this zones too. Each space will have these objects.
1 2 3 4 5 6 7 8 |
struct st_space { bool created; String info; st_object *objects; }; |
Now, we can defined our grid world including east, west, north, south, center
1 2 3 4 5 6 7 8 9 10 |
struct st_grid { bool created, visible; struct st_space east, west, north, south, center; }; struct st_grid world[3][3]; |
Here we imagine our word has composed with 3×3 grid ( you can imagine like they are rooms). We need to add objects to these rooms. So we need a procedure that creates a new object or adds a new object to the end of other objects in that object pointer.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
st_object *add_newobject(st_object *obj, String name, String color, String material, String status) { st_object *o=obj; if(o==NULL) { o = (struct st_object*) malloc(sizeof(st_object)); o->name = name; o->color = color; o->material = material; o->status = status; o->next=NULL; return(o); } else { while(o->next!=NULL) { o=o->next; } o->next = (struct st_object*) malloc(sizeof(st_object)); o->next->name = name; o->next->color = color; o->next->material = material; o->next->status = status; o->next->next=NULL; return(o->next); } }; |
For example, we can add a new object to the east space of grid at 0,0 , like this,
1 2 3 |
obj = add_newobject( grid[0][0].east.objects, "window", "white", "wooden", "dirty"); |
We need to setup map with these object details, So let’s write our map with a grid at 0,0 only,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
void setup_map(void) { st_object *obj; // GRID 0,0 EAST grid[0][0].east.created = true; grid[0][0].east.info = "There is a window showing a big tree"; obj = add_newobject( grid[0][0].east.objects, "window", "white", "wooden", "dirty"); obj = add_newobject( grid[0][0].east.objects, "tree", "green", "", "big"); // GRID 0,0 WEST grid[0][0].west.created = true; grid[0][0].west.info = "Door here !"; obj = add_newobject( grid[0][0].west.objects, "door", "black", "metal", "very rusty"); // GRID 0,0 CENTER grid[0][0].center.created = true; grid[0][0].center.info = " I can't move to the center, table here !"; obj = add_newobject( grid[0][0].center.objects, "door", "black", "metal", "very rusty"); } |
I am sure you can add more things to this map.
Now our character should move or look to get information. So, we should analyze input text like this,
1 2 3 4 5 6 7 8 9 10 11 12 |
analyze_text(String input) { if(input.Pos("MOVE")>0) { if(input.Pos("EAST")>0) { // move east } } } |
Finally when moving your character you should display information about that gird or space or object. Do not forget that, at the end of the game we should delete all memory allocations addressed at object pointers. Playing some few text based games as given in links above may give you more ideas.
After this step, you can add more actions, such as picking up objects, opening and closing doors or windows etc. We hope you enjoy this simple example. Not that we used String which is Unicode String in C++ Builder, that means you can develop your game in any world language. We recommend you to use some visual components i.e. TEdit component to get text and TMemo to display information, these would be better for the showing text compatibility in your language. Console applications needs more tweaks to support Unicode or Wide strings.
Get started building powerful apps with C++Builder!