C++Game DevelopmentLearn C++

Learn to Develop a Text Based Simple Adventure Game in C++ on Windows

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,

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.

Now, we can defined our grid world including east, west, north, south, center

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.

For example, we can add a new object to the east space of grid at 0,0 , like this,

We need to setup map with these object details, So let’s write our map with a grid at 0,0 only,

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,

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!

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20

What Is The Stack (std::stack) In Modern C++?

C++C++11C++14C++17C++20Learn C++

What Is The Queue (std::queue) In Modern C++?

C++C++11C++14C++17Learn C++SyntaxTemplates

What Are The Logical Operation Metafunctions In Modern C++?

C++C++14C++17C++20Learn C++

What Are The Deprecated C++14 Features In C++17?