Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <ctime>
- #include <random>
- using namespace std;
- int main(void) {
- //Get the input from user
- int numHumans;
- int numZombies;
- cout << "**Humans vs. Zombies**\n\n" << "How many Humans are there: ";
- cin >> numHumans;
- cout << "How many Zombies are there:";
- cin >> numZombies;
- cout << "CHARGE!!!!!!!!" << endl;
- //random number gen using time as the seed
- mt19937 randomGenerator(time(0));
- //random numbers attached to variable for humans and zombies
- uniform_real_distribution<float>attackHuman(1.00f, 2.00f);
- uniform_real_distribution<float>attackZombie(1.00f, 2.00f);
- int i = 0;
- int deadZombies = 0;
- int deadHumans = 0;
- //makes sure it loops once for each solider in both armys
- for (int i = 0; i < (numHumans + numZombies); i+= 1) {
- //checks to make sure there is still soliders in the amry
- while ((deadHumans <= numHumans) && (deadZombies <= numZombies)){
- // randomise attack
- float zombieATK = attackZombie(randomGenerator);
- float humanATK = attackHuman(randomGenerator);
- // refresh the health of both soliders
- float humanHP = 2.00f;
- float zombieHP = 2.00f;
- // deals the damage
- humanHP = humanHP - zombieATK;
- zombieHP = zombieHP - humanATK;
- // checks to see who did more
- if (humanHP > zombieHP) {
- deadZombies++;
- }
- else {
- deadHumans++;
- }
- // adds one to i which counts for one dead solider
- i++;
- }
- }
- cout << "zombies:" << deadZombies << endl;
- cout<< "humans:" << deadHumans << endl;
- // less dead = winners
- if (deadZombies < deadHumans) {
- cout << "ZOMBIES WIN!!!" << endl;
- }
- else {
- cout << "HUMANS WIN!!!!!" << endl;
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement