-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
215 lines (176 loc) · 4.08 KB
/
main.c
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <pthread.h>
#include <sys/socket.h>
/* #include <signal.h> */
/* TODO: Add signal handlers */
#ifdef _WIN32
#include <windows.h>
#else
#ifdef __linux
#include <unistd.h>
#define Sleep(time) usleep((time)*1000)
#endif
#endif
#define NAMES_SIZE 57
/* These names from Diablo II =) */
char * names[] = { "Amazon", "Assassin", "Sorceress",
"Paladin", "Necromancer", "Druid",
"Barbarian", "Akara", "Warriv",
"Anya", "Larzuk", "Natalya",
"Asheara", "Charsi", "Tyrael",
"Deckard", "Flavie", "Gheed",
"Kashya", "Atma", "Drognan",
"Elzix", "Fara", "Geglash",
"Greiz", "Jehryn", "Kaelan",
"Lysander", "Meshif", "Ormus",
"Alkor", "Hratli", "Halbu",
"Jamella", "Malah", "Nihlatak",
"Qual-Kehk", "Diablo", "Mephisto",
"Baal", "Duriel", "Radament",
"Andariel", "Rakanishu", "Torum",
"Negative", "Adrn", "Firk",
"Obsessed", "Grin", "Xardas",
"Plain", "Muny", "Archeg",
"Myatko", "Irknet", "Aler"
};
char ** zombie = NULL;
int zombie_size = 0;
pthread_t pthread;
pthread_attr_t attr;
int killme, score;
int zomb_time = 3000;
int wave = 0;
void zombies_lookout()
{
int i = 0;
for(i = 0; i < zombie_size; i++)
printf("Zombie \"%s\".\n", zombie[i]);
return;
}
int zombies_check_corpses()
{
int i, corpse_count;
for(i = 0; i < zombie_size; i++) {
if(!strcmp(zombie[i], "_CORPSE"))
corpse_count++;
}
return corpse_count;
}
int zombies_reload_ammo(int ammo)
{
printf("Reloading shotgun...\n");
Sleep(3000);
ammo = 7;
return ammo;
}
int zombies_start()
{
int i = 0;
/* Destroying old zombies, before we can allocate new zombies =) */
free(zombie);
srand(time(NULL));
wave++;
zombie_size += 5;
/* Allocate memory for zombies */
zombie = malloc(sizeof(char *) * zombie_size);
/* fill array with zombie names */
for(i = 0; i < zombie_size; i++) {
zombie[i] = strdup(names[rand() % NAMES_SIZE]);
}
printf("Wave %d, get ready...\n", wave);
Sleep(3000);
zombies_lookout();
for(i = 0; i < zombie_size; i++) {
if(strcmp(zombie[i], "_CORPSE")) {
printf("Zombie \"%s\" is nearby, shoot them NOW!!!\n", zombie[i]);
Sleep(zomb_time);
}
else {
Sleep(zomb_time);
if(zombies_check_corpses() == zombie_size)
return 0;
}
if(strcmp(zombie[i], "_CORPSE")) {
printf("\nZombie \"%s\" kill you!\n", zombie[i]);
printf("You was eaten by zombies.\n");
printf("Your dead of valor will be remembered.\n");
killme = 1;
printf("Your score: %d zombies.\n", score);
/* Free the zombie array and shutdown */
free(zombie);
exit(0);
}
}
if(wave % 5 == 0) {
if(zomb_time > 1300) {
zomb_time-=200;
printf("Zombie time has increased...\n");
}
zombie_size = 0;
}
return 0;
}
static void * threadfunc(void * arg)
{
while(1) {
zombies_start();
/* .... */
}
}
int shoot()
{
char * target = malloc(255);
int i = 0;
static char ammo = 7;
Sleep(1);
printf("Target: ");
scanf("%s", target);
if(!strcmp(target, "l")) {
zombies_lookout();
return 1;
}
else if(!strcmp(target, "a")) {
printf("Ammo: %d/7\n", ammo);
return 1;
}
else if(!strcmp(target, "r")) {
ammo = zombies_reload_ammo(ammo);
return 1;
}
if(ammo == 0) {
printf("You have no ammo in the shotgun.\n");
return 1;
}
else if(!strcmp(target, "_CORPSE")) {
printf("You can't kill corpse, lol\n");
ammo--;
return 1;
}
printf("Player shoots with good shotgun...\n");
ammo--;
for(i = 0; i < zombie_size; i++) {
if(!strcmp(zombie[i], target)) {
strcpy(zombie[i], "_CORPSE");
printf("Zombie killed!\n\n");
score++;
return 0;
}
}
printf("You are missed, zombie is still alive...\n");
return 1;
}
int main()
{
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
Sleep(1);
/* Start the main thread */
pthread_create(&pthread, &attr, threadfunc, NULL);
while(1) {
shoot();
}
return 0;
}