Advertisement
Shamyne

Untitled

Nov 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <time.h>
  5. using namespace std;
  6.  
  7. int createZombie() {
  8. if (rand() % 67 < 10)
  9. return 11;
  10.  
  11. else
  12. return rand() % 10 + 1;
  13. }
  14.  
  15. int main() {
  16. srand(time(NULL));
  17. char enter;
  18.  
  19. // game stats
  20. int playerAlive = true;
  21. int playerSkill = 9;
  22. int playerScore = 1;
  23. string playerName = "";
  24. int zombieCount = 0;
  25. int zombiesKilled = 0;
  26.  
  27. // title
  28. cout << "Welcome to Zombie War." << endl << "Press [ENTER] to start.";
  29. cin.get();
  30.  
  31. // player name
  32. cout << "Please enter your name: ";
  33. cin >> playerName;
  34.  
  35. // ask how many zombies
  36. cout << "How many zombies do you wish to fight? ";
  37. cin >> zombieCount;
  38.  
  39. cout << "Get ready to fight for your life, " << playerName << "!" << endl;
  40.  
  41. // main game loop
  42. while (playerAlive && zombiesKilled < zombieCount) {
  43. // create a random zombie
  44. int zombieSkill = createZombie();
  45.  
  46. // battle sequence
  47. if (zombieSkill > 10) {
  48. cout << endl << "Here comes a huge zombie!" << endl;
  49. }
  50. else {
  51. cout << endl << "Here comes zombie " << zombiesKilled + 1 << endl;
  52. }
  53.  
  54. cout << "Fighting..." << endl;
  55. sleep(2);
  56.  
  57. // zombie killed the player
  58. if (playerSkill < zombieSkill) {
  59. playerAlive = false;
  60. cout << "You have died." << endl;
  61. }
  62.  
  63. // player killed the zombie
  64. else {
  65. if (playerSkill - zombieSkill > 7) {
  66. cout << "You wasted the zombie!" << endl;
  67. playerScore = playerScore * 2;
  68. }
  69.  
  70. else if (playerSkill - zombieSkill > 5) {
  71. cout << "You decapitated the zombie!" << endl;
  72. playerScore = playerScore * 2;
  73. }
  74.  
  75. else if (playerSkill - zombieSkill > 0) {
  76. cout << "You killed the zombie!" << endl;
  77. playerScore = playerScore * 2;
  78. }
  79.  
  80. else {
  81. cout << "You killed the zombie, but suffered injuries." << endl;
  82. }
  83.  
  84. zombiesKilled++;
  85. }
  86.  
  87. cout << endl;
  88. sleep(1);
  89. }
  90.  
  91. // end game
  92. if (zombiesKilled == zombieCount) {
  93. // victory
  94. cout << "You have survived the onslaught!" << endl;
  95. }
  96. else {
  97. // lost
  98. cout << "You did not survive the zombie war." << endl;
  99. }
  100.  
  101. cout << "Zombies killed: " << zombiesKilled << endl;
  102. cout << "Final score: " << playerScore << endl << endl;
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement