Advertisement
theTANCO

Game Challenge 1: 1D Combat Simulator

Feb 11th, 2023 (edited)
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. // MakingGamesWithBen Game Challenge 1: 1D Combat Simulator 2014
  2. // https://www.youtube.com/watch?v=TH7plF4UT_E&list=PLSPw4ASQYyynKPY0I-QFHK0iJTjnvNUys&index=10
  3. // This program references the great war between the two main factions from the Ascension Academy roleplay series.
  4.  
  5. #include <iostream>
  6. #include <random>
  7. #include <ctime>
  8.  
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13.     float power1 = 44.5f;
  14.     float power2 = 81.0f;
  15.     int size1 = 8000;
  16.     int size2 = 5000;
  17.     int starting1 = size1;
  18.     int starting2 = size2;
  19.     float health1;
  20.     float health2;
  21.     float hit1;
  22.     float hit2;
  23.     float doHit;
  24.     mt19937 randGen(time(0)); // Random Generator
  25.     uniform_real_distribution genRoll(0.0f, 1.0f); // Generic Dice Roll
  26.  
  27.     cout << "Cross-Allied Forces vs. the Army of Darkness!\n\n";
  28.  
  29.     cout << "Combat has started!\n";
  30.  
  31.     cout << "\n*Combat noises*\n";
  32.  
  33.     health1 = genRoll(randGen) * power1 + power1 / 4;
  34.     health2 = genRoll(randGen) * power2 + power2 / 4;
  35.     hit1 = genRoll(randGen) * power1 + power1 / 8;
  36.     hit2 = genRoll(randGen) * power2 + power2 / 8;
  37.     while(size1 > 0 && size2 > 0){
  38.         while(health1 > 0 && health2 > 0){
  39.             doHit = genRoll(randGen) * (hit1 + hit2);
  40.             if(doHit < power1){
  41.                 health2 -= power1;
  42.             }else{
  43.                 health1 -= power2;
  44.             }
  45.         }
  46.         if(health1 <= 0){
  47.             size1--;
  48.             health1 = genRoll(randGen) * power1 + power1 / 4;
  49.             hit1 = genRoll(randGen) * power1 + power1 / 8;
  50.         }else if(health2 <= 0){
  51.             size2--;
  52.             health2 = genRoll(randGen) * power2 + power2 / 4;
  53.             hit2 = genRoll(randGen) * power2 + power2 / 8;
  54.  
  55.         }
  56.     }
  57.  
  58.     cout << "\nThe battle has ended!\n\n";
  59.  
  60.     cout << "There are " << size1 << " warriors left in the CAF.\n";
  61.     cout << "There are " << size2 << " warriors left in the AoD.\n\n";
  62.  
  63.     // Extra else if statements in case something weird happens with the results.
  64.     if(size1 == 0 && size2 > 0){
  65.         cout << "The Darkness wins!\n";
  66.     }else if(size1 > 0 && size2 == 0){
  67.         cout << "The CAF wins!\n";
  68.     }else if(size1 == 0 && size2 == 0){
  69.         cout << "Somehow there was a draw!\n";
  70.     }else{
  71.         cout << "There was a truce? How could that be?!\n";
  72.     }
  73.     cout << "The CAF lost " << starting1-size1 << " warriors and the Darkness lost " << starting2-size2 << " warriors.\n";
  74.  
  75.     system("PAUSE");
  76.     return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement