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
|
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
void battlewin();
void newgame();
bool bw = false;
void RANDSEED()
{
srand (time(NULL));
}
class userloc{
private:
int x, y, maxx, maxy;
public:
void set_map(int a, int b)
{
maxx = a;
maxy = b;
cout << "Map size is: " << maxx << "x" << maxy << ".\n";
}
} map;
class mob{};
class player: public mob{
public:
int gold, hp, maxhp, attack;
string name;
void newchar()
{
hp = 100;
maxhp = 100;
attack = 10;
gold = 0;
}
void deathchk()
{
if(hp<=0)
{
cout << "You have died!\n";
cout << "Press any button to exit.";
cin.ignore();
exit(0);
}
}
void takedmg(int atk)
{
int dmg;
dmg = rand() % atk + 1;
hp-=dmg;
cout << "The mob has hit you for " << dmg << endl;
cout << "You have " << hp << "/" << maxhp << " HP." << endl;
deathchk();
}
} user;
class enemy: public mob{
public:
int goldvalue, hp, attack;
void deathchk()
{
if(hp<=0)
{
battlewin();
}
}
void takedmg(int atk)
{
int dmg;
dmg = rand() % atk + 1;
hp-=dmg;
cout << "You hit the mob for " << dmg << endl;
cout << "Mob has " << hp << " HP." << endl;
deathchk();
}
void spawn(int o, int t, int th)
{
hp = rand() % o + 1;
attack = rand() % t + 1;
goldvalue = rand() % th + 1;
}
};
void newgame()
{
user.newchar();
}
void battlewin()
{
cout << "Congratulations! You won the battle.";
cout << "You have " << user.hp << "/" << user.maxhp << " HP.\n";
bw = true;
}
void fight()
{
enemy i;
i.spawn(50, 10, 10);
while(bw==false)
{
int choice;
cout << "Press 1 to attack. ";
cin >> choice;
if(choice==1)
{
i.takedmg(user.attack);
if(bw==false)
{
user.takedmg(i.attack);
}
}
}
bw=false; // if you're here you won
user.gold+=i.goldvalue;
cout << "Mob dropped " << i.goldvalue << " gold!" << endl;
}
int main()
{
RANDSEED();
player user;
user.newchar();
cout << "Please enter your name: ";
getline(cin,user.name);
cout << "Welcome, " << user.name << " to RPG fight!\n";
fight();
cout << bw;
return 0;
}
|