Mobile GamesFirst Person ShootersAction-Adventure GamesRPGsSimulation GamesConsolesMMORPGsSports GamesFighting GamesStrategy GamesHorror GamesClassic GamesPuzzle GameseSports

How to Make a Text-Based Game

Updated on February 3, 2015

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 are have these qualities and have confidence that you will not leave your project in the ‘under development’ 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 to think of an idea. You need to think of an idea that will make your game enjoyable and somewhat unique. This part you need to do on your own. You can think of any scenario, ranging from 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's the limit.

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

Creating and Unfolding the Story of your Game

Your idea will be the foundation for your main plot. 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 and not just throwing our random sentences and scenes.

There are two ways of going about your ‘creating and revealing’ 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 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.

In the start there is a very simple interaction. The player simply 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 One: 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 is based 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 Two: Giving a Choice

Another way to create interactions, is to give players choices and letting them choose their game-path. You can give them 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.

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();
Output Screen: Choice 1
Output Screen: Choice 1
Output Screen: Choice 2
Output Screen: Choice 2
What happens when you enter a wrong choice number.
What happens when you enter a wrong choice number.

Interaction Two, continued

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");
	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 Three: Random Outcomes

One more important form of interaction is randomized outcomes. With these kinds of interactions, the players will not know what to expect and they will look forward to discovering the unknown. Random interactions could come in any number of forms, 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.

#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;
}

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

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 get started and show your game-making skill to your friends, to online community or to the world.

Comments

    0 of 8192 characters used
    Post Comment

    • profile image

      Joe Cartt 2 years ago

      The code is broken.

    • profile image

      code4life 14 months ago

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

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

    • profile image

      tornio 14 months ago

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

    • profile image

      Naruto 11 months ago

      looks good!

    • profile image

      Debry 6 months ago

      Thanks, I really found the information useful! =)

    • profile image

      Ash 6 months ago

      how do you run it?

    • profile image

      Ac++beginnerprogrammer 6 months ago

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

    • profile image

      Cppbp89 4 months ago

      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'

    • profile image

      Mystear Primal 5 days ago

      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...

    Click to Rate This Article