Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › Programming Tutorials › How to make a simple text based game in c++

How to make a simple text based game in c++

Posts 1–14 of 14 · Page 1 of 1
VvITylerIvV
VvITylerIvV
How to make a simple text based game in c++
well. This is my first tutorial on c++, normally I can write good tutorials but it is my first on this topic so it may not be the best.

The code for the simple text based game we will be creating is as follows

in a console application I have created the following two files with the following code within them.

functions.h[php]
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

void Felse(){
cout << "that wasn't an answer...\n";
}

void test (string a, char c[40], char e[40] ){
if(a == "y"){
cout << c << endl;
}
else if(a == "n"){
cout << e << endl;
}
else { Felse(); }
}[/php]

functions.cpp
[php]#include "functions.h"

int main(){
string b;
char d[40] = "you answered yes";
char f[40] = "you answered no";

cout << "please enter y/n"<< endl;
getline (cin,a);
test(a, c, e);
}[/php]
If you put these in your compiler, it will be a VERY simple text based game.

If this makes sense to you, you shouldn't be reading this. If it doesn't make sense, well you came to the right place. I hope.



Lets take this apart, piece by piece.

The first things we notice in functions.h is [php]#include <iostream>
#include <string>
#include <sstream>[/php]

What this is saying, is to include the iostream.h file which includes input/output streams (cout/cin etc)

to include string, so we can use the string variable which is quite handy and to include sstream so we can use the getline (cin,a); which is far less glitchy the cin >>

as we continue down the code we see [php]using namespace std;[/php]

this handy piece of code makes it so we don't have to add std:: before just about everything. I like that .

Now we get to the confusing part of it... [php]void Felse(){
cout << "that wasn't an answer...\n";
}[/php]

Well, if this were to be void Felse; it would just be a variable with no type declared. But, it's a function with no type declared because its void Felse(){}

what this does, is it makes the code within the '{' '}' run whenever you call Felse();

which MEANS when we calle Felse(); it will basically be replaced by cout <<"that wasn't an answer...\n";

and THAT is what functions is all about (kinda)

[php]void test (string a, char c[40], char e[40] ){
if(a == "y"){
cout << c << endl;
}
else if(a == "n"){
cout << e << endl;
}
else { Felse(); }
}[/php]

now, its void test(string a, char c[40], char e[40]){} now, the strings and chars inside the () are replaced by whatever variables we use when we call this function in our code... more on that later.

Then we have the basic if statements, and what have you.

What you may or may not have noticed, is [php]else { Felse(); }[/php] Yes, thats right. I didn't wanna right cout <<... so I used the Felse function. Really handy and cleans up the code a lot.

Alright, now to expain functions.cpp
[php]#include "functions.h"

int main(){
string b;
char d[40] = "you answered yes";
char f[40] = "you answered no";

cout << "please enter y/n"<< endl;
getline (cin,a);
test(a, c, e);
}[/php]

You may be wondering, WHAT THE HELL1!?!?! but don't worry.

I included function test.h which included everything else we need (chain reaction type thing) By including our own header file, the .cpp file now contains all the code from that header file. Which means, we can use the functions in our header file in our .cpp file. Make sense?

Well, I basically have three variables, a string and two chars. char c is "you answered yes"

char e is "you answered no"

string a has nothing assigned to it yet.

We then use the cout function to display enter y/n then the getline function to get whatever was on that line, take that and put it into a.


get line works a little like cin, just a bit differently. It only works for strings, so you can't do

[php]
int a;
getline (cin,a);

/ have to do

string a;
getline (cin,a);

[/php]

and it just inputs whatever was on the line into the variable. quite simple really, not as buggy as cin.

weeellll now we arrive at the functions.

[php]
test(b, d, f);
[/php]

remember how we made the function
[php]
void test (string a, char c[40], char e[40] )
[/php]

well, see how they both have three variables within the brackets? thats important.

when you call a function, whatever is in the brackets replaces any other instance of what is in the brackets when you create the function.


soo, by using test(b,d,f);

we are changing the

[php]
void test (string a, char c[40], char e[40] ){
if(a == "y"){
cout << c << endl;
}
else if(a == "n"){
cout << e << endl;
}
else { Felse(); }
}
[/php]
function too

[php]
void test (string b, char d[40], char f[40] ){
if(b == "y"){
cout << d << endl;
}
else if(b == "n"){
cout << f << endl;
}
else { Felse(); }
}
[/php]

If this STILL does not make sense, please PM me and I'll explain further.


Please, if there is any way I could clean this up please PLEASE tell me. I want to help, not confuse.
#1 · 16y ago
Auxilium
Auxilium
Cool
I wouldn't call them Text Based games. Just Console Applications. Text based games would be like Games for a cp/m where its like an rpg just with text
#2 · edited 16y ago · 16y ago
VvITylerIvV
VvITylerIvV
Quote Originally Posted by Koreans View Post
Cool
I wouldn't call them Text Based games. Just Console Applications. Text based games would be like Games for a cp/m where its like an rpg just with text
Well, using this you can make a text based game. All you gotta do is re-use the code that is shown here.
#3 · 16y ago
Auxilium
Auxilium
It'd be a little more than that.
Most text based games were like you choose the direction to go and you get another string of text.
And you'd need to incorporate stuff like classes
#4 · 16y ago
VvITylerIvV
VvITylerIvV
Quote Originally Posted by Koreans View Post
It'd be a little more than that.
Most text based games were like you choose the direction to go and you get another string of text.
And you'd need to incorporate stuff like classes
shh don't scare me with classes yet every time I do anything with classes something happens to me... Last time I saw a code with classes in them my mother came home.

But no, you could make an entire RPG text based game without using any functions or classes. It just makes the code A LOT simpler and A LOT cleaner to read.

And yes, this is all you need to make a simple game, perhaps not a fighting game but a lifestyle game.

"Hi there, this is the bus. Where would you like today?
1. Victoria
2. Duncan
3. The Beach"

3

"Alright, off to the beach we goo"

"A lady wearing a yellow poka dot bikini walks up to you."

"Hi, I was wondering if you've seen my shoes anywhere... I've seem to have lost them"

"1. yes"
"2. no"


2

"Oh, sorry to bother you"

Later on I may add in how to make an RPG text based game but I'm kinda half asleep right now.
#5 · 16y ago
Kallisti
Kallisti
You can't make them without Classes or functions. Period.
#6 · 16y ago
Lonely Tedy Bear
Lonely Tedy Bear
Quote Originally Posted by Kallisti View Post
You can't make them without Classes or functions. Period.
dam dude you spam so much you had 300 like 1 day ago , also you should of got yor 1333 ban damit, we need a brake from you /
#7 · 16y ago
Kallisti
Kallisti
Quote Originally Posted by Lonely Tedy Bear View Post
dam dude you spam so much you had 300 like 1 day ago , also you should of got yor 1333 ban damit, we need a brake from you /
I just came back from my 1337 ban today ******
and i came back to mpgh this summer with 455 in mid july.

jealous ****** code leecha that enters leeched code in vbotw is jealous
#8 · edited 16y ago · 16y ago
Lonely Tedy Bear
Lonely Tedy Bear
Quote Originally Posted by Kallisti View Post


I just came back from my 1337 ban today ******
and i came back to mpgh this summer with 455 in mid july.

jealous ****** code leecha that enters leeched code in vbotw is jealous
hmm it's very hard to understand you. Maybe you should go learn English better
#9 · 16y ago
Kallisti
Kallisti
I hope you can understand this

I just came back from my 1337 post ban TODAY
And i came back to MPGH mid july, after i quit during school.

And
You are a jealous ****** who leeches code, then enters the leeched code into VBOTW. Easy enough to understand? I think you are a foreigner who cant read properly


LEECH MORE CODE
#10 · edited 16y ago · 16y ago
AC
aclonegeek
Quote Originally Posted by Kallisti View Post
I hope you can understand this

I just came back from my 1337 post ban TODAY
And i came back to MPGH mid july, after i quit during school.

And
You are a jealous ****** who leeches code, then enters the leeched code into VBOTW. Easy enough to understand? I think you are a foreigner who cant listen read properly


LEECH MORE CODE
sarry wat can u lurn too speek englash!

No but seriously I still don't think he understands. It took him awhile on the VBOTW thread.
#11 · 16y ago
Kallisti
Kallisti
I have a couple things to say about this from what i read,

1. [php]void felse;[/php] you said would be a variable with no type. you cant do that in C++

2. I wanna know how [php]getline(cin,shit);[/php] is 'far' less glitchy than [php]cin >> shit;[/php]
#12 · 16y ago
VvITylerIvV
VvITylerIvV
Quote Originally Posted by Kallisti View Post
I have a couple things to say about this from what i read,

1. [php]void felse;[/php] you said would be a variable with no type. you cant do that in C++

2. I wanna know how [php]getline(cin,shit);[/php] is 'far' less glitchy than [php]cin >> shit;[/php]


Yeah, I meant to say "which is not allowed..." on the variable with no type.

And I've found that cin >> shit; makes it combine all the lines and doesn't wait for input. Getline works perfectly for me, for other people I've recommended it for so I prefer to use it.


And btw
Quote Originally Posted by Kallisti View Post
You can't make them without Classes or functions. Period.

you absolutely can... it's just a LOT more code... like 100s to maybe even hundreds of thousands more lines... depending on how big of a game it would be.
#13 · edited 16y ago · 16y ago
Kallisti
Kallisti
Quote Originally Posted by VvITylerIvV View Post
Yeah, I meant to say "which is not allowed..." on the variable with no type.

And I've found that cin >> shit; makes it combine all the lines and doesn't wait for input. Getline works perfectly for me, for other people I've recommended it for so I prefer to use it.


And btw



you absolutely can... it's just a LOT more code... like 100s to maybe even hundreds of thousands more lines... depending on how big of a game it would be.
1. [php]cin >>[/php] does wait for input,

Code:
Enter number
(waits till number entered and enter is press)
2. If youre making a REAL game, that would cause spaghetti code and unwanted behavior. And not hundreds or thousands. If you were making a REAL game without classes and functions, code would be close to a million (or more) lines longer. And youd still deal with the spaghetti code
#14 · 16y ago
Posts 1–14 of 14 · Page 1 of 1

Post a Reply

Similar Threads

  • How to make a simple game in VB2008By trevor206 in Visual Basic Programming
    0Last post 17y ago
  • Text - Based - GameBy ktalin91 in WarRock - International Hacks
    7Last post 19y ago
  • Text-based-gamesBy tigerjr38 in Hack Requests
    0Last post 18y ago
  • Text based game hacksBy Justin4240 in General Hacking
    7Last post 17y ago
  • Text Based Game Hack..By Tayyab in Hack Requests
    0Last post 18y ago

Tags for this Thread

None