I'm trying to make a 1v1 battle sim which will make random values and generate a random health for my opponent. This should run the attacks in turns till someone hits 0 health. I can sue the current while loop to test 1 sort of, but it doesnt repeat. And if I split it into 2 while loops to test both it runs infinite times. Any help please? :s
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <ctime>
int main()
{
usingnamespace std;
int health = 100;
int health2;
int selection;
int damage;
int damage2;
string name;
system("COLOR 1f");
cout << "Welcome to my 1v1 battle simulator" << endl;
cout << "Your character has " << health << " health." << endl << endl;
srand(time(0));
selection = 1 + (rand()%4);
switch (selection)
{
case 1: health2 = rand()%100;
cout << "Your oponent is called Peter."
<< "" << endl // Enter the Description inside the ""
<< "He has a total health of " << health2 << "." << endl;
name = "Peter";
break;
case 2: health2 = rand()%100;
cout << "Your oponent is called Gavin."
<< "" << endl // Enter the Description inside the ""
<< "He has a total health of " << health2 << "." << endl;
name = "Gavin";
break;
case 3: health2 = rand()%100;
cout << "Your oponent is called Rich."
<< "" << endl // Enter the Description inside the ""
<< "He has a total health of " << health2 << "." << endl;
name = "Rich";
break;
case 4: health2 = rand()%100;
cout << "Your oponent is called Kyle."
<< "" << endl // Enter the Description inside the ""
<< "He has a total health of " << health2 << "." << endl;
name = "Kyle";
break;
}
cout << endl << "Let the battle begin!" << endl
<< "You go first!" << endl << endl;
damage = rand()%100;
damage2 = rand()%100;
while ( damage < health2)
{
if ( 0 < health)
{
//damage = rand()%100;
cout << "You have done " << damage << " damage to " << name << "." << endl;
health2 = health2 - damage;
cout << endl << name << " now has " << health2 << " health left." << endl;
}
if ( 0 >= health2)
{
cout << name << " has died! You have won the battle!" << endl;
}
if ( 0 < health2)
{
//damage2 = rand()%100;
cout << endl << "It is now " << name << "'s turn to hit." << endl
<< name << " did " << damage2 << " damage to you.";
health = health - damage2;
cout << endl << "You now have " << health << " health left." << endl;
}
if ( 0 >= health)
{
cout << "You have died! " << name << " has won the battle!" << endl;
}
}
system("pause");
return 0;
}