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
|
#include <iostream>
//#include <string>
#include <sstream>
#include <Math.h>
using namespace std;
const string classname[4] = { "Scholar", "Knight", "Parson", "Rogue" };
const string num[4] = { "first", "second", "third", "fourth" };
class character {
private:
string name;
int klass;
int experience;
int profession;
public:
character() {
profession = 0;
}
~character() { }
void setname(string sN) { name = sN; }
void setexp(int iE) { experience = iE; }
void setclass(int iK) { klass = iK; }
void setprof(int iP) { profession = iP; }
void addexp(int iE) { experience += iE; }
string getname() { return name; }
int getclass() { return klass; }
int getexp() { return experience; }
int getprof() { return profession; }
bool setup(int i);
int level() {
return (int)ceil(experience / 2000)+1;
}
};
bool character::setup(int i = 1) {
string temp;
cout << "Now lets begin your " << num[i] << " character.\n\n";
// Name
cout << "What is your " << num[i] << " character's name? ";
getline(cin, name);
// Class
cout << "\nWhat is your " << num[i] << " character's class?\n";
for (int a = 0; a < 4; a++)
cout << " " << char(97+a) << ") " << classname[a] << "\n";
while(true) {
getline(cin, temp);
transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
if (temp.length() == 1) {
if ( (temp[0] > 96) && (temp[0] < 101) ) break;
}
}
klass = temp[0] - 97;
cout << "So " << name << " is a " << classname[klass] << ".\n";
// Experience
cout << "Very well how much experience does he have? ";
while(true) {
getline(cin, temp);
stringstream myStream(temp);
if (myStream >> experience) break;
cout << "Enter a number. \n";
}
if (experience > 40000) experience = 40000;
cout << "\n\nSo then your " << num[i] << " character is going to be " << name << " the level "
<< level() << " " << classname[klass] << ".\n";
// Check
cout << "Is this correct? ";
while(true) {
cout << "(yes/no) ";
getline ( cin, temp);
transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
if (temp == "no") {
cout << "\n\n";
return false;
}
if (temp == "yes") {
cout << "\n\n";
return true;
}
}
}
string fixlength(string s, int l) {
string temp;
if (s.length() > l) {
temp = s.substr(0, l);
} else {
temp = s.append(l - s.length(), ' ');
}
return temp;
}
int main () {
string temp;
bool mainloop = true;
character mychar[3];
cout << "Welcome to Jamie's character generator\n";
cout << "You are going to need three characters each with a profession and a starting level.\n\n";
while (mainloop) {
for (int i = 0; i < 3; i++)
if (!mychar[i].setup(i)) i--;
cout << "Characters: \n\n";
cout << "Name Profession Level\n";
cout << "-----------------------------------\n\n";
for (int i = 0; i < 3; i++) {
cout << fixlength(mychar[i].getname(), 14) << " ";
cout << fixlength(classname[mychar[i].getprof()], 14);
cout << " " << mychar[i].level() << "\n";
}
while (true) {
cout << "\n\n\nRepeat? (y/n)";
getline(cin, temp);
transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
if (temp.length() == 1) {
if (temp[0] == 'y') break;
if (temp[0] == 'n') { mainloop = false; break; }
}
}
cout << "\n\n";
}
return 0;
}
|