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
|
#include <iostream>
#include <string>
using namespace std;
class Character
{
private:
int Str;
int Dex;
int Con;
int Int;
int Wis;
int Cha;
int roll;
string charType;
public:
Character(int str, int dex, int con, int intel, int wis, int cha,
const string &chType) :
Str(str), Dex(dex), Con(con), Int(intel), Wis(wis), Cha(cha),
roll(0), charType(chType)
{}
void Roll()
{
cout << "enter the number you rolled for " << charType<< '\n';
cin >> roll;
}
void displayStats() //in order to cout in must be declared
{
cout << "Saving throws for " << charType << " are \n";
cout << "Str = " << roll + Str << "\n";
cout << "Dex = " << roll + Dex << "\n";
cout << "Con = " << roll + Con << "\n";
cout << "Int = " << roll + Int << "\n";
cout << "Wis = " << roll + Wis << "\n";
cout << "Cha = " << roll + Cha << "\n";
}
void setStr(int value) //void set can be called out in int main
{
Str = value;
}
void setDex(int value) //title void set___ is how it is found by anil
{
Dex = value;
}
void setCon(int value)
{
Con = value;
}
void setInt(int value)
{
Int = value;
}
void setWis(int value)
{
Wis = value;
}
void setCha(int value)
{
Cha = value;
}
};
class Ranger : public Character
{
public:
Ranger() : Character(3,3,-1,0,2,1,"ranger") {}
};
class Sorcerer : public Character
{
public:
Sorcerer(): Character(1,2,3,3,0,-1, "sorcerer") {}
};
class Bard : public Character
{
public:
Bard() : Character(0,2,1,1,0,3, "bard") {}
};
class Warlock : public Character
{
public:
Warlock(): Character(-1,2,1,2,0,3, "warlock") {}
};
int
main()
{
Ranger player1;
player1.Roll();
player1.displayStats();
Sorcerer player2;
player2.Roll();
player2.displayStats();
Bard player3;
player2.Roll();
player3.displayStats();
Warlock player4;
player2.Roll();
player4.displayStats();
return 0;
}
| |