Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. // Strategy.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <string>
  6. #include <vector>
  7. #include <iostream>
  8. #include <map>
  9. using namespace std;
  10.  
  11. class Unit {
  12. protected:
  13. string name;
  14. int attack;
  15. int health;
  16. int defense;
  17. int initiative;
  18. const string attack_type;
  19. public:
  20. void info() {
  21. cout << name << '\n';
  22. };
  23. };
  24.  
  25. class Warrior : public Unit {
  26. protected:
  27. const string attack_type = "Closest target";
  28. };
  29.  
  30. class Mage : public Unit {
  31. protected:
  32. const string attack_type = "All targets";
  33. string element;
  34. };
  35.  
  36. class Ranger : public Unit {
  37. private:
  38. const string attack_type = "Any target";
  39. };
  40.  
  41. class Knight : public Warrior {
  42. private:
  43. public:
  44. const static int ID = 0;
  45. const static int cost = 0;
  46. Knight() {
  47. name = "Knight";
  48. attack = 0;
  49. defense = 0;
  50. health = 0;
  51. initiative = 0;
  52. };
  53. ~Knight() {};
  54. };
  55.  
  56. class Archer : public Ranger {
  57. private:
  58. public:
  59. const static int ID = 1;
  60. const static int cost = 0;
  61. Archer() {
  62. name = "Archer";
  63. attack = 0;
  64. defense = 0;
  65. health = 0;
  66. initiative = 0;
  67. };
  68. ~Archer() {};
  69. };
  70.  
  71. class Wizard : public Mage {
  72. private:
  73. public:
  74. const static int ID = 2;
  75. const static int cost = 0;
  76. Wizard() {
  77. name = "Wizard";
  78. attack = 0;
  79. defense = 0;
  80. health = 0;
  81. initiative = 0;
  82. element = "Air";
  83. };
  84. ~Wizard() {};
  85. };
  86.  
  87. /*class Hero {
  88.  
  89. };
  90.  
  91. class Special : public Unit {
  92.  
  93. };*/
  94.  
  95. class Army {
  96. public:
  97. vector<Warrior*> Warriors;
  98. vector<Mage*> Mages;
  99. vector<Ranger*> Rangers;
  100. void info() {
  101. cout << "Warriors:\n";
  102. for (auto i : Warriors) {
  103. i->info();
  104. }
  105. cout << "Mages:\n";
  106. for (auto i : Mages) {
  107. i->info();
  108. }
  109. cout << "Rangers:\n";
  110. for (auto i : Rangers) {
  111. i->info();
  112. }
  113. }
  114. ~Army() {
  115. for (auto i : Warriors) {
  116. delete i;
  117. }
  118. for (auto i : Mages) {
  119. delete i;
  120. }
  121. for (auto i : Rangers) {
  122. delete i;
  123. }
  124. }
  125. };
  126.  
  127. class ArmyFactory {
  128. protected:
  129. map<string, vector<pair<string, int>>> FractionOverview;
  130. public:
  131. virtual Warrior* createWarrior(int ID) = 0;
  132. virtual Mage* createMage(int ID) = 0;
  133. virtual Ranger* createRanger(int ID) = 0;
  134. ~ArmyFactory() {};
  135. };
  136.  
  137. class HumanArmyFactory : public ArmyFactory {
  138. public:
  139. HumanArmyFactory() {
  140. FractionOverview["Warriors"] = { make_pair("Knight", Knight::cost) };
  141. FractionOverview["Mages"] = { make_pair("Wizard", Wizard::cost) };
  142. FractionOverview["Rangers"] = { make_pair("Archer", Archer::cost) };
  143. }
  144. Warrior* createWarrior(int ID) {
  145. switch (ID) {
  146. case Knight::ID:
  147. return new Knight;
  148. }
  149. }
  150. Mage* createMage(int ID) {
  151. switch (ID) {
  152. case Wizard::ID:
  153. return new Wizard;
  154. }
  155. }
  156. Ranger* createRanger(int ID) {
  157. switch (ID) {
  158. case Archer::ID:
  159. return new Archer;
  160. }
  161. }
  162. };
  163.  
  164. class UndeadArmyFactory : public ArmyFactory {
  165. public:
  166.  
  167. };
  168.  
  169. class Menu {
  170. public:
  171. Army* CreateArmy(int &balance, ArmyFactory* factory) {
  172. while (true) {
  173. cout << "Your balance: " << balance << "\n";
  174. for (auto i : factory->FractionOverview)
  175. }
  176. }
  177. };
  178.  
  179. class Player {
  180. private:
  181. int fraction_ID;
  182. Army* Player_Army;
  183. int balance;
  184. ArmyFactory* factory;
  185. public:
  186. Player(int balance): fraction_ID(0), Player_Army(nullptr), balance(balance) {}
  187. int ShowFraction() {
  188. return fraction_ID;
  189. }
  190. void SetFraction() {
  191. cout << "Choose your fraction:\n1. Humans\n2. Undead";
  192. cin >> fraction_ID;
  193. switch (fraction_ID) {
  194. case 1:
  195. factory = new HumanArmyFactory();
  196. case 2:
  197. factory = new HumanArmyFactory();
  198. }
  199. }
  200. void Initialize() {
  201. SetFraction();
  202. Menu PlMenu;
  203. Player_Army = PlMenu.CreateArmy(balance, factory);
  204. }
  205. };
  206.  
  207. int main()
  208. {
  209. int balance;
  210. cout << "Enter the starting treasury >> ";
  211. cin >> balance;
  212. Player Player_1(balance);
  213. Player_1.Initialize();
  214. Player Player_2(balance);
  215. Player_2.Initialize();
  216.  
  217. return 0;
  218. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement