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
|
#include <iostream>
#include <string>
using namespace std;
/***********************************
* 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 Functions *
***********************************/
Character::Character()
{
str = 8; dex = 8; con = 0; inte = 8; wis = 8; 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);
if(con != 0)
cout << "\nA basic DnD character for creation has " << str << " strength, " <<
dex << " dexterity, " << con << " constitution, " << inte << " intelligence, "
<< wis << " wisdom and " << cha << " charisma." << endl << endl;
else if(cha == 6)
cout << str << " strength, " << dex << " dexterity, " << con << " constitution, "
<< inte << " intelligence, " << wis << " wisdom and " << cha << " charisma." << endl << endl;
else
cout << "\nA dead basic DND character has " << str << " strength, " <<
dex << " dexterity, " << con << " constitution, " << inte << " intelligence, "
<< wis << " wisdom and " << cha << " charisma." << endl << endl;
}
/***********************************
* Monster Class *
***********************************/
class Monster
{
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); // constructor
void setMonster(string enemy, int lvl, int str, int dex, int con, int inte, int wis, int cha);
void printStats();
private:
Character monChar; // composite object
int lvl;
string enemy;
};
/***********************************
* Monster Class Functions *
***********************************/
Monster::Monster(string Enemy, int Lvl, int str, int dex, int con, int inte, int wis, int cha)
:monChar(str, dex, con, inte, wis, cha)
{
enemy = Enemy;
lvl = Lvl;
}
void Monster::setMonster(string Enemy, int Lvl, int Str, int Dex, int Con, int Inte, int Wis, int Cha)
{
enemy = Enemy;
lvl = Lvl;
monChar.setStats(Str, Dex, Con, Inte, Wis, Cha);
}
void Monster::printStats()
{
cout << "A " << enemy << " of level " << lvl << " may have stats of ";
Character::printStats();
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.
doTest(guy);
Monster thing;
thing.setMonster("half-orc", 3, 10, 8, 8, 6, 8, 6);
doTest(thing);
}
| |