SHARE
TWEET

main.cpp

zCool May 17th, 2012 14 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Character.h"
  2. #include "Enemy.h"
  3. #include<iostream>
  4. #include "Stats.h"
  5. #include "Player.h"
  6. #include "time.h"
  7. #include<string>
  8.  
  9. using namespace std;
  10.  
  11. void waitForEnter()
  12. {
  13.         while(1) { if( '\n' == getchar()) { break; } }
  14. }
  15.  
  16. int main()
  17. {
  18.         int roundNumber = 0;
  19.         string playerChoice = "";
  20.         Stats monsterStats(50 , 10 , 10 , 5);
  21.         Enemy monster(monsterStats);
  22.        
  23.         Stats playerStats(50, 10, 10, 5);
  24.         Player player(playerStats);
  25.  
  26.         //seed random generator
  27.         srand(time(NULL));
  28.  
  29.         while(monster.getHealthStat() > 0 &&
  30.                 player.getHealthStat() > 0)
  31.         {
  32.                 cout << "----------------------------------------\n";
  33.                 cout << "Starting round " << roundNumber << endl;
  34.                 cout << "----------------------------------------\n";
  35.                 monster.setEnemyDefaultDefense();
  36.                 cout << "Monster Stats" << endl;
  37.                 monster.printStats();
  38.                 cout << "Player Stats" << endl;
  39.                 player.printStats();
  40.                
  41.                 //enemy turn
  42.  
  43.                 // handle enemy logic
  44.                 Enemy::decisionTypes enemyDecision = monster.chooseWhatToDo(); //Enemy 'AI'
  45.                  
  46.                 switch(enemyDecision)
  47.                 {
  48.                 case Enemy::DEFEND:
  49.                         cout <<"Monster uses Defend...\n";
  50.                         monster.incrementEnemyDefense(5);
  51.                         break;
  52.                 case Enemy::RAGE:
  53.                         cout <<"Monster uses Rage...\n";
  54.                         monster.incrementEnemyAttack(5);
  55.                         break;
  56.  
  57.                 case Enemy::ATTACK:
  58.                         cout << "Monster Attacks...\n";
  59.                         player.getHit(monster.getAttackStat() , player.getDefenseStat(), player.getHealthStat());
  60.                         monster.setEnemyDefaultAttack();
  61.                         break;
  62.                 default:
  63.                         break; //wtf?
  64.                 }
  65.  
  66.                 //player turn
  67.                 cout << "Player's Turn:\n";
  68.                 cout << "What would you like to do?";
  69.  
  70.                 //get user input and validate
  71.                 getline(cin, playerChoice);
  72.  
  73.                 while(playerChoice.compare("heal") != 0
  74.                         && playerChoice.compare("magic") != 0
  75.                         && playerChoice.compare("attack") != 0)
  76.                 {
  77.                         cout << "What would you like to do?";
  78.                         getline(cin, playerChoice);
  79.                 }
  80.  
  81.                 //handle user's choice - attack, magic, heal
  82.  
  83.                 if(playerChoice.compare("attack") == 0)
  84.                 {
  85.                         cout << "Player Attacks...\n";
  86.                         monster.getHit(player.getAttackStat(), monster.getDefenseStat(), monster.getHealthStat());
  87.                 }
  88.  
  89.                 if(playerChoice.compare("magic") == 0)
  90.                 {
  91.                         cout << "Player casts fireball spell... \n";
  92.                         monster.getHit(player.fireBall(player.getSkillStat()) , monster.getDefenseStat(), monster.getHealthStat());
  93.                 }
  94.  
  95.                 if(playerChoice.compare("heal") == 0)
  96.                 {
  97.                         cout << "Player casts heal...\n";
  98.                         player.healSelf(player.getSkillStat());
  99.                 }
  100.                 roundNumber++;
  101.         }
  102.         cout << "Press Enter to Exit...";
  103.         waitForEnter();
  104. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top