Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1.  
  2.  
  3. #include "pch.h"
  4. #include <iostream>
  5. #include <ctime>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. struct ArmyTemplate {
  11. int health;
  12. int damage;
  13. int defence;
  14.  
  15. char name;
  16. char type;
  17. char ammo_type;
  18. };
  19.  
  20. class Army {
  21. private:
  22. int current_index = 0;
  23. public:
  24. ArmyTemplate *armyTemplate;
  25. int ArmySize;
  26.  
  27. Army(int size){
  28. armyTemplate = new ArmyTemplate[size];
  29. ArmySize = size;
  30. }
  31.  
  32. void addUnit(int unit_health, int unit_damage, int unit_defence, char unit_name, char unit_type, char unit_ammo_type) {
  33. armyTemplate[current_index].health = unit_health;
  34. armyTemplate[current_index].damage = unit_damage;
  35. armyTemplate[current_index].defence = unit_defence;
  36.  
  37. armyTemplate[current_index].name = unit_name;
  38. armyTemplate[current_index].type = unit_type;
  39. armyTemplate[current_index].ammo_type = unit_ammo_type;
  40.  
  41. current_index++;
  42. }
  43.  
  44. void get()
  45. {
  46. for (int i = 0; i < current_index; i++) {
  47. cout << "Здоровье - " << armyTemplate[i].health << endl;
  48. cout << "Урон - " << armyTemplate[i].damage << endl;
  49. cout << "Защита - " << armyTemplate[i].defence << endl;
  50.  
  51. cout << "Имя - " << armyTemplate[i].name << endl;
  52. cout << "Тип - " << armyTemplate[i].type << endl;
  53. cout << "Тип боеприпасов - " << armyTemplate[i].ammo_type << endl << endl;
  54. }
  55. }
  56. };
  57.  
  58.  
  59. class Soldier {
  60. public:
  61.  
  62. int health = 0;
  63. int damage = 0;
  64. int defence = 0;
  65. string type = "human";
  66. string name = "";
  67.  
  68. Soldier(int new_health, int new_damage, int new_defence, string new_name)
  69. {
  70. health = new_health;
  71. damage = new_damage;
  72. defence = new_defence;
  73. name = new_name;
  74. }
  75.  
  76. void Print() {
  77. cout << "health" << health << "damage" << damage << endl;
  78.  
  79. }
  80. };
  81.  
  82. class Mechanism {
  83. public:
  84. int health = 0;
  85. int damage = 0;
  86. int defence = 0;
  87.  
  88. string type = "mechanism";
  89. string name = "";
  90. string ammo_type = "";
  91.  
  92. Mechanism(int new_health, int new_damage, int new_defence, string new_name, string new_ammo_type)
  93. {
  94. health = new_health;
  95. damage = new_damage;
  96. defence = new_defence;
  97. name = new_name;
  98. ammo_type = new_ammo_type;
  99. }
  100.  
  101.  
  102. void Print() {
  103. cout << "health" << health << "damage" << damage << endl;
  104.  
  105. }
  106.  
  107. };
  108.  
  109. int main()
  110. {
  111. int armySize;
  112.  
  113. // Soldier test_unit(100, 200, 50, "Маг");
  114. // Mechanism test_mech(100, 200, 50, "Пушка", "Ядро");
  115. cout << "Введите размер армии..." << endl;
  116. cin >> armySize;
  117.  
  118. Army army(armySize);
  119.  
  120. // army.addUnit(test_unit.health, test_unit.damage, test_unit.defence, test_unit.name, test_unit.type, "none");
  121. //army.addUnit(test_mech.health, test_mech.damage, test_mech.defence, test_mech.name, test_mech.type, test_mech.ammo_type);
  122.  
  123. string names = { "Маг", "Тигр" };
  124. string types = { "human", "animal" };
  125. string ammo_types = { "magic_stick", "nails"};
  126.  
  127. int health = 0;
  128. int damage = 0;
  129. int defence = 0;
  130. int random_index = 0;
  131.  
  132. for (int i = 0; i < armySize; i++)
  133. {
  134. srand(time(NULL));
  135. health = 30 + rand() % 80;
  136. damage = 10 + rand() % 50;
  137. defence = 5 + rand() % 15;
  138.  
  139.  
  140. random_index = rand() % 1;
  141. cout << random_index << endl;
  142. cout << health << endl;
  143. cout << damage << endl;
  144. cout << defence << endl;
  145. break;
  146. //army.addUnit(health, damage, defence, names[random_index], types[random_index], ammo_types[random_index]);
  147. }
  148.  
  149. //army.get();
  150.  
  151. system("pause");
  152. return 0;
  153. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement