Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <time.h>
  4. #include <dos.h>
  5. #include "Manager.h"
  6. #include "Soldier.h"
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. srand ( time(NULL) );
  13. string str;
  14. Team team;
  15. Manager manager;
  16. manager.info();
  17. //getline(cin, str);
  18. //manager.getFunction(str);
  19. cout << "Game over!" << endl;
  20. return 0;
  21. }
  22.  
  23. #ifndef MANAGER_H
  24. #define MANAGER_H
  25. #include <iostream>
  26. #include <string>
  27. #include <cstring>
  28. #include <stdio.h>
  29. #include <malloc.h>
  30.  
  31. using namespace std;
  32.  
  33. class Team;
  34.  
  35. class Manager
  36. {
  37. private:
  38. typedef struct
  39. {
  40. string name;
  41. int *adress;
  42. } DB;
  43. DB funcBase[19];
  44. string param = "Nike";
  45. public:
  46. Manager(){
  47. cout << "Welcome to the GAME!nEnter your command to your army!" << endl;
  48. funcBase[1].name = "addSoldier";
  49. //funcBase[1].adress = &Team::addSoldier();
  50. }
  51. int getFunction(string strng){
  52.  
  53. char *str = new char[strng.length()];
  54. strcpy(str, strng.c_str());
  55. char *pos = strchr(str, ':');
  56. int piece_length = pos-str;
  57. char *str_action = new char[piece_length];
  58. strncpy(str_action,str, piece_length);
  59. str_action[piece_length] = '';
  60. cout << str_action << endl;
  61.  
  62. delete [] str;
  63. delete [] str_action;
  64. }
  65. int info()
  66. {
  67. cout << &Team::addSoldier();
  68. }
  69.  
  70. protected:
  71. };
  72. #endif // MANAGER_H
  73.  
  74. #ifndef SOLDIER_H
  75. #define SOLDIER_H
  76.  
  77.  
  78. class Team
  79. {
  80. private:
  81. int i;
  82. int soldier_count = 0;
  83. int power;
  84. int money = 700;
  85. typedef struct
  86. {
  87. string name;
  88. int strength;
  89. int speed;
  90. } Soldier;
  91. Soldier Soldiers[19];
  92.  
  93. protected:
  94. public:
  95. Team(){
  96. addSoldier("Andrew");
  97. addSoldier("Sanchez");
  98. addSoldier("Cody");
  99. addSoldier("Bob");
  100. }
  101. int update_power()
  102. {
  103. i = 0;
  104. power = 0;
  105. for(i; i < soldier_count; i++)
  106. {
  107. int newpower = (Soldiers[i].strength*Soldiers[i].speed)/100;
  108. power = power + newpower;
  109.  
  110. }
  111. }
  112. int addSoldier(string inputName){
  113. if(soldier_count >= 20){cout << "Sorry you can't add more than 20 soldiers in your team:(" << endl; }
  114. else
  115. {
  116. if(money < 100) {cout << "You have no money to add new soldier to your team!" << endl;}
  117. else
  118. {
  119. soldier_count++;
  120. Soldiers[soldier_count-1].strength = rand()%90 +30;
  121. Soldiers[soldier_count-1].speed = rand()%400 + 100;
  122. Soldiers[soldier_count-1].name = inputName;
  123. money -= 100;
  124. update_power();
  125. }
  126. }
  127. }
  128. int getInfo(){
  129. cout << "Soldiers in your team right now:" << endl << "There are " << soldier_count << " soldiers in your team" << endl;
  130. for(i = 0; i<soldier_count; i++){
  131. cout<< "#" << i << " Name:" << Soldiers[i].name << " Strength:" << Soldiers[i].strength<< " Speed:" << Soldiers[i].speed<<endl;
  132. }
  133. cout<< "Total POWER is " << power << endl << "You have: " << money << "$" << endl;
  134. }
  135. int killSolder(int id)
  136. {
  137. if(id<=soldier_count && id>=0)
  138. {
  139. Soldiers[id].name = Soldiers[soldier_count-1].name;
  140. Soldiers[id].speed = Soldiers[soldier_count-1].speed;
  141. Soldiers[id].strength = Soldiers[soldier_count-1].strength;
  142. Soldiers[soldier_count].name.empty();
  143. soldier_count--;
  144. update_power();
  145. }
  146. else{cout << "There is no soldier with id = " << id <<endl;}
  147. }
  148. int goToMission(int complexity){
  149. if(power > 0)
  150. {
  151. int chance = 0;
  152. int mResult = 0;
  153. chance = power/400;
  154. mResult = rand()%(101*complexity-chance);
  155. if(mResult < 50)
  156. {
  157. i = 0;
  158. for(i; i < soldier_count; i++)
  159. {
  160. Soldiers[i].speed = Soldiers[i].speed + rand()%(10*complexity) + 1;
  161. Soldiers[i].strength = Soldiers[i].strength + rand()%(10*complexity) + 1;
  162. }
  163. money += 10*complexity;
  164. cout << "Mission complete! Your solders get stat boost" << endl;
  165. }
  166. else
  167. {
  168. killSolder(rand()%(soldier_count - 1));
  169. cout << "Mission failed! One of your soldiers dead." << endl;
  170. }
  171. update_power();
  172. }
  173. else{cout << "You should add at least one soldier in your team to start mission!" <<endl;}
  174. }
  175.  
  176.  
  177. };
  178.  
  179. #endif // SOLDIER_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement