Scooter7
June 11th, 2008, 02:00 AM
Hi,
I'm learning C++, and practicing by writing a basic text rpg. I'm using Arch Linux.
At one point, the player encounters an NPC, who then speaks to the player. I want the program to pause and wait for the player to hit a key to continue, so that they have time to read what the NPC says before moving on.
From what I've done in the past, I figured cin.get(); would work, but it doesn't seem to have any effect.
Here is the code I have so far:
//--------------------------------------
//| A simple(?) text rpg |
//| By Vertimyst |
//| (http://www.darknet-fusion.co.cc) |
//--------------------------------------
#include <iostream>
using namespace std;
char cfname[50]; // Character's first name
char clname[50]; // Character's last name
char cgender; // Character's gender
char crace[50]; // Character's race
int experience; // (Exp)erience points
int exp_cap; // Exp cap - can grow over time
int level; // Level - grows as you gain exp
int exp(); // The function that manages exp
int main()
{
exp_cap = 1000; // Set the experience cap
cout << "Shadowgate Productions Presents...\n";
cout << "A simple(?) text rpg\n";
cout << "Written, directed, and programmed...\n";
cout << "Entirely by ME (Vertimyst)!\n";
cout << "\n";
cout << "So I'm assuming you want to start playing.\n";
cout << "You can do that (and currently only that), so let's proceed.\n";
cout << "\n";
cout << "First, enter your character's first name (Must be less than 50 characters): ";
cin >> cfname;
cout << "\nAnd now, your character's last name (same limit as before): ";
cin >> clname;
cout << "\nExcellent, now your gender (M/F): ";
cin >> cgender;
cout << "\nVery good, and now your race (50 characters or less\n";
cout << "and I'm too lazy to make a list, so just make something up, Human is as good as any): ";
cin >> crace;
cout << "\n";
cout << "Okay, here is your (currently basic) character sheet:\n";
cout << "Name: " << cfname << " " << clname << endl;
cout << "Gender: " << cgender << endl;
cout << "Race: " << crace << endl;
cout << "\n";
cout << "Good, now that we have that over with, I'll send you\n";
cout << "into the world. If you arrive with your limbs intact, you may\n";
cout << "meet someone helpful. Good luck!\n";
cout << "\n";
cout << "You wake up (although you didn't know you were sleeping O.o), and\n";
cout << "you see a mage. Yea, a mage... dunno his name yet.\n";
cout << "\n";
cout << "Mage:\n";
cout << "\"Hello, hello. I shall give you experience!\"\n";
cin.get();
experience = 20;
exp();
return 0;
}
int exp()
{
cout << "You have recieved " << experience << " experience points!\n";
if (experience == 1000)
{
cout << "You have gained a level! DING! GRATZ ^^;\n";
(level++);
cout << "You are now level: " << level << "!\n";
experience = 0;
}
if (experience < 1000)
{
cout << "You need " << (exp_cap - experience) << " more experience points (out of " << experience << ") to level up. Keep it up!\n";
}
}
Also (and this isn't really a problem, I just find it odd), I've read that without using namespace std;, I have to put std:: before every cout and such. However, I had been using them before without the namespace std.
Any suggestions?
I'm learning C++, and practicing by writing a basic text rpg. I'm using Arch Linux.
At one point, the player encounters an NPC, who then speaks to the player. I want the program to pause and wait for the player to hit a key to continue, so that they have time to read what the NPC says before moving on.
From what I've done in the past, I figured cin.get(); would work, but it doesn't seem to have any effect.
Here is the code I have so far:
//--------------------------------------
//| A simple(?) text rpg |
//| By Vertimyst |
//| (http://www.darknet-fusion.co.cc) |
//--------------------------------------
#include <iostream>
using namespace std;
char cfname[50]; // Character's first name
char clname[50]; // Character's last name
char cgender; // Character's gender
char crace[50]; // Character's race
int experience; // (Exp)erience points
int exp_cap; // Exp cap - can grow over time
int level; // Level - grows as you gain exp
int exp(); // The function that manages exp
int main()
{
exp_cap = 1000; // Set the experience cap
cout << "Shadowgate Productions Presents...\n";
cout << "A simple(?) text rpg\n";
cout << "Written, directed, and programmed...\n";
cout << "Entirely by ME (Vertimyst)!\n";
cout << "\n";
cout << "So I'm assuming you want to start playing.\n";
cout << "You can do that (and currently only that), so let's proceed.\n";
cout << "\n";
cout << "First, enter your character's first name (Must be less than 50 characters): ";
cin >> cfname;
cout << "\nAnd now, your character's last name (same limit as before): ";
cin >> clname;
cout << "\nExcellent, now your gender (M/F): ";
cin >> cgender;
cout << "\nVery good, and now your race (50 characters or less\n";
cout << "and I'm too lazy to make a list, so just make something up, Human is as good as any): ";
cin >> crace;
cout << "\n";
cout << "Okay, here is your (currently basic) character sheet:\n";
cout << "Name: " << cfname << " " << clname << endl;
cout << "Gender: " << cgender << endl;
cout << "Race: " << crace << endl;
cout << "\n";
cout << "Good, now that we have that over with, I'll send you\n";
cout << "into the world. If you arrive with your limbs intact, you may\n";
cout << "meet someone helpful. Good luck!\n";
cout << "\n";
cout << "You wake up (although you didn't know you were sleeping O.o), and\n";
cout << "you see a mage. Yea, a mage... dunno his name yet.\n";
cout << "\n";
cout << "Mage:\n";
cout << "\"Hello, hello. I shall give you experience!\"\n";
cin.get();
experience = 20;
exp();
return 0;
}
int exp()
{
cout << "You have recieved " << experience << " experience points!\n";
if (experience == 1000)
{
cout << "You have gained a level! DING! GRATZ ^^;\n";
(level++);
cout << "You are now level: " << level << "!\n";
experience = 0;
}
if (experience < 1000)
{
cout << "You need " << (exp_cap - experience) << " more experience points (out of " << experience << ") to level up. Keep it up!\n";
}
}
Also (and this isn't really a problem, I just find it odd), I've read that without using namespace std;, I have to put std:: before every cout and such. However, I had been using them before without the namespace std.
Any suggestions?