Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- void WaitForEnter();
- int attack(int attackerATK, int victimHP, int victimDEF);
- int heal(int oldHP);
- int playerHP = 100;
- int playerATK = 10;
- int playerDEF = 5;
- int monsterHP = 50;
- int monsterATK = 10;
- int monsterDEF = 5;
- string userInput = "";
- while (monsterHP > 0 && playerHP > 0)
- {
- //display HP for monster & player
- cout << "Monster HP: "<< monsterHP << endl
- << "Player HP: " << playerHP << endl;
- //display options (Attack, Heal)
- cout << "Attack" << endl
- << "Heal" << endl
- << "What would you like to do? ";
- getline(cin, userInput);
- //Validate
- while(userInput.compare("Attack") != 0 &&
- userInput.compare("Heal") != 0)
- {
- cout << "What would you like to do? ";
- getline(cin, userInput);
- }
- //Attack
- if(userInput.compare("Attack") == 0)
- {
- //player attack
- monsterHP = attack(playerATK, monsterHP, monsterDEF);
- //monster attack
- playerHP = attack(monsterATK, playerHP, playerDEF);
- }
- //Heal
- if(userInput.compare("Heal") == 0)
- {
- //player heal
- playerHP = heal(playerHP);
- //monster attack
- playerHP = attack(monsterATK, playerHP, playerDEF);
- }
- }
- cout << "Press Enter To Exit...";
- WaitForEnter();
- }
- //Taken from Moosader (Rachel J. Morris)
- void WaitForEnter(){ while(1) { if ('\n' == getchar() ) { break; } } }
- //attack function
- int attack(int attackerATK, int victimHP, int victimDEF)
- {
- return (victimHP - rand()%(attackerATK - victimDEF));
- }
- //heal function
- int heal(int oldHP)
- {
- return (oldHP + rand()%5 + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement