Advertisement
Guest User

Untitled

a guest
May 16th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <conio.h>
  4. #include<cmath>
  5. #include<cstdlib>
  6. #include"Header.h"
  7. using namespace std;
  8.  
  9. #define ATTACK 1
  10. #define HEAL 2
  11. #define FALSE 0
  12. #define QUIT 9
  13.  
  14. int main()
  15. {
  16. int phealth; //player health
  17. int ehealth; //enemy health
  18. int heal; //amount healed
  19. int pdam; //amount of damage dealt by player
  20. int edam; //amount of damage dealt by enemy
  21. int choice;
  22. int crit; //critical hit / miss chance (1 in 5 chance for each)
  23. phealth = 100;
  24. ehealth = 100;
  25. while (true) {
  26. cout << "Player HP: " << phealth << endl;
  27. cout << "Enemy HP: " << ehealth << endl;
  28. printf("Select an action... \n");
  29. printf("1.) Attack\n2.) Heal\n");
  30. cin >> choice;
  31.  
  32. if (cin.fail()) {
  33. // purge keyboard buffer relics
  34. cin.clear(); // calm down 'cin' internal flags
  35. rewind(stdin); // clear out the actual keyboard corruption
  36. continue;
  37. }
  38.  
  39. switch (choice)
  40. {
  41. case ATTACK:
  42. ClearScreen();
  43. SeedRNGToSystemClock();
  44. crit = generateRandomValue(1, 5);
  45. pdam = generateRandomValue(0, 10);
  46. if (crit == 1)
  47. {
  48. pdam = (pdam * 2.5) + 5;
  49. cout << "CRITICAL HIT!" << endl;
  50. }
  51. if (crit == 2)
  52. {
  53. pdam = pdam * 0;
  54. cout << "Your attack missed!" << endl;
  55. }
  56. ehealth -= pdam;
  57. edam = generateRandomValue(0, 10);
  58. phealth -= edam;
  59. cout << "You dealt " << pdam << " damage to opponent." << endl;
  60. cout << "Enemy dealt " << edam << " damage to you." << endl << endl;
  61. break;
  62. case HEAL:
  63. ClearScreen();
  64. SeedRNGToSystemClock();
  65. heal = generateRandomValue(3, 25);
  66. phealth += heal;
  67. edam = generateRandomValue(0, 10);
  68. phealth -= edam;
  69. cout << "You healed " << heal << " HP." << endl;
  70. cout << "Enemy dealt " << edam << " damage to you." << endl << endl;
  71. break;
  72. default:
  73. cout << "Incorrect input. Try again! \n";
  74. }
  75. } // end - while
  76. _getch();
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement