Advertisement
Tavxela

Untitled

Nov 13th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int AttackDamage(int, int);
  8. int Heal(int);
  9. int RandomNumberGenerator();
  10.  
  11. int main() {
  12. int playerHealth = 100;
  13. int playerDamage = 25;
  14.  
  15. int wolfHealth = 100;
  16. int wolfDamage = 15 + RandomNumberGenerator();
  17.  
  18. int generalMove = 1;
  19. char input1,playerMove;
  20. string game;
  21.  
  22. cout << "Wolf HP: " << wolfHealth << endl;
  23. cout << "Your HP: " << playerHealth << endl;
  24.  
  25. while (playerHealth > 0 || wolfHealth > 0) {
  26.  
  27. if (generalMove == 1) {
  28. cout << "\nType A to attack or H to heal" << endl;
  29. cin >> playerMove;
  30. if (playerMove == 'a' || playerMove == 'A') {
  31. generalMove++;
  32. wolfHealth = AttackDamage(wolfHealth, playerDamage);
  33. cout << "Damage dealt: " << playerDamage << endl;
  34. cout << "Wolf HP: " << wolfHealth << endl;
  35. }
  36. else if (playerMove == 'h' || playerMove == 'H') {
  37. generalMove++;
  38. playerHealth = Heal(playerHealth);
  39. cout << "You regained: " << RandomNumberGenerator() << " HP" << endl;
  40. cout << "Your Health: " << playerHealth << endl;
  41. }
  42. }
  43. else {
  44. generalMove--;
  45. playerHealth = AttackDamage(playerHealth, wolfDamage);
  46. cout << "\nDamage Recieved: " << wolfDamage << endl;
  47. cout << "Your HP: " << playerHealth << endl;
  48. }
  49. }
  50. if (wolfHealth < 0) {
  51. cout << "You win!" << endl;
  52. }
  53. else if (playerHealth < 0 && wolfHealth < 0) {
  54. cout << "You both died" << endl;
  55. }
  56. else if (playerHealth < 0) {
  57. cout << "You lost!" << endl;
  58. }
  59. }
  60. int AttackDamage(int hp, int dmg) {
  61. hp -= dmg;
  62. return hp;
  63. }
  64.  
  65. int Heal(int hp) {
  66. hp += RandomNumberGenerator();
  67. return hp;
  68. }
  69.  
  70. int RandomNumberGenerator() {
  71. int randomNumber = 0;
  72. default_random_engine generator(time(NULL));
  73. uniform_int_distribution<int> interval(1, 10);
  74. randomNumber = interval(generator);
  75. return randomNumber;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement