SHARE
TWEET

RPG Battle Part II

zCool May 7th, 2012 22 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. void WaitForEnter();
  8. int attack(int attackerATK, int victimHP, int victimDEF);
  9. int heal(int oldHP);
  10. int playerHP = 100;
  11. int playerATK = 10;
  12. int playerDEF = 5;
  13. int monsterHP = 50;
  14. int monsterATK = 10;
  15. int monsterDEF = 5;
  16. string userInput = "";
  17.  
  18.  
  19. while (monsterHP > 0 && playerHP > 0)
  20. {
  21.         //display HP for monster & player
  22.         cout << "Monster HP: "<< monsterHP << endl
  23.                  << "Player HP: " << playerHP << endl;
  24.        
  25.         //display options (Attack, Heal)
  26.         cout << "Attack" << endl
  27.                  << "Heal" << endl
  28.                  << "What would you like to do? ";
  29.  
  30.         getline(cin, userInput);
  31.  
  32.         //Validate
  33.         while(userInput.compare("Attack") != 0 &&
  34.                 userInput.compare("Heal") != 0)
  35.         {
  36.                 cout << "What would you like to do? ";
  37.                 getline(cin, userInput);
  38.         }
  39.  
  40.         //Attack
  41.         if(userInput.compare("Attack") == 0)
  42.         {
  43.                 //player attack
  44.                 monsterHP = attack(playerATK, monsterHP, monsterDEF);
  45.  
  46.                 //monster attack
  47.                 playerHP = attack(monsterATK, playerHP, playerDEF);
  48.         }
  49.  
  50.         //Heal
  51.         if(userInput.compare("Heal") == 0)
  52.         {
  53.                 //player heal
  54.                 playerHP = heal(playerHP);
  55.  
  56.                 //monster attack
  57.                 playerHP = attack(monsterATK, playerHP, playerDEF);
  58.         }
  59.  
  60. }
  61.  
  62. cout << "Press Enter To Exit...";
  63. WaitForEnter();
  64.  
  65. }
  66.  
  67. //Taken from Moosader (Rachel J. Morris)
  68. void WaitForEnter(){ while(1) { if ('\n' == getchar() ) { break; } } }
  69.  
  70. //attack function
  71. int attack(int attackerATK, int victimHP, int victimDEF)
  72. {
  73.         return (victimHP - rand()%(attackerATK - victimDEF));
  74. }
  75.  
  76. //heal function
  77. int heal(int oldHP)
  78. {
  79.         return (oldHP + rand()%5 + 1);
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top