Tavxela

Untitled

Nov 15th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <tuple>
  4. #include <ctime>
  5.  
  6. using namespace std;
  7.  
  8. int DealDamage(int, int);
  9. int ActualDamage(int);
  10. int RandomNumber();
  11. int Shop(int&, int&);
  12. int IsPlayerAlive(int&);
  13. void Stage1(int&);
  14.  
  15. int Fight(int& , int, int, int, string, int&);
  16.  
  17. int main() {
  18.  
  19. bool playerIsAlive;
  20.  
  21. int gold = 0;
  22. int skillPoints = 0;
  23. int healthPotions = 3;
  24. int playerHealth = 100;
  25. int playerDamage = 25;
  26.  
  27. int wolfHealth = 100;
  28. int wolfDamage = 15;
  29.  
  30. //Fight(playerHealth, wolfHealth, playerDamage, wolfDamage, "Wolf", healthPotions);
  31. //Stage1(playerHealth);
  32.  
  33. if (Fight(playerHealth, wolfHealth, playerDamage, wolfDamage, "Wolf", healthPotions) == true) {
  34. gold += 100;
  35. skillPoints += 1;
  36. cout << "____________________________________________________________" << endl;
  37. cout << "Well Done, you gained " << gold << " Gold " << endl;
  38. cout << "Your HP: " << playerHealth << endl;
  39. Shop(gold, healthPotions);
  40. cout << gold << " " << healthPotions << endl;
  41. }
  42. else {
  43. cout << "Baah NOOB!" << endl;
  44. }
  45. }
  46.  
  47. int DealDamage(int hp, int dmg) {// Dealing damage to entities
  48. hp -= dmg;
  49. return hp;
  50. }
  51.  
  52. int ActualDamage(int actualdmg) {//adds damage random's 10%(random is (1, 50))
  53. int(float(actualdmg += (RandomNumber() * 0.10f)));
  54. return actualdmg;
  55. }
  56.  
  57. int RandomNumber() {// random (1, 50)
  58. default_random_engine generator(time(NULL));
  59. uniform_int_distribution<int> interval(1, 50);
  60. return interval(generator);
  61. }
  62.  
  63. int IsPlayerAlive(int& playerHealth){
  64. if (playerHealth > 0) {
  65. return true;
  66. }
  67. else {
  68. return false;
  69. }
  70. }
  71.  
  72. void Stage1(int& playerHealth) {
  73. if (IsPlayerAlive(playerHealth)) {
  74. cout << "You are alive" << endl;
  75. }
  76. else {
  77. cout << "You Died" << endl;
  78. }
  79. }
  80.  
  81. int Shop(int& gold,int& healthPotions) {
  82. int input = 0;
  83. cout << "____________________________________________________________" << endl;
  84. cout << "Gold: " << gold << endl;
  85. cout << "Type 1 to buy Shield, cost: 100 Gold " << endl;
  86. cout << "Type 2 to buy Health Potion, cost: 35 Gold" << endl;
  87. cout << "Type 3 to upgrade sword (+10 Damage), cost: 200 Gold" << endl;
  88. cout << "Type B to leave the shop" << endl;
  89. cin >> input;
  90. if (input == 1 && gold >= 100) {
  91. gold -= 100;
  92. cout << "You now have a Shield \nGold Remaining: " << gold << endl;
  93. }
  94. else if (input == 2 && gold >= 35) {
  95. gold -= 35;
  96. healthPotions++;
  97. cout << "You purchased health potion \nGold Remaining: " << gold << endl;
  98. }
  99. else if (input == 3 && gold >= 200) {
  100. gold -= 200;
  101. cout << "You upgraded Sword \nGold Remaining: " << gold << endl;
  102. }
  103. else if (input == 'b' || input == 'B') {
  104. return 0;
  105. }
  106. return 0;
  107. }
  108.  
  109. int Fight(int& playehp, int hp2, int dmg1, int dmg2, string enemyName, int& healthPotion) {// 1. Player 2. Enemy
  110.  
  111. int turn = 1;//this decides wether it's players turn or not
  112. int fightStatus; // if fight is won or lost
  113. int maxEnemyHealth = hp2; // gives us max hp of an enemy
  114. char playerMove;
  115.  
  116. dmg2 = ActualDamage(dmg2);
  117.  
  118. cout << "Your HP: " << playehp << endl;
  119. cout << enemyName << " HP: " << hp2 << endl;
  120.  
  121. while (playehp > 0 && hp2 > 0) { //fight
  122. if (turn == 1) {// player move
  123. cout << "\nType A to deal damage or type H to use potion" << endl;
  124. cin >> playerMove;
  125. if (playerMove == 'a' || playerMove == 'A') {
  126. turn--;
  127.  
  128. hp2 = DealDamage(hp2, dmg1);
  129. cout << "Damage dealt: " << dmg1 << endl;
  130. cout << enemyName << " HP: " << hp2 << endl;
  131. }
  132. else if (playerMove == 'h' && healthPotion > 0 || playerMove == 'H' && healthPotion > 0) {
  133. turn--;
  134. healthPotion--;
  135. playehp += RandomNumber();// heals player (1, 50)
  136. cout << "\nYou drank potion and gained: " << RandomNumber() << " HP " << endl;
  137. cout << "Potions remaining: " << healthPotion << endl;
  138. cout << "Your HP: " << playehp << endl;
  139. }
  140. }
  141. else {// enemy move
  142. turn++;
  143. playehp -= dmg2;
  144. hp2 += maxEnemyHealth * 0.06;//heals enemy by 6%
  145. cout << "\nDamage recieved: " << dmg2 << endl;
  146. cout << "Enemy regained " << (maxEnemyHealth * 0.06) << " HP " << endl;
  147. cout << enemyName << " HP: " << hp2 << endl;
  148. cout << "Your HP: " << playehp << endl;
  149. cout << "____________________________________________________________" << endl; // end of the turn
  150. }
  151. }
  152. /*if (playehp > 0 && hp2 < 0) {
  153. status = true;
  154. cout << "Player Wins" << endl;
  155. }
  156. else if (playehp < 0 && hp2 < 0) {
  157. status = false;
  158. cout << "You both died" << endl;
  159. }
  160. else {
  161. status = false;
  162. cout << "You died!" << endl;
  163. }
  164.  
  165. return status;//returns if player is alive*/
  166. return 0;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment