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
|
#include "harmless.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <stdlib.h>
#include <string>
#include <functional>
#include <algorithm>
#include "RollerMk3.h"
using namespace std;
class character {
protected:
int statStam, statWill, statRef, statInt, statStr, statPercp, statAgil, statAware, _
ringVoid, ringAir, ringEarth, ringWater, ringFire;
string charName;
int setRing(int, int);
public:
character(string, vector<int>&);
~character(){};
void printStats();
friend class characterSet;
};
/************************/
/*Lots of functions here*/
/************************/
character * newCharacter();
class characterSet {
vector<int> x;
list<character*> characters;
list<character*>::iterator it;
character *temp;
string name;
int selection, dice, tempInt;
ofstream mySaveFile;
ifstream myOpenFile;
public:
void showMenu();
};
void characterSet::showMenu(){
cout << "***************************" << endl;
cout << "* Make a selection: *" << endl;
cout << "* 1) New Character *" << endl;
cout << "* 2) Delete Character *" << endl;
cout << "* 3) Save Characters *" << endl;
cout << "* 4) Open Characters *" << endl;
cout << "* 5) Print Characters *" << endl;
cout << "* 6) Roll Dice *" << endl;
cout << "* 0) Exit *" << endl;
cout << "***************************" << endl;
cout << "Menu$ ";
cin >> selection;
switch (selection){
case 1:
temp = newCharacter();
characters.push_back(temp);
it = characters.begin();
while(it != characters.end()){
(*it)->printStats();
++it;
}
break;
case 2:
cout << "Enter the character name to delete." << endl;
cout << "Delete$ ";
cin >> name;
it = characters.begin();
while(it != characters.end()){
if((*it)->charName == name){
delete *it;
it = characters.erase(it);
}
else{++it;}
}
break;
case 3:
mySaveFile.open("save.txt");
it = characters.begin();// I deleted the line under this because it's useless and long.
++it;
}
mySaveFile.close();
break;
case 4:
myOpenFile.open("save.txt");
it = characters.begin();
while(!myOpenFile.eof()){
myOpenFile >> name;
for(int i = 0; i < 9; i++){
myOpenFile >> tempInt;
x.push_back(tempInt);
}
temp = new character(name, x);
characters.push_front(temp);
x.clear();
}
myOpenFile.close();
break;
case 5:
cout << "Enter the character to print." << endl;
cout << "Print$ ";
cin >> name;
it = characters.begin();
while(it != characters.end()){
if((*it)->charName == name){
(*it)->printStats();
++it;
}
else{++it;}
}
break;
case 6:
cout << "Enter the character to roll for." << endl;
cout << "Roll$ ";
cin >> name;
it = characters.begin();
while(it != characters.end()){
if((*it)->charName == name){
dice = diceRoller((*it)->statStam, (*it)->statWill);
cout << "Rolled a " << dice << endl;
++it;
}
else{++it;}
}
break;
case 0:
exit(0);
break;
default:
cout << "Invalid choice" << endl;
break;
}
showMenu();
}
//This public function gets variables for the character name and stats from the user, creates a pointer to a new character, passes the stats, calls printStats(), and calls diceRoller().
character * newCharacter(){
vector<int> stats;
int temp;
string name, statNames[9] = {"Void Ring", "Stamina", "Will", "Reflex", "Intelligence", "Strength", "Perception", "Agility", "Awareness"};
cout << "Enter the character's:" << endl;
cout << "Name$ ";
cin >> name;
for(int i = 0; i < 9; i++){
cout << statNames[i] << "$ ";
cin >> temp;
stats.push_back(temp);
}
character *newChar = new character(name, stats);
return newChar;
}
|