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