New Games!

Ok hi everyone! I have already tried posting and looking around on the forums about this but I still need help. So basically I am coming from batch to cplusplus and wanted to hear about a few basic commands to make a text based game.
When ever I watch a tut it takes me somewhere else and off my objective. I just need to know some basic commands... I know some but not all. This is for console applications.
A clear screen command.
A "Press any key to continue" command.
If you chose something it goes to a different story:
Do you want to adventure or get wood?
Types in "Get Wood"
and it goes to a different story.
So that is currently all I need thank you!
I can help. what kind of help do you need?
closed account (1v5E3TCk)
I am working on a text based RPG game but ıt is not easy as it looks.
But if you don't want to have all RPG stuff like level, skills, equipments etc..

you only need to know functioıns, strings, if statements.

Your to-do list:

-Learn functions
-learn strings
-learn if statements
-make functuion for every place
-tie the functions with if statements
-congrats
Last edited on
Try out the tutorial on this site. It does a good job of covering all the basics. I too am working on a story driven console game. Even on a most primitive level I still use object oriented programming. This can be learned from this sites lessons.

To do the things you want I used to use system commands like...

system ("PAUSE");
system ("CLS");

But I stop this practice as it is bad form. Now when I want a pause I use...
1
2
cout << "Press enter to continue." << endl;
cin.get();


somethimes I have to double the "cin.get();" line to pause.
closed account (1v5E3TCk)
@Manga

instead of double cin.get(); use cin.ignore(); before cin.get();
That was easy enough... thanks senhor.
closed account (1v5E3TCk)
What is your game about? I would be happy to help you with the game.
well I don't have much done yet, but basically its an outer space adventure. you start off with a single person space craft, which you can modify with different weapons and such. Then you can eventually buy larger spaceship and take on crew members, which will also effect you ships performance. Right now I am shooting for 10 different missions, once completed the game is won.
for the pause command, try this function, it's most likely safe.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#ifdef max()	//	windows.h library defines a function-like macro with the name of max()
#define _TEMP_MACRO_() max()	//	store the predefined macro in a new one
#undef max()	//	undefine the problamatic macro.
#endif
void pause( const char* prompt )
{
    std::cin.clear() ; // clear failed/error states of the stream if they are set

    if( std::cin.rdbuf()->in_avail() ) // if there are any characters in the input buffer
        std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ) ; // throw them away

    std::cout << prompt ;
    std::cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ) ;
}
#ifdef _Temp_MACRO_()
#define max() _TEMP_MACRO_()	// restore the max() macro.
#undef _TEMP_MACRO_()	// undefine the temporary macro.
#endif  


about the clear screen command, there's no such function in native C++ that does this job, MSDN descriped one in terms of windows API, but when i tried it, it didn't clear the screen, and some unknown phrases appeared, i still use system("cls");.

system() is described to be bad as its behavior is based on calling another program, maybe built into the OS, maybe not.
this behavior is hated by some antivirus software, and might cause some problems.
another thing is, it looks to me like OS depending, the same phrase can have multiple meanings on different operating systems.
some command defined in windows, isn't even defined in Linux.


EDIT - i forgot to add the code for pause, lol :).
i published the code into a news post, but looks like the admins might have deleted it for unknown purpose.
Last edited on
closed account (N36fSL3A)
If you're going to make maps make each map a class, and then use a map manager class with a vector of maps to handle them.

Don't make each map a function.

BTW - Going from the console to graphical apps isn't that much of a leap ;)
Its not a true clear screen but works to create the illusion.
1
2
3
for(int i=0; i<100; i++) {
cout << endl;
}
Rechard3 wrote:
some command defined in windows, isn't even defined in Linux.

This is why most experienced programmers say to avoid system() calls if you can. Otherwise you will have to code more to make workarounds for each OS. For example, clearing a terminal in Windows is "cls" but in Linux it is simply "clear".
closed account (1v5E3TCk)
I think he dont know enough to make classes or other staff. He only needs to leaarn what he have to know for making a simple text based game, it means he didnt learn anything until now. So basic requirments for a text based game is function and if statements.

And what do you mean with map? Places in text based RPG games arent map, there is only a little description.
closed account (N36fSL3A)
Well then I think he should simply follow his tutorials. He'll learn if statements and input soon enough.
Topic archived. No new replies allowed.