Advertisement
zCool

RPG Battle Part I

May 5th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.31 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <math.h>
  4. #include <ctime>
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     //declarations
  10.     void printClazzName(string sArray[4]);
  11.     int setStrength(string s, string strArr[4]);
  12.     void WaitForEnter();
  13.     string clazzName[4] = {"Monk", "Barbarian", "Mage", "Archer"};
  14.     string playerClazz;
  15.     int strength;
  16.     int monsterHealth = 100;
  17.  
  18.     //Introduction + List Classes
  19.     cout << "It seems you have stumbled upon a monster with 100 health" <<endl;
  20.     printClazzName(clazzName);
  21.     cout << "Please select a character from the list of classes above: ";
  22.  
  23.     //Get User Input
  24.     getline(cin, playerClazz);
  25.     //Validate
  26.     while(playerClazz.compare("Monk") != 0 &&
  27.         playerClazz.compare("Barbarian") !=0 &&
  28.         playerClazz.compare("Mage") !=0 &&
  29.         playerClazz.compare("Archer") !=0)
  30.     {
  31.         cout << "Please select a character from the list of classes above: ";
  32.         getline(cin,playerClazz);
  33.     }
  34.  
  35.     //set the playerStrength
  36.     strength = setStrength(playerClazz, clazzName);
  37.     cout << "class strength is " << strength << endl;
  38.  
  39.     //Battle the Monster!!!
  40.     while(monsterHealth > 0)
  41.     {
  42.         cout << "The monster has health : " << monsterHealth << "." << endl;
  43.         cout << "You hit the monster for " << strength << " damage." << endl;
  44.         monsterHealth = monsterHealth - strength;
  45.     }
  46.  
  47.     //Display Victory Message
  48.     cout << "You defeated the monster, or at least you think it was a monster.\n"
  49.          << "Maybe you are the monster in this scenario.\n"
  50.          << "Oh well, putting aside such philosophical concerns, you rejoice.\n"
  51.          << "And head for the town pub for a pint of their finest 'Hero's' Ale. \n";
  52.  
  53.     //Prompt the user to hit enter to quit
  54.     cout << "Press enter to quit";
  55.     WaitForEnter();
  56.    
  57.  
  58. }
  59.  
  60.  
  61. //print the classes
  62. void printClazzName(string clazzName[4])
  63. {
  64.     for(int i=0 ; i<4 ; i++)
  65.     {
  66.         cout << "Class " << i+1 <<" : " << clazzName[i] <<endl;
  67.  
  68.     }
  69. }
  70.  
  71. //set player strength depending on class.
  72. int setStrength(string playerClazz , string clazzName[4])
  73. {
  74. srand(time(0));
  75. int playerStrength;
  76.  
  77.     for(int i = 0 ; i<4 ; i++)
  78.     {
  79.         if(playerClazz.compare(clazzName[i]) ==0)
  80.         {
  81.             playerStrength = (int) (100 + fmod(pow(-1.0, i+1) * (double) rand(), 50.0));
  82.         }
  83.     }
  84.     return playerStrength;
  85. }
  86.  
  87. //stolen(borrowed) from Moosader
  88. void WaitForEnter()
  89. {
  90.     while ( 1 ) { if ( '\n' == getchar() ) { break; } }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement