Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <math.h>
- #include <ctime>
- using namespace std;
- int main()
- {
- //declarations
- void printClazzName(string sArray[4]);
- int setStrength(string s, string strArr[4]);
- void WaitForEnter();
- string clazzName[4] = {"Monk", "Barbarian", "Mage", "Archer"};
- string playerClazz;
- int strength;
- int monsterHealth = 100;
- //Introduction + List Classes
- cout << "It seems you have stumbled upon a monster with 100 health" <<endl;
- printClazzName(clazzName);
- cout << "Please select a character from the list of classes above: ";
- //Get User Input
- getline(cin, playerClazz);
- //Validate
- while(playerClazz.compare("Monk") != 0 &&
- playerClazz.compare("Barbarian") !=0 &&
- playerClazz.compare("Mage") !=0 &&
- playerClazz.compare("Archer") !=0)
- {
- cout << "Please select a character from the list of classes above: ";
- getline(cin,playerClazz);
- }
- //set the playerStrength
- strength = setStrength(playerClazz, clazzName);
- cout << "class strength is " << strength << endl;
- //Battle the Monster!!!
- while(monsterHealth > 0)
- {
- cout << "The monster has health : " << monsterHealth << "." << endl;
- cout << "You hit the monster for " << strength << " damage." << endl;
- monsterHealth = monsterHealth - strength;
- }
- //Display Victory Message
- cout << "You defeated the monster, or at least you think it was a monster.\n"
- << "Maybe you are the monster in this scenario.\n"
- << "Oh well, putting aside such philosophical concerns, you rejoice.\n"
- << "And head for the town pub for a pint of their finest 'Hero's' Ale. \n";
- //Prompt the user to hit enter to quit
- cout << "Press enter to quit";
- WaitForEnter();
- }
- //print the classes
- void printClazzName(string clazzName[4])
- {
- for(int i=0 ; i<4 ; i++)
- {
- cout << "Class " << i+1 <<" : " << clazzName[i] <<endl;
- }
- }
- //set player strength depending on class.
- int setStrength(string playerClazz , string clazzName[4])
- {
- srand(time(0));
- int playerStrength;
- for(int i = 0 ; i<4 ; i++)
- {
- if(playerClazz.compare(clazzName[i]) ==0)
- {
- playerStrength = (int) (100 + fmod(pow(-1.0, i+1) * (double) rand(), 50.0));
- }
- }
- return playerStrength;
- }
- //stolen(borrowed) from Moosader
- void WaitForEnter()
- {
- while ( 1 ) { if ( '\n' == getchar() ) { break; } }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement