fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4. #include <vector>
  5. #include <algorithm>
  6. #include <functional>
  7. using namespace std;
  8.  
  9. ///////////////////////////////
  10. // Declarations //
  11. ///////////////////////////////
  12. void banner (string name, string type = "\\", int size = 40);
  13. class character{
  14. public:
  15. character(); // Constructor
  16. bool operator== (character); // use when comparing init of objects
  17. bool operator< (character);
  18. bool operator> (character);
  19. string getname ()const ; // return name of object
  20. string getname ();
  21. int getinit () const; // return init of object
  22. int getinit ();
  23. void set_init (int a); // set init of object to 'a'
  24. void heal_full(); // max out hp and 0 nl dam
  25. void heal(int amt); // modify hp by given amount
  26. void heal_nl (int amt); // heal nl dam by given amount
  27. void dam_nl (int amt); // give nl dam by given amount, checks for disabled or unconscious state.
  28. int getHP(); // return current hp
  29. int getnlDam(); // return nl dam
  30. void SetnMob (character* nmob); // Sets next mob
  31. character* GetnMob (); // Gets the address of next mob.
  32.  
  33. private:
  34. string name; // name of character
  35. int mHP; // max hit points
  36. int HP; // current hit points
  37. int nlDam; // amount of non lethal damage object currently has
  38. int init; // initiative of character
  39. character* nextMob; // points to next mob to iterate to
  40. };
  41. class encounter{
  42. public:
  43. encounter (character*, int); // Constructor
  44. void listFull ();
  45. private:
  46. int ENEMIES; // number of enemies in this encounter
  47. character enemy[]; // array of all enemies in encounter
  48. character* holding[]; // array of pointers to all mobs currently holding turn
  49. character* player; // pointer to array of player mobs
  50. character* firstMob; // pointer to highest init mob
  51. void setInits (character ary[], int arraySize);
  52. character* sortAryLL (character* ary[], int arraySize);
  53. };
  54. void rebuildCharArray (character arry[], int size){
  55. delete[] arry;
  56. arry = new character[size];
  57. }
  58. ///////////////////////////////
  59. // Main Function //
  60. ///////////////////////////////
  61. int main(){
  62. int input = 1;
  63. string select;
  64. int PLAYERS;
  65. banner ("COMBAT HELPER", "=");
  66. cout << "Welcome to D&D Combat Helper.\n"
  67. << "Lets begin by adding all players.\n"
  68. << "How many players are there?";
  69. cin >> PLAYERS;
  70. character* player = new character[PLAYERS];
  71.  
  72.  
  73. //////////////////////////////////
  74. // MAIN MENU //
  75. //////////////////////////////////
  76.  
  77. while (input != 0)
  78. {
  79. banner ("MAIN MENU");
  80.  
  81. cout << "\nPlease select from the following options:\n"
  82. << "1. (Re)build all players\n"
  83. << "2. Start a new encounter\n"
  84. << "3. Reset all player's health\n"
  85. << "0. Quit\n";
  86. cin >> input;
  87. switch (input)
  88. {
  89. case 1: //New players
  90. {
  91. break;
  92. };
  93. case 2: //new fight
  94. {
  95. encounter crnt_enco (player, PLAYERS);
  96. break;
  97. };
  98. case 3: //Heal players
  99. {
  100. cout << "All players restored to full health";
  101. break;
  102. };
  103. case 0: // quit
  104. {
  105. cout << "Thank you for using D&D Combat Helper.\nHave a nice day.";
  106. break;
  107. };
  108. default: // incorrect input
  109. {
  110. cout << "Invalid selection, please try again.";
  111. break;
  112. };
  113. }; // Switch end
  114. }; //While end
  115.  
  116. }
  117. ///////////////////////////////
  118. // Misc Function Definitions //
  119. ///////////////////////////////
  120. void banner (string name, string type, int size){
  121. cout << endl;
  122. for (int i=0; i < size; i++) { cout << type; };
  123.  
  124. cout << "\n" << type << type
  125. << setw (((size-4)/2) + ((name.size())/2) /*- (name.size()%2)*/ ) << name
  126. << setw (((size-4)/2) - ((name.size())/2) + (name.size()%2))
  127. << type << type << "\n";
  128.  
  129. for (int i=0; i < size; i++) { cout << type; };
  130. cout << endl;
  131. };
  132. ///////////////////////////////
  133. // character class //
  134. ///////////////////////////////
  135. character::character() {
  136. string select;
  137. cout << "\nCreating new character.\nWhat is their name?";
  138. cin >> name;
  139. cout << "\nWhat is their max HP?";
  140. cin >> mHP;
  141. cout << "Are they currently injured? (y/n)";
  142. cin >> select;
  143. if (select == "y"){
  144. cout << "What is their current HP?";
  145. cin >> HP;
  146. cout << "How much non-lethal damage do they currently have?";
  147. cin >> nlDam;
  148. }
  149. else{
  150. HP = mHP;
  151. nlDam = 0;
  152. };
  153. init = 1;
  154. };
  155. bool character::operator== (character b) {return init == b.init;}
  156. bool character::operator> (character b) {return init > b.init;}
  157. bool character::operator< (character b) {return init < b.init;}
  158. string character::getname () const { return name; }
  159. string character::getname () { return name; }
  160. int character::getinit () const { return init; }
  161. int character::getinit () { return init; }
  162. void character::set_init (int a) { init = a; }
  163. void character::heal_full() {
  164. HP = mHP;
  165. nlDam = 0;
  166. };
  167. void character::heal(int amt) { HP += amt; }
  168. void character::heal_nl (int amt) {
  169. if (nlDam < 0)
  170. {
  171. nlDam -= (amt - nlDam);
  172. cout << name << "now has "<< nlDam << " non lethal damage" << endl;
  173. }
  174. else if (nlDam >= 0)
  175. { cout << name << " has no non lethal damage. No action required" << endl;};
  176.  
  177. }
  178. void character::dam_nl (int amt) {
  179. nlDam += amt;
  180. if ( nlDam == HP )
  181. {
  182. cout << name << " is now Staggered, and can only take one standard action.";
  183. }
  184. else if (nlDam > HP)
  185. {
  186. cout << name << " is now unconscious.";
  187. }
  188. }
  189. int character::getHP() { return HP; }
  190. int character::getnlDam() { return nlDam; }
  191. void character::SetnMob(character* nmob) { nextMob = nmob;}
  192.  
  193. ///////////////////////////////
  194. // encounter class //
  195. ///////////////////////////////
  196. encounter::encounter (character players_in[], int PLAYERS ){
  197. banner ("NEW ENCOUNTER", "*");
  198. character* high;
  199. player = players_in;
  200. cout<< "How many enemies?";
  201. cin >> ENEMIES;
  202. enemy[ENEMIES];
  203. cout<< "Roll for initiative and input for each person or enemy:"
  204. << "\n(Don't worry about ties, they will be resolved shortly)";
  205. setInits(player, PLAYERS); // get players init
  206. setInits(enemy, ENEMIES); // get enemies init
  207. character* highestPlayer = sortAryLL(player&, PLAYERS);
  208. character* highestEnemy = sortAryLL(enemy&, ENEMIES);
  209. for (int i = 0; i < PLAYERS; i++) { // sort players by init w/ linked list
  210. if (player[i].getinit() > high->getinit() ) {
  211.  
  212. }
  213. else if (player[i].getinit() == high->getinit() ) {
  214.  
  215. }
  216. else if (player[i].getinit() < high->getinit() ) {
  217.  
  218. }
  219. }
  220. for (int i = 0; i < ENEMIES; i++) { // sort enemies by init w/ linked list
  221. if (enemy[i].getinit() > high->getinit() ) {
  222.  
  223. }
  224. else if (enemy[i].getinit() == high->getinit() ) {
  225.  
  226. }
  227. else if (enemy[i].getinit() > high->getinit() ) {
  228.  
  229. }
  230. }
  231. for ( int i = 0 , j = 0 ; i < PLAYERS && j < ENEMIES ; ) { //sort all mobs w/ linked list
  232. if ( player[i] > enemy[j] ) {
  233. player[i].SetnMob( &enemy[j] );
  234. i++;
  235. }
  236. else if ( player[i] > enemy[j] ) {
  237. enemy[j].SetnMob( &player[i] );
  238. j++;
  239. }
  240. else if ( player[i] == enemy[j] ) {
  241. bool a = false;
  242. while (a == false) {
  243. cout<< player[i].getname() << " and " << enemy[j].getname()
  244. << "are tied. Please roll again and select higher init."
  245. << "\n1. " << player[i].getname()
  246. << "\n2. " << enemy[j].getname();
  247. int select;
  248. cin >> select;
  249. if (select == 1) {
  250. player[i].SetnMob( &enemy[j] );
  251. i++;
  252. a = true;
  253. }
  254. else if (select == 2) {
  255. enemy[j].SetnMob( &player[i] );
  256. j++;
  257. a = true;
  258. }
  259. else {
  260. cout << "Invalid selection, Please try again";
  261. }
  262. }
  263. }
  264. }
  265. }
  266. void encounter::setInits (character ary[], int arraySize) {
  267. for ( int i = 0; i < arraySize; i++) {
  268. int in;
  269. cout << ary[i].getname() << ": ";
  270. cin >> in;
  271. ary[i].set_init(in);
  272. }
  273. }
  274. character* encounter::sortAryLL (character* ary[], int arraySize) {
  275. int iteration = 0;
  276. int high = 0;
  277. int i = 0;
  278. while (iteration < arraySize) {
  279. if (ary[i]->getinit() < ary[high]->getinit() ) {
  280.  
  281. }
  282. else if (ary[i]->getinit() > ary[high]->getinit() ) {
  283. ary[high]->SetnMob(ary[i]);
  284. }
  285. else if ( ary[i]->getinit() == ary[high]->getinit() ) {
  286.  
  287. }
  288. }
  289. }
  290.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In constructor ‘encounter::encounter(character*, int)’:
prog.cpp:202:18: warning: statement has no effect [-Wunused-value]
     enemy[ENEMIES];
                  ^
prog.cpp:207:49: error: expected primary-expression before ‘,’ token
     character* highestPlayer = sortAryLL(player&, PLAYERS);
                                                 ^
prog.cpp:208:47: error: expected primary-expression before ‘,’ token
     character* highestEnemy = sortAryLL(enemy&, ENEMIES);
                                               ^
prog.cpp:207:16: warning: unused variable ‘highestPlayer’ [-Wunused-variable]
     character* highestPlayer = sortAryLL(player&, PLAYERS);
                ^
prog.cpp:208:16: warning: unused variable ‘highestEnemy’ [-Wunused-variable]
     character* highestEnemy = sortAryLL(enemy&, ENEMIES);
                ^
prog.cpp: In member function ‘character* encounter::sortAryLL(character**, int)’:
prog.cpp:289:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
stdout
Standard output is empty