Updated date:

How to Make a Text-Based Game

Akashdeep loves to create games and experiment with different software programs.

Make your vision a reality!

Make your vision a reality!

Introduction to Making Text-Based Games

Ever since you could use a computer, you've likely used them to play games. But maybe something in the creative part of your brain goes off and you're taken with the sudden urge to make a game of your own. If you've never made a game before, developing a 3D MMORPG, like World of Warcraft, may be a bit out of your league. But you can still design a text-based game while you develop your skills.

Making a game of any kind requires desire, determination and some skills. So, if you feel that you have these qualities and have confidence that you will not leave your project in the ‘underdevelopment’ phase, then you are ready to begin.

  • Note for Programmers: We will use C++ to make the game. However, concepts of C++ can be used with other programming languages too. Code snippets will be explained at the end of the article.
  • Note for Non-Programmers: Some game building tools will also be discussed (for the benefit of non-programmers). You can skip the code snippets if you want to.

Ideas for Text-Based Games

Before you start writing your program or using an online tool, you need an idea. Your idea is the first step in creating an enjoyable and somewhat unique game. Any scenario works—whether you're inspired by the thought of a dragon that has been dormant in an ancient swamp, or a schoolboy who is scared of his new teacher and needs to get out of his class with the help of nearby objects and classmates. Since you won't need to animate it, the sky is the limit.

Once you have an idea, we can proceed to the next step.

You can't rely on dialogue to make up for a disorganized story.

You can't rely on dialogue to make up for a disorganized story.

Creating and Unfolding Your Story

Your story will stem from your original idea. However amazing your idea and story might be, though, you still have to develop it in an organized way. Players should feel that you know what you are doing—don't throw out random sentences and scenes to make up for a disorganized story.

There are two ways of going about your ‘create and reveal’ process:

  1. Unfold all at once. Write down your entire story (including sub-plots, battles, monsters, traps, etc) and then reveal that story in a linear or parallel fashion in your game.
  2. Unfold while you create. In this method you let your imagination and creative juices flow at blazing speeds while you write down your story bit by bit, as it flows through your mind.

Whichever method you choose is completely up to you. You need to find out for yourself what suits your design style. Are you a more organized person who likes to plan everything out, or are you someone who just likes to go with the flow and follow wherever your fancy takes you?

Elements of Text-Based Games

The whole point of a text-based game is to make the player interact with the text and thus, the game. But how do we interact with text? There are many ways you can do so, and the more ways you include, the more interesting the game becomes.

At the beginning of your game, start with a very simple interaction. The player responds to questions posed by the game, like, “I remember your face! What is your name?” or maybe something like “Open your eyes!” and then the player replies with "opening eyes", etc.

Interaction 1. Taking Text Input

Below is a sample code for the start of a text-based adventure. In this case, we have taken the input from the user about his or her name and then we have displayed it back. This type of interaction (getting input from the user) will be used frequently during the run of the game. So it is important that you learn how to do create this interaction properly in your preferred programming language/tool. It is possible to make a game by using only this method, but then how interesting it gets depends on your imagination.

#include <iostream>
#include <conio.h>
#include <stdlib.h>
using namespace std;

int main()
{
	char name[50];
	cout << "What is your name, warrior?" << endl;
	cin.getline(name, 50);
	cout << "You better move fast, " << name << ". The goblins are attacking the city." << endl;
	cout << "\n----------------------Press any key to continue----------------------" << endl;
	_getch();
	return 0;
}
Application Run: First Part of the Game

Application Run: First Part of the Game

Interaction 2. Giving a Choice

Another way to create interactions is to give players choices and letting them choose their game-path. You can give them a choice between two weapons, the path they would like to take, or anything else that you can think of. Remember, ultimately, it's your game. Below is the code snippet to show you how the choices work, followed by the output images of the choices.

After the player makes his or her choice, you then have to unfold the storyline that follows from that choice. (The stories for all the options should be different, otherwise what's the point of choices!).

This separation of stories can be done using switch cases (in C++), which allows you to write code blocks based on your inputs and create a different experience for each choice. Below is the code snippet that shows how the switch cases work.

system("cls");
	int choiceOne_Path;
	cout << "# What would you like to do?" << endl;
	cout << "\t >> Enter '1' to follow the Chief?" << endl;
	cout << "\t >> Enter '2' to find your own path?" << endl;
	retry:
	cout << "\nEnter your choice: ";
	cin >> choiceOne_Path;
	if(choiceOne_Path == 1)
	{
		cout << "\n!!!----------------------Chapter One: Escape----------------------!!!" << endl;
		cout << "\nYou: Where are we going?" << endl;
		cout << "Chief: Soon you will know. Just follow me." << endl;
		cout << "# You run behind the chief." << endl;
	}
	else if(choiceOne_Path == 2)
	{
		cout << "\n!!!----------------------Chapter One: Escape----------------------!!!" << endl;
		cout << "\nYou: I am going to find a way out!" << endl;
		cout << "Chief: You are insane. You will get killed out there." << endl;
		cout << "You: I have my secrets and I know my way out." << endl;
		cout << "# You jump over the nearby broken fence" << endl;
		cout << "# and run off towards the City Wall." << endl;
	}
	else
	{
		cout << "You are doing it wrong, warrior! Press either '1' or '2', nothing else!" << endl;
		goto retry;
	}

	cout << "\n----------------------Press any key to continue----------------------" << endl;
	_getch();
system("cls");
	switch(choiceOne_Path)
	{
		case 1:	cout << "Write your program related to choice 1 here." << endl;
			break;
		case 2: cout << "Write your program related to choice 2 here." << endl;
			break;
	}
	cout << "\n----------------------Press any key to continue----------------------" << endl;
	_getch();

Interaction 3. Random Outcomes

One more important form of interaction is randomized outcomes. With these interactions, the players will not know what to expect and they will look forward to discovering the unknown. Random interactions could come in any form, like a treasure chest that a player finds for example. When you're designing the game, you can establish a list of possible items that the chest could contain and create a code that would randomize the object that the player finds. Below is a code snippet that shows you how to generate random numbers between 1 to 10.

The random numbers generated can be assigned to the amount of gold the players get, or maybe the probability of breaking open a door, or any other similar events that come down to 'chance' and 'uncertainty'.

#include <iostream>
#include <cstdlib>
#include <time.h>
#include <conio.h>
using namespace std;

int main()
{
    cout << "This program will print a random number." << endl;
    srand((unsigned)time(0));
    int rnum = (rand()%10) + 1;
    cout << "\nGenerated random number: " << rnum << endl;
	_getch();
    return 0;
}

Show Your Game-Making Skills Off!

These three interactions above, plus the story you make up, are almost everything that you will need to make your own text-based game. Now, it's time to get started and show your game-making skills to your friends, the online community and the world.

Text-Based Game References

Resources for Non-Programmers

  • TextAdventures
    Play text adventure games, create and share your own interactive fiction stories.
  • Playfic
    The online community that lets you write, remix, share and play interactive text-based games with the world.

Game Design Tools

  • Quest (Program to Make a Game)
    Play text adventure games, create and share your own interactive fiction stories. Non-programmers can benefit from this.
  • Quest (Tutorial)
    Learn how to use the Quest tool.
  • ADRIFT
    Non-programmers can benefit from this.
  • TADS
    The Text Adventure Development System is an Interactive Fiction authoring tool. Dive into this if you have some experience with programming.

© 2013 Akashdeep Singh

Comments

Kevin Mann from Canada on August 25, 2019:

I miss text based games, I need to find some new ones ppl are making.

Mystear Primal on July 21, 2017:

For some reason, CodeBlocks is not letting me use char name[50], and I'm a complete beginner. Says:-

error: no matching function to call to (getline,char[50], int)

Any help?

Learning Status: Started learning C++ since April, and all I've learnt till now is to make addition programs from school...and I thought learning to make CYOA games would give me a boost (not Text-Based RPG...they're wayy too complicated for me, but I still think I'm trying to make an unnecessarily big jump...

Cppbp89 on March 27, 2017:

its not letting me use system cls command for some reason, cant find anything helpful through search. copied exactly as written.

13 1 C:\Users\thoma\Documents\Untitled1.cpp [Error] expected initializer before 'system'

16 1 C:\Users\thoma\Documents\Untitled1.cpp [Error] 'cout' does not name a type

17 1 C:\Users\thoma\Documents\Untitled1.cpp [Error] 'cout' does not name a type

18 1 C:\Users\thoma\Documents\Untitled1.cpp [Error] 'cout' does not name a type

19 6 C:\Users\thoma\Documents\Untitled1.cpp [Error] found ':' in nested-name-specifier, expected '::'

19 1 C:\Users\thoma\Documents\Untitled1.cpp [Error] 'retry' does not name a type

21 1 C:\Users\thoma\Documents\Untitled1.cpp [Error] 'cin' does not name a type

22 1 C:\Users\thoma\Documents\Untitled1.cpp [Error] expected unqualified-id before 'if'

Ac++beginnerprogrammer on January 10, 2017:

You need to have a c++ code compiler to build and run test your programs

Ash on January 09, 2017:

how do you run it?

Debry on January 08, 2017:

Thanks, I really found the information useful! =)

Naruto on August 03, 2016:

looks good!

tornio on May 23, 2016:

Probably the world's largest online text-based game: https://www.torn.com

code4life on May 08, 2016:

Here's a great example of a cmd game made using python:

https://github.com/ckonjeti/TEXT-BASED-GAME/blob/m...

Joe Cartt on February 22, 2015:

The code is broken.