Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- *
- * @Name : 1D Combat Simulator 2014
- *
- * @Author : Jeremias N
- * @Copyright : 2014 GPL
- * @Version : 0.1b
- *
- * @Notes : This is a 1D combat simulator created for the video series of Making Games with Ben
- * this is the first challenge.
- * more info: https://www.youtube.com/watch?v=TH7plF4UT_E
- *
- */
- #include <iostream>
- #include <string>
- #include <random>
- #include <ctime>
- using namespace std;
- int main()
- {
- //
- default_random_engine randomGenerator(time(NULL));
- uniform_real_distribution < float > attackRoll(0.0f, 1.0f);
- // vars for our humans
- float hAttack = 0.4f;
- float hHealth = 100.0f;
- float hDamage = 70.0f;
- float chHealth = hHealth;
- // var for our cyborg zombies
- float cZombiesAttack = 0.2f;
- float cZombiesHealth = 70.0f;
- float cZombiesDamage = 55.0f;
- float czHealth = cZombiesHealth;
- // games vars
- float aResults;
- int NumbersHumans;
- int NumbersZombies;
- // lets print our game name at the top
- cout << " ######################################### \n";
- cout << " ############# CYBORG ZOMBIES ############ \n";
- cout << " ################### VS ################# \n";
- cout << " ############### Humans ############# \n";
- cout << " ######################################### \n";
- cout << " ########Copyright Jeremias 2014########## \n";
- cout << " ######################################### \n\n\n";
- // Lets get the numbers of humans and zombies
- cout << "Type the numbers of Zombies? \n\n";
- cin >> NumbersZombies;
- cout << "Type the numbers of Humans? \n\n";
- cin >> NumbersHumans;
- /*
- * lets allow the player to choose which one is going to
- * attack first
- */
- bool turn;
- cout << "Which one do you want to attack First? \n";
- cout << "Type 1 for the Cyborg Zombies attack first \n";
- cout << "Or type 0 if you want the Humans first \n";
- cin >> turn;
- /* we create our while for the simulation
- * and we check which turn is for the attack
- */
- while (NumbersHumans > 0 && NumbersZombies >0)
- {
- // attack
- aResults = attackRoll(randomGenerator);
- // Zombies strike first
- if (turn == true)
- {
- // success
- if (aResults <= cZombiesAttack)
- {
- chHealth -= cZombiesDamage;
- // Die
- if (chHealth < 0)
- {
- NumbersHumans--;
- chHealth = hHealth;
- }
- }
- turn = false;
- }
- else if(turn == false){
- if (aResults <= hAttack)
- {
- czHealth -= hDamage;
- // Die
- if (czHealth < 0)
- {
- NumbersZombies--;
- czHealth = cZombiesHealth;
- }
- }
- turn = true;
- }
- else{
- //if the user type anything else, we will give an error
- cout << "This is no a valid Option! \n";
- system("PAUSE");
- }
- }
- cout << "Battle is Over \n\n";
- if (NumbersZombies > 0)
- {
- cout << "Cybog Zombies Won \n\n";
- cout << " There are " << NumbersZombies << " Zombies lef\n\n";
- }
- else{
- cout << "Humans Won \n\n";
- cout << " There are " << NumbersHumans << " Humans lef\n\n";
- }
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement