PlayaFoSho
08-30-2009, 04:39 AM
Hey I cant think right now and I need help with a calculation in my code... Ill post the whole function( its suppose to be a simple fight scene and is not finished. I need to figure out the "Phit" part first before I can finish it up.
void Fight()
{
int enemylife;
int playerlife;
int Phit;
string answer;
enemylife = 100;
playerlife = 100;
Phit = 0;
cout << " You encountered a giant serpent do you want to 'run away' or 'fight'?" <<endl;
cout << ">";
cin >> answer;
if (answer == "fight")
{
while (enemylife > 0 && playerlife > 0)
{
if (itemlocations[0] == 99)
{
bonusDamage = 20;
}
enemylife = enemylife - ((rand() % 5) + bonusDamage);
playerlife = playerlife - (rand() % 25);
long i;
for (i=1; i<=100000000;i++)
{
}
Phit = Phit +100 - enemylife ;
cout << "You have hit the Serpent for "<< Phit << "The Serpent has " << enemylife << " health remaining" << endl;
cout << endl;
if (enemylife > 0)
{
cout << " You have " << playerlife << " health remaining" << endl;
cout << endl;
}
}
if (enemylife <=0)
{
cout << " You have defeated the giant serpent!!!" << endl;
monsterDefeated = 1;
}
else
{
cout << " You have been defeated... you suck" << endl;
cin.get();
exit(0);
}
}
else
{
locationindex = 3;
}
cin.get();
}
it obviously doesnt work the way I want it to. I want the "Phit" to show how much I have hit the enemy. ive tried a few different things but I cant seem to get it to work correctly.
Thanks
void Fight()
{
int enemylife;
int playerlife;
int Phit;
string answer;
enemylife = 100;
playerlife = 100;
Phit = 0;
cout << " You encountered a giant serpent do you want to 'run away' or 'fight'?" <<endl;
cout << ">";
cin >> answer;
if (answer == "fight")
{
while (enemylife > 0 && playerlife > 0)
{
if (itemlocations[0] == 99)
{
bonusDamage = 20;
}
enemylife = enemylife - ((rand() % 5) + bonusDamage);
playerlife = playerlife - (rand() % 25);
long i;
for (i=1; i<=100000000;i++)
{
}
Phit = Phit +100 - enemylife ;
cout << "You have hit the Serpent for "<< Phit << "The Serpent has " << enemylife << " health remaining" << endl;
cout << endl;
if (enemylife > 0)
{
cout << " You have " << playerlife << " health remaining" << endl;
cout << endl;
}
}
if (enemylife <=0)
{
cout << " You have defeated the giant serpent!!!" << endl;
monsterDefeated = 1;
}
else
{
cout << " You have been defeated... you suck" << endl;
cin.get();
exit(0);
}
}
else
{
locationindex = 3;
}
cin.get();
}
it obviously doesnt work the way I want it to. I want the "Phit" to show how much I have hit the enemy. ive tried a few different things but I cant seem to get it to work correctly.
Thanks