Guest User

Game Challenge 1

a guest
May 31st, 2014
7,678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     //Dont forget to seed your random engine with time!
  10.     default_random_engine randomEngine(time(NULL));
  11.     uniform_real_distribution<float> attack(0.0f, 1.0f);
  12.  
  13.     // Human properties
  14.     float humanAttack = 0.6f;
  15.     float humanHealth = 250.0f;
  16.     float humanDamage = 200.0f;
  17.     float currentHumanHealth = humanHealth;
  18.  
  19.     //skeleton properties
  20.     float skeletonAttack = 0.4f;
  21.     float skeletonHealth = 50.0f;
  22.     float skeletonDamage = 40.0f;
  23.     float currentSkeletonHealth = skeletonHealth;
  24.  
  25.     float attackResult;
  26.  
  27.     int startSkeletons;
  28.     int startHumans;
  29.  
  30.     int numSkeletons;
  31.     int numHumans;
  32.  
  33.     char turn = 'H';
  34.  
  35.     cout << "*** Skeletons Vs Humans! ***\n\n";
  36.  
  37.     //Get the number of humans
  38.     cout << "Enter the number of humans: ";
  39.     cin >> numHumans;
  40.  
  41.     startHumans = numHumans;
  42.  
  43.     //Get the number of skeletons
  44.     cout << "Enter the number of skeletons: ";
  45.     cin >> numSkeletons;
  46.  
  47.     startSkeletons = numSkeletons;
  48.  
  49.     cout << "\nBeginning combat!\n\n";
  50.  
  51.     while ((numHumans > 0) && (numSkeletons > 0)) {
  52.         //Get our attack result
  53.         attackResult = attack(randomEngine);
  54.  
  55.         // Humans turn
  56.         if (turn == 'H') {
  57.          
  58.             //Check if attack was successful
  59.             if (attackResult <= humanAttack) {
  60.                 currentSkeletonHealth -= humanDamage;
  61.  
  62.                 if (currentSkeletonHealth < 0) {
  63.                     numSkeletons--;
  64.                     currentSkeletonHealth = skeletonHealth;
  65.                 }
  66.             }
  67.             //now its skellys turn!
  68.             turn = 'S';
  69.  
  70.         } else { // if its not humans turn, then we know its skellys turn!
  71.  
  72.             if (attackResult <= skeletonAttack) {
  73.                 currentHumanHealth -= skeletonDamage;
  74.  
  75.                 if (currentHumanHealth < 0) {
  76.                     numHumans--;
  77.                     currentHumanHealth = humanHealth;
  78.                 }
  79.             }
  80.             //now its humans turn!
  81.             turn = 'H';
  82.  
  83.         }
  84.  
  85.     }
  86.  
  87.     cout << "\nBattle is over!\n\n";
  88.  
  89.     //print out the results!
  90.     if (numHumans > 0) {
  91.         cout << "Humans won!\n";
  92.         cout << "There are " << numHumans << " humans left!\n";
  93.     } else {
  94.         cout << "Skeletons won!\n";
  95.         cout << "There are " << numSkeletons << " skeletons left!\n";
  96.     }
  97.  
  98.     //KILL COUNTER!
  99.     cout << startHumans - numHumans << " humans and " << startSkeletons - numSkeletons << " skeletons lost their lives.\n\n";
  100.  
  101.     system("PAUSE");
  102.     return 0;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment