![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Expert Programmer
|
change:
#include <iostream.h> to: #include <iostream> add: using namespace std; after the #includes.
__________________
Join us at #programmingforums @ irc.freenode.net! My software never has bugs. It just develops random features.
|
|
|
|
|
|
#12 | |
|
Professional Programmer
|
Whats the difference between adding using namespace std; and using <iostream> instead of <iostream.h>? I always thought it was just wether you prefer it or not..
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
|
|
#13 |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
#include <iostream.h> is considered deprecated
![]() |
|
|
|
|
|
#14 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
...
char mName[15];
...
...
cout << "First of all, you must name your character: ";
cin >> mName;
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#15 | |
|
Professional Programmer
|
I dont know wether i want to allow multiple names.. but i have noticed that when trying before and i will probably use a string later on just for more experience.
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
|
|
#16 | |
|
Professional Programmer
|
Im currently working on the fighting system, im enjoying it as usual.. except ive been working on it for about 2 hours straight so now i need a little break, might as well let people see it, not like anyone will since its probably 7:30 for most people and they are mostly sleeping but here it is anyways, tell me what you think!
#include <iostream.h>
#include "mersenne.cpp"
#include <time.h>
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
double health, mana, speed, experience;
int32 seed = time(0);
TRandomMersenne rg(seed);
int reset = 0, mStrength = 0, mIntelligence, mAgility, mPoints = 20, mEncounter = 0;
char mName[15];
void Battle()
{
int mDecision = 0;
mEncounter = rg.IRandom(1,4);
if (mEncounter == 1) {
cout << "You have encountered a poisonous frog!\nWould you like to fight or run?\n1. Fight \n2. Run \nDecision: ";
cin >> mDecision;
if (mDecision == 1){
cout << "You have decided to fight, the battle will begin shortly"; cout << "."; wait (1); cout << "."; wait (1); cout << ".\n";
}
else {
cout << "You have escaped from the enemy!\n";
}
}
if (mEncounter == 2) {
cout << "You have encountered a fanged rabbit!\nWould you like to fight or run?\n1. Fight \n2. Run \nDecision: ";
cin >> mDecision;
if (mDecision == 1){
cout << "You have decided to fight, the battle will begin shortly"; cout << "."; wait (1); cout << "."; wait (1); cout << ".\n";
}
else {
cout << "You have escaped from the enemy!\n";
}
}
if (mEncounter == 3) {
cout << "You have encountered a seagul!\nWould you like to fight or run?\n1. Fight \n2. Run \nDecision: ";
cin >> mDecision;
if (mDecision == 1){
cout << "You have decided to fight, the battle will begin shortly"; cout << "."; wait (1); cout << "."; wait (1); cout << ".\n";
}
else {
cout << "You have escaped from the enemy!\n";
}
}
if (mEncounter == 4) {
cout << "You have encountered a king cobra!\nWould you like to fight or run?\n1. Fight \n2. Run \nDecision: ";
cin >> mDecision;
if (mDecision == 1){
cout << "\nYou have decided to fight, the battle will begin shortly"; cout << "."; wait (1); cout << "."; wait (1); cout << ".\n";
}
else {
cout << "You have escaped from the enemy!\n";
}
}
}
int main()
{
cout << "~=~Welcome to Monster fighter version 0.01!~=~\n\nThe basics of the game will be created in this portion of the text based game \ncalled 'Monster Fighter'. Although the name of the game may vary during the\nprocess, I would still appreciate you call it by the appropriate name.\n\nPress enter proceed to the character creation process...";
cin.get();
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
system("cls");
cout << "First of all, you must name your character: ";
cin >> mName;
do {
mPoints = 20;
system("cls");
cout << "You have " << mPoints << " left.\n";
cout << endl << "Enter strength: ";
do {
cin.clear ();
if (cin.sync ());
mStrength = 0;
cin >> mStrength;
system("cls");
if (!cin.good ()) cout << "You must enter an integer: ";
else if (mStrength >= mPoints - 2 || mStrength < 1) cout << "Enter a value between 1 and " << mPoints - 2 << ": ";
} while ( mStrength > mPoints - 2 || mStrength < 1 );
mPoints = mPoints - mStrength;
system("cls");
cout << "You have " << mPoints << " left.\n";
cout << endl << "Enter agility: ";
do {
cin.clear ();
if (cin.sync ());
cin >> mAgility;
system("cls");
if (!cin.good ()) cout << "You must enter an integer: ";
else if (mAgility > mPoints -1 || mAgility < 1) cout << "Enter a value between 1 and " << mPoints - 1 << ": ";
} while ( mAgility > mPoints - 1 || mAgility < 1 );
mPoints = mPoints - mAgility;
system("cls");
cout << "You have " << mPoints << " left.\n";
cout << endl << "Enter intelligence: ";
do {
cin.clear ();
if (cin.sync ());
cin >> mIntelligence;
system("cls");
if (!cin.good ()) cout << "You must enter an integer: ";
else if (mIntelligence >= mPoints || mIntelligence < 1) cout << "Enter a value between 1 and " << mPoints << ": ";
} while ( mIntelligence > mPoints || mIntelligence < 1 );
mPoints = mPoints - mIntelligence;
cout << "You have " << mPoints << " left.";
system ("cls");
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
struct attributes{
int health;
int mana;
int speed;
int damage;
};
attributes Player_1;
Player_1.health = mStrength * 14;
Player_1.mana = mIntelligence * 12;
Player_1.speed = mAgility * 18;
cout << "Congratulations, you have created your character successfully!\n\nHere is your character:\n\nCharacter name: " << mName << "\nStrength: " << mStrength << "\nAgility: " << mAgility << "\nIntelligence: " << mIntelligence << "\n";
cout << "Health: " << Player_1.health << "\nMana: " << Player_1.mana << "\nAttack/Move speed:" << Player_1.speed << "\n\n\n\n";
cout << "Enter either 1 to reselect hero skill points, or 0 to finish.";
do {
cin >> reset;
if ( reset > 1 || reset < 0 ) {
system ("CLS");
cout << "To reselect hero skill points enter\n1 = Yes, reselect skills.\n0 = No, they're fine.\n\n";
}
} while ( reset > 1 || reset < 0 );
system ("CLS");
}while ( reset == 1 );
Battle();
system("PAUSE");
struct monsters{
int health;
int32 damage;
};
monsters frog; frog.health = 16; frog.damage = rg.IRandom(5,10);
monsters rabbit; rabbit.health = 25; rabbit.damage = rg.IRandom(8,15);
monsters seagul; seagul.health = 49; seagul.damage = rg.IRandom(12,19);
monsters cobra; cobra.health = 62; cobra.damage = rg.IRandom(17,22);
monsters farmer; farmer.health = 83; farmer.damage = rg.IRandom(26,38);
cin.get();
}
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
|
|
#17 | |
|
Professional Programmer
|
Ok, so ive been working on the fighting system for a while now and decided that it needs to be clean.. so i re-did it and now it looks like this
. I'm pleased with the outcome so far but there is still (Fortunately) a lot to complete till you can compile this and actually get dirty for as much as the console version will be worth.EDIT: I also forgot to mention names can now have spaces in them, for example: John Doe, Alexander Graham Bell, Fruity tooty..ect #include <iostream.h>
#include "mersenne.cpp"
#include <time.h>
#include <string.h>
using std::string;
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
double mHealth, mMana, mSpeed, experience;
int32 seed = time(0);
TRandomMersenne rg(seed);
int reset = 0, mStrength = 0, mIntelligence, mAgility, mPoints = 20, mEncounter = 0, monstDamage, monstHealth, Damage;
string mName;
string Monst;
void Battle()
{
Damage = mStrength + rg.IRandom(8,13);
int mDecision = 0;
mEncounter = rg.IRandom(1,4);
if (mEncounter == 1) {
Monst = "poisonous frog";
monstDamage = rg.IRandom(5,10);
monstHealth = 34;
}
if (mEncounter == 2) {
Monst = "fanged rabbit";
monstDamage = rg.IRandom(8,15);
monstHealth = 58;
}
if (mEncounter == 3) {
Monst = "seagul";
monstDamage = rg.IRandom(12,19);
monstHealth = 83;
}
if (mEncounter == 4) {
Monst = "king cobra";
monstDamage = rg.IRandom(17,22);
monstHealth = 112;
}
cout << "You have encountered a " << Monst << "\nWould you like to fight or run?\n1. Fight \n2. Run \nDecision: ";
cin >> mDecision;
if (mDecision == 1){
cout << "You have decided to fight, the battle will begin shortly"; cout << "."; wait (1); cout << "."; wait (1); cout << ".\n"; system("cls");
cout << "You have damaged the " << Monst << " for " << Damage << " hp.\n";
}
else {
cout << "You have escaped from the enemy!\n";
}
}
int main()
{
cout << "~=~Welcome to Monster fighter version 0.01!~=~\n\nThe basics of the game will be created in this portion of the text based game \ncalled 'Monster Fighter'. Although the name of the game may vary during the\nprocess, I would still appreciate you call it by the appropriate name.\n\nPress enter proceed to the character creation process...";
cin.get();
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
system("cls");
cout << "First of all, you must name your character: ";
getline (cin,mName);
do {
mPoints = 20;
system("cls");
cout << "You have " << mPoints << " left.\n";
cout << endl << "Enter strength: ";
do {
cin.clear ();
if (cin.sync ());
mStrength = 0;
cin >> mStrength;
system("cls");
if (!cin.good ()) cout << "You must enter an integer: ";
else if (mStrength >= mPoints - 2 || mStrength < 1) cout << "Enter a value between 1 and " << mPoints - 2 << ": ";
} while ( mStrength > mPoints - 2 || mStrength < 1 );
mPoints = mPoints - mStrength;
system("cls");
cout << "You have " << mPoints << " left.\n";
cout << endl << "Enter agility: ";
do {
cin.clear ();
if (cin.sync ());
cin >> mAgility;
system("cls");
if (!cin.good ()) cout << "You must enter an integer: ";
else if (mAgility > mPoints -1 || mAgility < 1) cout << "Enter a value between 1 and " << mPoints - 1 << ": ";
} while ( mAgility > mPoints - 1 || mAgility < 1 );
mPoints = mPoints - mAgility;
system("cls");
cout << "You have " << mPoints << " left.\n";
cout << endl << "Enter intelligence: ";
do {
cin.clear ();
if (cin.sync ());
cin >> mIntelligence;
system("cls");
if (!cin.good ()) cout << "You must enter an integer: ";
else if (mIntelligence >= mPoints || mIntelligence < 1) cout << "Enter a value between 1 and " << mPoints << ": ";
} while ( mIntelligence > mPoints || mIntelligence < 1 );
mPoints = mPoints - mIntelligence;
cout << "You have " << mPoints << " left.";
system ("cls");
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
mHealth = mStrength * 14;
mMana = mIntelligence * 12;
mSpeed = mAgility * 18;
cout << "Congratulations, you have created your character successfully!\n\nHere is your character:\n\nCharacter name: " << mName << "\nStrength: " << mStrength << "\nAgility: " << mAgility << "\nIntelligence: " << mIntelligence << "\n";
cout << "Health: " << mHealth << "\nMana: " << mMana << "\nAttack/Move speed:" << mSpeed << "\n\n\n\n";
cout << "Enter either 1 to reselect hero skill points, or 0 to finish.";
do {
cin >> reset;
if ( reset > 1 || reset < 0 ) {
system ("CLS");
cout << "To reselect hero skill points enter\n1 = Yes, reselect skills.\n0 = No, they're fine.\n\n";
}
} while ( reset > 1 || reset < 0 );
system ("CLS");
}while ( reset == 1 );
Battle();
system("PAUSE");
cin.get();
}
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
|
|
#18 | |
|
Professional Programmer
|
I've decided to pause work on the actual game base, and work on a secondary component of the game... which is the monsters database, which will look something like this
class monster {
int experience;
int health;
int damage;
char name;
public:
void set_health(int hp) { health = hp; }
int get_health() { return health; }
void set_experience(int exp) { experience = exp; }
int get_experience() { return experience; }
void set_damage(int dmg) { damage = dmg; }
int get_damage() { return damage; }
};
class frog : public monster {
string name;
public:
void set_name(string mon) { name = mon; }
string get_name() { return name; }
void show();
};
void frog::show()
{
cout << get_name() << "\n";
cout << get_damage() << "\n";
cout << get_experience() << "\n";
cout << get_health() << "\n";
}I will be building on that so that it includes all the monsters and all the details of the monsters. Heres the source again, as you can see the fight system has been taken out since it will be redone to include the new flexible monster database. #include <iostream.h>
#include <Monsters.h>
#include "mersenne.cpp"
#include <time.h>
#include <string.h>
using std::string;
using namespace std;
void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}
double mHealth, mMana, mSpeed, experience;
int32 seed = time(0);
TRandomMersenne rg(seed);
int main()
{
/*
frog frog1;
frog1.set_health(34);
frog1.set_damage(5);
frog1.set_experience(22); Just a test for the monster database
frog1.set_name("monkey");
frog1.show();
*/
int reset = 0;
rect.mEncounter = 0;
rect.mPoints = 20;
cout << "~=~Welcome to Monster fighter version 0.01!~=~\n\nThe basics of the game will be created in this portion of the text based game \ncalled 'Monster Fighter'. Although the name of the game may vary during the\nprocess, I would still appreciate you call it by the appropriate name.\n\nPress enter proceed to the character creation process...";
cin.get();
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
system("cls");
cout << "First of all, you must name your character: ";
getline (cin,rect.mName);
do {
rect.mPoints = 20;
system("cls");
cout << "You have 20 skill points to create your character.\n";
cout << endl << "Enter strength: ";
do {
cin.clear ();
if (cin.sync ());
rect.mStrength = 0;
cin >> rect.mStrength;
system("cls");
if (!cin.good ()) cout << "You must enter an integer: ";
else if (rect.mStrength >= rect.mPoints - 2 || rect.mStrength < 1) cout << "Enter a value between 1 and " << rect.mPoints - 2 << ": ";
} while ( rect.mStrength > rect.mPoints - 2 || rect.mStrength < 1 );
rect.mPoints = rect.mPoints - rect.mStrength;
system("cls");
cout << "You have " << rect.mPoints << " left.\n";
cout << endl << "Enter agility: ";
do {
cin.clear ();
if (cin.sync ());
cin >> rect.mAgility;
system("cls");
if (!cin.good ()) cout << "You must enter an integer: ";
else if (rect.mAgility > rect.mPoints -1 || rect.mAgility < 1) cout << "Enter a value between 1 and " << rect.mPoints - 1 << ": ";
} while ( rect.mAgility > rect.mPoints - 1 || rect.mAgility < 1 );
rect.mPoints = rect.mPoints - rect.mAgility;
system("cls");
cout << "You have " << rect.mPoints << " left.\n";
cout << endl << "Enter intelligence: ";
do {
cin.clear ();
if (cin.sync ());
cin >> rect.mIntelligence;
system("cls");
if (!cin.good ()) cout << "You must enter an integer: ";
else if (rect.mIntelligence >= rect.mPoints || rect.mIntelligence < 1) cout << "Enter a value between 1 and " << rect.mPoints << ": ";
} while ( rect.mIntelligence > rect.mPoints || rect.mIntelligence < 1 );
rect.mPoints = rect.mPoints - rect.mIntelligence;
cout << "You have " << rect.mPoints << " left.";
system ("cls");
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
/* Skill points Skill points Skill points Skill points Skill points Skill points Skill points Skill points */
mHealth = rect.mStrength * 14;
mMana = rect.mIntelligence * 12;
mSpeed = rect.mAgility * 18;
cout << "Congratulations, you have created your character successfully!\n\nHere is your character:\n\nCharacter name: " << rect.mName << "\nStrength: " << rect.mStrength << "\nAgility: " << rect.mAgility << "\nIntelligence: " << rect.mIntelligence << "\n";
cout << "Health: " << mHealth << "\nMana: " << mMana << "\nAttack/Move speed:" << mSpeed << "\n\n\n\n";
cout << "Enter either 1 to reselect hero skill points, or 0 to finish.";
do {
cin >> reset;
if ( reset > 1 || reset < 0 ) {
system ("CLS");
cout << "To reselect hero skill points enter\n1 = Yes, reselect skills.\n0 = No, they're fine.\n\n";
}
} while ( reset > 1 || reset < 0 );
system ("CLS");
}while ( reset == 1 );
system("PAUSE");
cin.get();
}
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
|
|
#19 |
|
Hobbyist Programmer
|
Have you tried compiling this? you have
#include <Monsters.h> shouldnt this be "Monsters.h" instead? <include> is used for system includes, ones that are in the include path. "include" will look in the directory where your program is someone correct me if i'm wrong
__________________
#programmingforums relay - http://thegupstudio.com/cgi-bin/pforelay.cgi freelance scripts - http://ryanguthrie.com/index.html |
|
|
|
|
|
#20 | |
|
Professional Programmer
|
i didnt even know that, thanks.. now i dont have to put the monster.h in the compiler folder anymore :o
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|