1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <ctime>
using namespace std;
void autoAttack(string* pm_name, int* pm_DmgMax, int* pm_DmgMin, int* phealth, int* pdefense, int* pblock, int* pm_health); //This is for the Mobs attack AI
void playerAttack(int* pplayerDmgMax, int* pplayerDmgMin, int* pm_health, string* pm_name, int* pm_healthConst, int* phealth); //This is for player attack sequence
void randomMobGen(int* pm_mobID1, int* pm_mobID2, int* phealth, int* prandomMob);
class Mob
{
public:
int m_DmgMax;
int m_mobID;
int m_DmgMin;
int m_health;
string m_name;
int m_healthConst;
void Appear();
void Health(int* phealthConst, int* pm_health);
};
void Mob::Appear()
{
cout << m_name << " HP: [" << m_health << "]\n\n" << endl;
}
void Mob::Health(int* phealthConst, int* pm_health)
{
*phealthConst = *pm_health;
}
int main()
{
//These variables represent the players stats.
int health = 100;
int charDef = 2;
int charBlock = 10;
int playerDmgMax = 8;
int playerDmgMin = 18;
Mob pirate;
pirate.m_mobID = 1;
pirate.m_DmgMin = 3;
pirate.m_DmgMax = 6;
pirate.m_name = "Pirate";
pirate.m_health = 30;
pirate.m_healthConst = 30;
srand(time(0));
Mob bandit;
bandit.m_mobID = 2;
bandit.m_DmgMin = 10;
bandit.m_DmgMax = 16;
bandit.m_name = "Bandit";
bandit.m_health = 50;
bandit.m_healthConst = 50;
Mob wildbear;
bandit.m_mobID = 3;
bandit.m_DmgMin = 11;
bandit.m_DmgMax = 20;
bandit.m_name = "Wild Bear";
bandit.m_health = 70;
bandit.m_healthConst = 70;
//Random mob battle sequences
int randomMob = rand() % (wildbear.m_mobID - pirate.m_mobID + 1) + pirate.m_mobID;
//Bandit Mob
do
{
if (randomMob == bandit.m_mobID)
bandit.Appear();
autoAttack(&bandit.m_name, &bandit.m_DmgMax, &bandit.m_DmgMin, &health, &charDef, &charBlock, &bandit.m_health);
system("PAUSE");
cout << "\n\n" << endl;
playerAttack(&playerDmgMax, &playerDmgMin, &bandit.m_health, &bandit.m_name, &bandit.m_healthConst, &health);
system("PAUSE");
cout << "\n\n" << endl;
}while (bandit.m_health > 1);
//Pirate Mob
do
{
if (randomMob == pirate.m_mobID)
pirate.Appear();
autoAttack(&pirate.m_name, &pirate.m_DmgMax, &pirate.m_DmgMin, &health, &charDef, &charBlock, &pirate.m_health);
system("PAUSE");
cout << "\n\n" << endl;
playerAttack(&playerDmgMax, &playerDmgMin, &pirate.m_health, &pirate.m_name, &pirate.m_healthConst, &health);
system("PAUSE");
cout << "\n\n" << endl;
}while (pirate.m_health > 1);
do
{
if (randomMob == wildbear.m_mobID)
wildbear.Appear();
autoAttack(&wildbear.m_name, &wildbear.m_DmgMax, &wildbear.m_DmgMin, &health, &charDef, &charBlock, &wildbear.m_health);
system("PAUSE");
cout << "\n\n" << endl;
playerAttack(&playerDmgMax, &playerDmgMin, &wildbear.m_health, &wildbear.m_name, &wildbear.m_healthConst, &health);
system("PAUSE");
cout << "\n\n" << endl;
}while (wildbear.m_health > 1);
randomMobGen(&wildbear.m_mobID, &pirate.m_mobID, &health, &randomMob);
system("PAUSE");
return 0;
}
//This function is for the mobs attack AI
void autoAttack(string* pm_name, int* pm_DmgMax, int* pm_DmgMin, int* phealth, int* pdefense, int* pblock, int* pm_health)
{
if (rand()% 100 + 1 > 100 - *pblock)
{
cout << "You block " << *pm_name << "'s attack.\n\n\n" << endl;
}
else
{
int randomAutoAttack = rand() % (*pm_DmgMax - *pm_DmgMin + 1) + *pm_DmgMin;
*phealth = *phealth - randomAutoAttack + *pdefense;
cout << *pm_name << " attacks you for " << randomAutoAttack << " point(s) of damage.\n" << endl;
cout << "You armor deflected " << *pdefense << " point(s) of damage\n" << endl;
cout << "You have " << *phealth << " HP's remaining.\n\n\n\n\n\n" << endl;
}
}
//Player attack input
void playerAttack(int* pplayerDmgMax, int* pplayerDmgMin, int* pm_health, string* pm_name, int* pm_healthConst, int* phealth)
{
int randomAutoAttack = rand() % (*pplayerDmgMax - *pplayerDmgMin + 1) + *pplayerDmgMin;
*pm_health = *pm_health - randomAutoAttack;
cout << "You attack " << *pm_name << " for " << randomAutoAttack << " point(s) of damage.\n" << endl;
cout << *pm_name << " has " << *pm_health << "HP's ramining.\n\n\n" << endl;
if (*pm_health < 1)
{
cout << "\n\n\n" << *pm_name << " has been slain!\n" << endl;
*pm_health = *pm_healthConst;
*phealth = 100;
cout << "Your health has been replenished.\n\n\n" << endl;
}
}
void randomMobGen(int* pm_mobID1, int* pm_mobID2, int* phealth, int* prandomMob)
{
if (*phealth == 100)
*prandomMob = rand() % (*pm_mobID1 - *pm_mobID2 + 1) + *pm_mobID2;
}
|