• Register
search
Log In

Computers can be used for different uses, we can use computers for playing games. By hearing the word game we start thinking about great animation and graphics but there is a category of games “text-based games” in which we only use text. Text-based games are fun. In this article we are going to discuss them and how to create them. I am assuming that you have some knowledge of programming. We will be using C++ for programming in this article.

 

Ideas

Before creating the game we need ideas for the game. Idea is the first step towards the creation of the game. The game should be enjoyable and somehow unique. You can create your own story for the game just imagine and write down your story.

 

You can tell your story in two ways. First is unfolding at once and the second is unfolding it while you create.

  • All at once. Write your story then reveal it in a linear or parallel way in your game.

  • While you create. In this method you let your imagination flow as fire while you write your story bit by bit.

 

Choosing the method for telling the story is completely your call. In text-based games we have to make the player interact with the game. Start with the simple question or a simple sentence. Remember not to throw random sentences since it will make the player uncomfortable.

 

Step 1 Taking Text Input

In this step we have to take the input from the player. We have to interact and take input from the user so many times in this game. So it is important to learn how to do that. For example in a game, you are asking the player for his/her name and then you will be returning the name.

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

 

Step 2 Giving a Choice

For interacting with the player you can also give him a choice and let them choose. Like you can give them a choice for weapon and language. After the player makes his choice, then you have to unfold the storyline from that choice.

We can use switch cases in c++ for separation of the stories.

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();

 

Step 3 Random Outcomes

Another important way of interaction is giving the random outcomes to the player. This method will generate interest and curiosity in players. Like giving them random awards. Like the number of gold coins given to the player.


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

 

These methods of interaction and the storyline of yours will definitely make the game interesting. You are all set to make a text-based game by yourself. Go get started and show your skills.

posted May 27 in c++ 100 points