Advertisement
zCool

RPG Battle Part 3 Main.cpp

May 13th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.40 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include "Enemy.h"
  4. #include "Player.h"
  5. #include "Stats.h"
  6.  
  7. using namespace std;
  8.  
  9. int main()
  10. {
  11.  
  12. void WaitForEnter();
  13. string userInput;
  14. Stats s;
  15. int damage;
  16.  
  17. //set up enemy and player object
  18. Enemy monster(100,10,5,2);
  19. Player hero(100, 10, 5, 2);
  20.  
  21. while(monster.getStats().getHealth() > 0 &&
  22.     hero.getStats().getHealth() > 0)
  23. {
  24.  
  25. //display enemy and player health
  26. monster.displayHP();
  27. hero.displayHP();
  28.  
  29. std::cout << "What would you like to do? ";
  30. getline(cin, userInput);
  31.  
  32. //Validate
  33. while(userInput.compare("Attack") != 0 &&
  34.         userInput.compare("Heal") != 0)
  35.     {
  36.         std::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.         int oMonsterHealth = monster.getStats().getHealth();
  45.         int cMonsterHealth = monster.getHit(hero.getStats().getAttack(), monster.getStats().getDefense(),
  46.             monster.getStats().getHealth());
  47.         damage = oMonsterHealth - cMonsterHealth;
  48.         cout << "Damage Dealt to Monster: " << damage << endl;
  49.         s = monster.getStats();
  50.         s.setHealth(cMonsterHealth);
  51.         monster.setStats(s);
  52.  
  53.         //monster attack
  54.         int oHeroHealth = hero.getStats().getHealth();
  55.         int cHeroHealth = hero.getHit(hero.getStats().getAttack(), hero.getStats().getDefense(),
  56.             hero.getStats().getHealth());
  57.         damage = oHeroHealth - cHeroHealth;
  58.         cout << "Damage Dealt to Hero: " << damage << endl;
  59.         s = hero.getStats();
  60.         s.setHealth(cHeroHealth);
  61.         hero.setStats(s);
  62.     }
  63.  
  64.     //Heal
  65.     if(userInput.compare("Heal") == 0)
  66.     {
  67.  
  68.         //player heal
  69.         int oHeroHealth = hero.getStats().getHealth();
  70.         int nHeroHealth = hero.healSelf(hero.getStats().getHealth(),
  71.             hero.getStats().getSkill());
  72.         s = hero.getStats();
  73.         s.setHealth(nHeroHealth);
  74.         hero.setStats(s);
  75.         cout << "Player Healed " << nHeroHealth - oHeroHealth << " HP!" << endl;
  76.  
  77.         //monster attack
  78.         int oMonsterHealth = monster.getStats().getHealth();
  79.         int nMonsterHealth = monster.healSelf(monster.getStats().getHealth(),
  80.             monster.getStats().getSkill());
  81.         s = monster.getStats();
  82.         s.setHealth(nMonsterHealth);
  83.         monster.setStats(s);
  84.         cout << "Monster Healed " << nMonsterHealth - oMonsterHealth << " HP!" << endl;
  85.     }
  86. }
  87.  
  88.  
  89. //Program End
  90. cout << "Press Enter To Exit...";
  91. WaitForEnter();
  92.  
  93.  
  94. }
  95.  
  96. //Taken from Moosader (Rachel J. Morris)
  97. void WaitForEnter(){ while(1) { if ('\n' == getchar() ) { break; } } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement