Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include "Enemy.h"
- #include "Player.h"
- #include "Stats.h"
- using namespace std;
- int main()
- {
- void WaitForEnter();
- string userInput;
- Stats s;
- int damage;
- //set up enemy and player object
- Enemy monster(100,10,5,2);
- Player hero(100, 10, 5, 2);
- while(monster.getStats().getHealth() > 0 &&
- hero.getStats().getHealth() > 0)
- {
- //display enemy and player health
- monster.displayHP();
- hero.displayHP();
- std::cout << "What would you like to do? ";
- getline(cin, userInput);
- //Validate
- while(userInput.compare("Attack") != 0 &&
- userInput.compare("Heal") != 0)
- {
- std::cout << "What would you like to do? ";
- getline(cin, userInput);
- }
- //Attack
- if(userInput.compare("Attack") == 0)
- {
- //player attack
- int oMonsterHealth = monster.getStats().getHealth();
- int cMonsterHealth = monster.getHit(hero.getStats().getAttack(), monster.getStats().getDefense(),
- monster.getStats().getHealth());
- damage = oMonsterHealth - cMonsterHealth;
- cout << "Damage Dealt to Monster: " << damage << endl;
- s = monster.getStats();
- s.setHealth(cMonsterHealth);
- monster.setStats(s);
- //monster attack
- int oHeroHealth = hero.getStats().getHealth();
- int cHeroHealth = hero.getHit(hero.getStats().getAttack(), hero.getStats().getDefense(),
- hero.getStats().getHealth());
- damage = oHeroHealth - cHeroHealth;
- cout << "Damage Dealt to Hero: " << damage << endl;
- s = hero.getStats();
- s.setHealth(cHeroHealth);
- hero.setStats(s);
- }
- //Heal
- if(userInput.compare("Heal") == 0)
- {
- //player heal
- int oHeroHealth = hero.getStats().getHealth();
- int nHeroHealth = hero.healSelf(hero.getStats().getHealth(),
- hero.getStats().getSkill());
- s = hero.getStats();
- s.setHealth(nHeroHealth);
- hero.setStats(s);
- cout << "Player Healed " << nHeroHealth - oHeroHealth << " HP!" << endl;
- //monster attack
- int oMonsterHealth = monster.getStats().getHealth();
- int nMonsterHealth = monster.healSelf(monster.getStats().getHealth(),
- monster.getStats().getSkill());
- s = monster.getStats();
- s.setHealth(nMonsterHealth);
- monster.setStats(s);
- cout << "Monster Healed " << nMonsterHealth - oMonsterHealth << " HP!" << endl;
- }
- }
- //Program End
- cout << "Press Enter To Exit...";
- WaitForEnter();
- }
- //Taken from Moosader (Rachel J. Morris)
- void WaitForEnter(){ while(1) { if ('\n' == getchar() ) { break; } } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement