//Trying to take the structure as a argument so we could select which stats to be picked up to //initialize the combat against the specific entity.
#include <iostream>
#include <random>
class Combat {
public:
struct Player {
int Health = 100;
int Attack = 10;
int Magic = 10;
} p;
struct Wisp {
int Health = 40;
int Attack = 30;
int Magic = 5;
} e;
int Running = 1;
int Choice;
char Crit_Choice;
int Player_Crit_Roll;
int Player_Damage;
int Player_Healroll;
int Player_Heal;
int Run_Roll;
int Enemy_Crit_Roll;
int Enemy_Damage;
int Enemy_Healroll;
int Enemy_Heal;
int Enemy_Roll;
int Enemy_Numb_Check = 0;
int Player_Magic_Attack;
int Enemy_Magic_Attack;
int Status_Checker;
public:
int getRandomNumber(int min, int max) {
Seed the random number generator std::random_device rd;
std::mt19937 gen(rd());
Define the distribution std::uniform_int_distribution<> dis(min, max);
Generate and return the random number return dis(gen);
}
void Fight(struct x) {
while ((p.Health > 0) && (Running = 1)) {
x.Health = 100;
while (x.Health > 0) {
std::cout << "You have " << p.Health
<< " Health and your enemy has " << x.Health
<< " Health what would you do ? n 1.Attack n 2. "
"Heal n 3.Magic n 4.Runn";
std::cin >> Choice;
switch (Choice) {
case 1:
{
Player_Crit_Roll = getRandomNumber(0, 100);
if (Player_Crit_Roll >= 80) {
Player_Damage = p.Attack * 4;
std::cout
<< "You managed to hit a critical hit dealing "
<< Player_Damage << " dmgn";
} else {
Player_Damage = p.Attack * 2;
std::cout << "You hit " << Player_Damage
<< " dmgn";
}
x.Health = x.Health - Player_Damage;
} break;
case 2:
Player_Healroll = getRandomNumber(1, 15);
Player_Heal = Player_Healroll * p.Magic;
p.Health = p.Health + Player_Heal;
std::cout << "You have managed to heal by "
<< Player_Heal << "Heal";
break;
case 3:
case 4:
Run_Roll = getRandomNumber(0, 10);
if (Run_Roll < 7) {
std::cout
<< "Running Failed, Enemy caught up to you";
} else {
std::cout << "You ran away successfully";
Running = 0;
}
break;
default:
std::cout << "Enter Valid input";
break;
}
Enemy Turn // if (x.Health > 70)
{
Enemy_Roll = 0;
}
else if ((x.Health > 30) && (x.Health < 70)) {
Enemy_Roll = 0;
}
else if ((x.Health > 0) && (x.Health < 30)) {
Enemy_Roll = 2;
}
else {
std::cout << "Another Enemy Defeatedn";
Enemy_Numb_Check = Enemy_Numb_Check + 1;
std::cout << "You have defeated " << Enemy_Numb_Check
<< " enemies so farn";
break;
}
switch (Enemy_Roll) {
case 0:
Enemy_Crit_Roll = getRandomNumber(0, 100);
if (Enemy_Crit_Roll >= 80) {
Enemy_Damage = x.Attack * 4;
p.Health = p.Health - Enemy_Damage;
std::cout << "Enemy managed to hit you with a "
"critical hit dealing "
<< Enemy_Damage << " dmgn";
}
else {
Enemy_Damage = x.Attack * 2;
p.Health = p.Health - Enemy_Damage;
std::cout << "Enemy Hit you for " << Enemy_Damage
<< " dmgn";
}
break;
case 2:
Enemy_Healroll = getRandomNumber(1, 15);
x.Health = x.Health + Enemy_Healroll;
std::cout << "Enemy Healed itself by " << Enemy_Healroll
<< " hpn";
break;
default:
break;
}
}
}
}
};
int main() {
int Checker;
Combat p1;
std::cout << "Which Enemy would you like to fight 1.Wisp" std::cin >>
Checker switch (Checker)
case 1 :
p1.Fight(Wisp)
std::cout
<< " You have exited the simulation. I hope you Enjoyed";
return 0;
}
//I thought taking struct x would take as a temporary structure and when used function as //fight(wisp) it will take Wisp stats and intialize combat
New contributor
Harshil Surti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1