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
|
#include <iostream>
#include <string>
using namespace std;
/***********************************
* Hp Class *
***********************************/
class Hp
{
public:
Hp();
Hp(int);
void setHp(int);
int getHp(int &);
void printHp();
private:
int life;
};
/***********************************
* Hp Class Function Definitions *
***********************************/
Hp::Hp()
{
life = 0;
}
Hp::Hp(int Life)
{
life = Life;
}
void Hp::setHp(int Life)
{
life = Life;
}
int Hp::getHp(int &)
{
return life;
}
void Hp::printHp()
{
cout << life;
}
/***********************************
* Character Class *
***********************************/
class Character
{
public:
Character();
~Character();
Character(int, int, int, int, int, int);
void setStats(int, int, int, int, int, int);
int getStats(int &, int &, int &, int &, int &, int &);
virtual void printStats(); // virtual function
private:
int str, dex, con, inte, wis, cha;
};
/***************************************
* Character Class Function Definitions *
***************************************/
Character::Character()
{
str = 9; dex = 8; con = 7; inte = 9; wis = 7; cha = 8;
}
Character::~Character()
{}
Character::Character(int Str, int Dex, int Con, int Inte, int Wis, int Cha)
{
str = Str; dex = Dex; con = Con; inte = Inte; wis = Wis; cha = Cha;
}
void Character::setStats(int Str, int Dex, int Con, int Inte, int Wis, int Cha)
{
str = Str; dex = Dex; con = Con; inte = Inte; wis = Wis; cha = Cha;
}
int Character::getStats(int &, int &, int &, int &, int &, int &)
{
return str, dex, con, inte, wis, cha;
}
void Character::printStats()
{
getStats(str, dex, con, inte, wis, cha);
cout << str << " strength, " << dex << " dexterity, " << con << " constitution, "
<< inte << " intelligence, " << wis << " wisdom and " << cha << " charisma";
}
/***********************************
* Monster Class *
***********************************/
class Monster: public Character
{
public:
Monster(string enemy = "", int lvl = 0, int str = 0, int dex = 0, int con = 0, int inte = 0, int wis = 0, int cha = 0, int life = 0); // constructor
void setMonster(string enemy, int lvl, int str, int dex, int con, int inte, int wis, int cha, int life);
void printStats();
private:
Character monChar; // composite object
Hp blood;
int lvl;
string enemy;
};
/*************************************
* Monster Class Function Definitions *
*************************************/
Monster::Monster(string Enemy, int Lvl, int str, int dex, int con, int inte, int wis, int cha, int life)
:monChar(str, dex, con, inte, wis, cha), blood(life)
{
enemy = Enemy;
lvl = Lvl;
}
void Monster::setMonster(string Enemy, int Lvl, int Str, int Dex, int Con, int Inte, int Wis, int Cha, int Life)
{
enemy = Enemy;
lvl = Lvl;
monChar.setStats(Str, Dex, Con, Inte, Wis, Cha);
blood.setHp(Life);
}
void Monster::printStats()
{
cout << "A " << enemy << " of level " << lvl << " may have stats of: ";
monChar.printStats();
cout << ", along with a possible ";
blood.printHp();
cout << " hit points of life.";
cout << endl;
}
/***********************************
* Stand Alone Function *
***********************************/
void doTest(Character &input)
{
input.printStats();
}
/***********************************
* Main *
***********************************/
int main()
{
Character guy; // dead character stats for 0 lv.
guy.setStats(8, 8, 8, 8, 8, 8); // basic character stats for 0 lv.
cout << "A basic character may have little life, ";
doTest(guy);
cout << "." << endl << endl;
Monster thing;
thing.setMonster("half-orc", 3, 10, 8, 8, 6, 8, 6, 32);
doTest(thing);
}
| |