Tavxela

Untitled

Nov 14th, 2019
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int dealDamage(int, int);
  8. int actualDamage(int);
  9. int randomNumber();
  10.  
  11. int Fight(int, int, int, int, bool, string, int);
  12.  
  13. int main() {
  14.  
  15. bool playerIsAlive;
  16.  
  17. int gold = 0;
  18. int skillPoints = 0;
  19. int healthPotions = 0;
  20. int playerHealth = 100;
  21. int playerDamage = 25;
  22.  
  23. int wolfHealth = 100;
  24. int wolfDamage = 15;
  25.  
  26. if (Fight(playerHealth, wolfHealth, playerDamage, wolfDamage, playerIsAlive = true, "Wolf", healthPotions = 3) == true) {
  27. gold += 100;
  28. skillPoints += 1;
  29. cout << "____________________________________________________________" << endl;
  30. cout << "Well Done, you gained " << gold << " Gold and " << skillPoints << " Skill Points" << endl;
  31. }
  32. else {
  33. cout << "Baah NOOB!" << endl;
  34. }
  35. }
  36.  
  37. int Fight(int hp1, int hp2, int dmg1, int dmg2, bool status, string enemyName, int healthPotion) {// 1. Player 2. Enemy
  38.  
  39. int turn = 1;//this decides wether it's players turn or not
  40. int fightStatus; // if fight is won or lost
  41. int maxEnemyHealth = hp2; // gives us max hp of an enemy
  42. char playerMove;
  43.  
  44. dmg2 = actualDamage(dmg2);
  45.  
  46. cout << "Your HP: " << hp1 << endl;
  47. cout << enemyName << " HP: " << hp2 << endl;
  48.  
  49. while (hp1 > 0 && hp2 > 0) { //fight
  50. if (turn == 1) {// player move
  51. cout << "\nType A to deal damage or type H to use potion" << endl;
  52. cin >> playerMove;
  53. if (playerMove == 'a' || playerMove == 'A') {
  54. turn--;
  55.  
  56. hp2 = dealDamage(hp2, dmg1);
  57. cout << "Damage dealt: " << dmg1 << endl;
  58. cout << enemyName << " HP: " << hp2 << endl;
  59. }
  60. else if (playerMove == 'h' && healthPotion > 0 || playerMove == 'H' && healthPotion > 0) {
  61. turn--;
  62. healthPotion--;
  63. hp1 += randomNumber();// heals player (1, 50)
  64. cout << "\nYou drank potion and gained: " << randomNumber() << " HP " << endl;
  65. cout << "Potions remaining: " << healthPotion << endl;
  66. cout << "Your HP: " << hp1 << endl;
  67. }
  68. }
  69. else {// enemy move
  70. turn++;
  71. hp1 -= dmg2;
  72. hp2 += maxEnemyHealth * 0.06;//heals enemy by 6%
  73. cout << "\nDamage recieved: " << dmg2 << endl;
  74. cout << "Enemy regained " << (maxEnemyHealth * 0.06) << " HP " << endl;
  75. cout << enemyName << " HP: " << hp2 << endl;
  76. cout << "Your HP: " << hp1 << endl;
  77. cout << "____________________________________________________________" << endl; // end of the turn
  78. }
  79. }
  80. if (hp1 > 0 && hp2 < 0) {
  81. status = true;
  82. cout << "Player Wins" << endl;
  83. }
  84. else if (hp1 < 0 && hp2 < 0) {
  85. status = false;
  86. cout << "You both died" << endl;
  87. }
  88. else {
  89. status = false;
  90. cout << "You died!" << endl;
  91. }
  92. return status;//returns if player is alive
  93. }
  94.  
  95. int dealDamage(int hp, int dmg) {// Dealing damage to entities
  96. hp -= dmg;
  97. return hp;
  98. }
  99.  
  100. int actualDamage(int actualdmg) {//adds damage random's 10%(random is (1, 50))
  101. int(float(actualdmg += (randomNumber() * 0.10f)));
  102. return actualdmg;
  103. }
  104.  
  105. int randomNumber() {// random (1, 50)
  106. int output;
  107. default_random_engine generator(time(NULL));
  108. uniform_int_distribution<int> interval(1, 50);
  109. output = interval(generator);
  110. return output;
  111. }
  112.  
  113. /*int shopChoices(int gold) {
  114. int input;
  115. cout << "____________________________________________________________" << endl;
  116. cout << "Gold: " << gold << endl;
  117. cout << "Type 1 to buy Shield, cost: 100 Gold " << endl;
  118. cout << "Type 2 to buy Health Potion, cost: 35 Gold" << endl;
  119. cout << "Type 3 to upgrade sword (+10 Damage), cost: 200 Gold" << endl;
  120. cin >> input;
  121. return input;
  122. }*/
Advertisement
Add Comment
Please, Sign In to add comment