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

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

		case 1:	cout << "Write your program related to choice 1 here." << endl;
		case 2: cout << "Write your program related to choice 2 here." << endl;
	cout << "\n----------------------Press any key to continue----------------------" << endl;

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;
    int rnum = (rand()%10) + 1;
    cout << "\nGenerated random number: " << rnum << endl;
    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.

Questions & Answers


      0 of 8192 characters used
      Post Comment
      • whatageek profile image

        Kevin Mann 

        7 weeks ago from Canada

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

      • profile image

        Mystear Primal 

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

      • profile image


        2 years 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


        2 years ago

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

      • profile image


        2 years ago

        how do you run it?

      • profile image


        2 years ago

        Thanks, I really found the information useful! =)

      • profile image


        3 years ago

        looks good!

      • profile image


        3 years ago

        Probably the world's largest online text-based game:

      • profile image


        3 years ago

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

      • profile image

        Joe Cartt 

        4 years ago

        The code is broken.


      This website uses cookies

      As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

      For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at:

      Show Details
      HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
      LoginThis is necessary to sign in to the HubPages Service.
      Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
      AkismetThis is used to detect comment spam. (Privacy Policy)
      HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
      HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
      Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
      CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
      Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
      Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
      Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
      Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
      Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
      Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
      VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
      PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
      Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
      MavenThis supports the Maven widget and search functionality. (Privacy Policy)
      Google AdSenseThis is an ad network. (Privacy Policy)
      Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
      Index ExchangeThis is an ad network. (Privacy Policy)
      SovrnThis is an ad network. (Privacy Policy)
      Facebook AdsThis is an ad network. (Privacy Policy)
      Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
      AppNexusThis is an ad network. (Privacy Policy)
      OpenxThis is an ad network. (Privacy Policy)
      Rubicon ProjectThis is an ad network. (Privacy Policy)
      TripleLiftThis is an ad network. (Privacy Policy)
      Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
      Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
      Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
      Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
      ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
      Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)
      ClickscoThis is a data management platform studying reader behavior (Privacy Policy)