Advertisement
Guest User

Untitled

a guest
Oct 24th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. /*
  2. *
  3. * @Name : 1D Combat Simulator 2014
  4. *
  5. * @Author : Jeremias N
  6. * @Copyright : 2014 GPL
  7. * @Version : 0.1b
  8. *
  9. * @Notes : This is a 1D combat simulator created for the video series of Making Games with Ben
  10. * this is the first challenge.
  11. * more info: https://www.youtube.com/watch?v=TH7plF4UT_E
  12. *
  13. */
  14.  
  15. #include <iostream>
  16. #include <string>
  17. #include <random>
  18. #include <ctime>
  19.  
  20. using namespace std;
  21.  
  22. int main()
  23. {
  24. //
  25. default_random_engine randomGenerator(time(NULL));
  26. uniform_real_distribution < float > attackRoll(0.0f, 1.0f);
  27.  
  28.  
  29. // vars for our humans
  30. float hAttack = 0.4f;
  31. float hHealth = 100.0f;
  32. float hDamage = 70.0f;
  33. float chHealth = hHealth;
  34.  
  35.  
  36. // var for our cyborg zombies
  37. float cZombiesAttack = 0.2f;
  38. float cZombiesHealth = 70.0f;
  39. float cZombiesDamage = 55.0f;
  40. float czHealth = cZombiesHealth;
  41.  
  42.  
  43. // games vars
  44. float aResults;
  45.  
  46. int NumbersHumans;
  47. int NumbersZombies;
  48.  
  49. // lets print our game name at the top
  50. cout << " ######################################### \n";
  51. cout << " ############# CYBORG ZOMBIES ############ \n";
  52. cout << " ################### VS ################# \n";
  53. cout << " ############### Humans ############# \n";
  54. cout << " ######################################### \n";
  55. cout << " ########Copyright Jeremias 2014########## \n";
  56. cout << " ######################################### \n\n\n";
  57.  
  58.  
  59. // Lets get the numbers of humans and zombies
  60. cout << "Type the numbers of Zombies? \n\n";
  61. cin >> NumbersZombies;
  62.  
  63. cout << "Type the numbers of Humans? \n\n";
  64. cin >> NumbersHumans;
  65.  
  66. /*
  67. * lets allow the player to choose which one is going to
  68. * attack first
  69. */
  70.  
  71. bool turn;
  72. cout << "Which one do you want to attack First? \n";
  73. cout << "Type 1 for the Cyborg Zombies attack first \n";
  74. cout << "Or type 0 if you want the Humans first \n";
  75.  
  76. cin >> turn;
  77.  
  78.  
  79.  
  80.  
  81. /* we create our while for the simulation
  82. * and we check which turn is for the attack
  83. */
  84. while (NumbersHumans > 0 && NumbersZombies >0)
  85. {
  86. // attack
  87. aResults = attackRoll(randomGenerator);
  88.  
  89. // Zombies strike first
  90. if (turn == true)
  91. {
  92. // success
  93. if (aResults <= cZombiesAttack)
  94. {
  95. chHealth -= cZombiesDamage;
  96.  
  97. // Die
  98. if (chHealth < 0)
  99. {
  100. NumbersHumans--;
  101. chHealth = hHealth;
  102. }
  103. }
  104.  
  105. turn = false;
  106.  
  107. }
  108. else if(turn == false){
  109.  
  110. if (aResults <= hAttack)
  111. {
  112. czHealth -= hDamage;
  113.  
  114. // Die
  115. if (czHealth < 0)
  116. {
  117. NumbersZombies--;
  118. czHealth = cZombiesHealth;
  119. }
  120. }
  121. turn = true;
  122.  
  123. }
  124. else{
  125.  
  126. //if the user type anything else, we will give an error
  127. cout << "This is no a valid Option! \n";
  128. system("PAUSE");
  129.  
  130. }
  131. }
  132.  
  133. cout << "Battle is Over \n\n";
  134. if (NumbersZombies > 0)
  135. {
  136. cout << "Cybog Zombies Won \n\n";
  137. cout << " There are " << NumbersZombies << " Zombies lef\n\n";
  138. }
  139. else{
  140. cout << "Humans Won \n\n";
  141. cout << " There are " << NumbersHumans << " Humans lef\n\n";
  142. }
  143.  
  144. system("PAUSE");
  145. return 0;
  146. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement