Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MakingGamesWithBen Game Challenge 1: 1D Combat Simulator 2014
- // https://www.youtube.com/watch?v=TH7plF4UT_E&list=PLSPw4ASQYyynKPY0I-QFHK0iJTjnvNUys&index=10
- // This program references the great war between the two main factions from the Ascension Academy roleplay series.
- #include <iostream>
- #include <random>
- #include <ctime>
- using namespace std;
- int main()
- {
- float power1 = 44.5f;
- float power2 = 81.0f;
- int size1 = 8000;
- int size2 = 5000;
- int starting1 = size1;
- int starting2 = size2;
- float health1;
- float health2;
- float hit1;
- float hit2;
- float doHit;
- mt19937 randGen(time(0)); // Random Generator
- uniform_real_distribution genRoll(0.0f, 1.0f); // Generic Dice Roll
- cout << "Cross-Allied Forces vs. the Army of Darkness!\n\n";
- cout << "Combat has started!\n";
- cout << "\n*Combat noises*\n";
- health1 = genRoll(randGen) * power1 + power1 / 4;
- health2 = genRoll(randGen) * power2 + power2 / 4;
- hit1 = genRoll(randGen) * power1 + power1 / 8;
- hit2 = genRoll(randGen) * power2 + power2 / 8;
- while(size1 > 0 && size2 > 0){
- while(health1 > 0 && health2 > 0){
- doHit = genRoll(randGen) * (hit1 + hit2);
- if(doHit < power1){
- health2 -= power1;
- }else{
- health1 -= power2;
- }
- }
- if(health1 <= 0){
- size1--;
- health1 = genRoll(randGen) * power1 + power1 / 4;
- hit1 = genRoll(randGen) * power1 + power1 / 8;
- }else if(health2 <= 0){
- size2--;
- health2 = genRoll(randGen) * power2 + power2 / 4;
- hit2 = genRoll(randGen) * power2 + power2 / 8;
- }
- }
- cout << "\nThe battle has ended!\n\n";
- cout << "There are " << size1 << " warriors left in the CAF.\n";
- cout << "There are " << size2 << " warriors left in the AoD.\n\n";
- // Extra else if statements in case something weird happens with the results.
- if(size1 == 0 && size2 > 0){
- cout << "The Darkness wins!\n";
- }else if(size1 > 0 && size2 == 0){
- cout << "The CAF wins!\n";
- }else if(size1 == 0 && size2 == 0){
- cout << "Somehow there was a draw!\n";
- }else{
- cout << "There was a truce? How could that be?!\n";
- }
- cout << "The CAF lost " << starting1-size1 << " warriors and the Darkness lost " << starting2-size2 << " warriors.\n";
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement