@tiki720/

Survive 2

C

No description

fork
loading
Files
  • main.c
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
#include "stdio.h"
#include "stdbool.h"
#include "stdlib.h"
#include "string.h"
#include "time.h"
#include "unistd.h"
int random_number(int min_num, int max_num);
int AreaItems[9][12]={
	{0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0,0,0,0}
};
char *Items[2][12]={
	{"DT","BA","FL","AX","TC","TF","WI","SB","ED","HA","JC","WA"},
	{"Duct tape","Battery","Flashlight","Axe","Tin can","Tin foil","Wire","Shattered Bottle","Energy drink","Hammer","Jerry can","Water"}
};
char *Phrases[6] = {"You find yourself in a","You are now in a","The place you are at is a","You are in a","The place you are at is a"};
int Inventory[12]=
{0,0,0,0,0,0,0,0,0,0,0,0};
int NESW[11][4]={
	{0,2,4,0}, //1
	{0,3,5,1}, //2
	{0,0,6,2}, //3
	{1,5,7,0}, //4
	{2,6,8,4}, //5
	{3,0,9,5}, //6
	{4,8,0,0}, //7
	{5,9,0,7}, //8
	{6,0,0,8}  //9
};
bool Visit[9]={false,false,false,false,false,false,false,false,false};
char *Classification[2][11]={
	{"","","","","","","","","","",""},
	{"","","","","","","","","","",""}
};
char *DifClass[2][5]={
	{"Abandoned","Scorched","Ransacked","Burntdown","Empty"},
	{"House","Apartement","Duplex","Hotel","Park"}
};
char Input[30];
int bn = 0;
int z,x,c,v,y;
int Location=0;
int CreatureLocation[3]={0,0,0};//Zombie,Bunny,Mouse
int Town=1;
bool Run=true;
bool Play=true;
bool Compass=false;
bool North=false;
bool East=false;
bool South=false;
bool West=false;
bool CreatureNorth=false;
bool CreatureEast=false;
bool CreatureSouth=false;
bool CreatureWest=false;
int main(void) {
	
	
//Starting to make the random "SEED"
printf("Randomizing the map(this will take around 30sec)\n");
for(z=0;z<9;z++){
time_t t;
srand((unsigned) time(&t));
sleep(1);
Classification[1][z]=DifClass[1][random_number(0,4)];
//printf("%d",random_number(0,4));
sleep(1);
Classification[0][z]=DifClass[0][random_number(0,4)];
//printf("%d",random_number(0,4));
}
printf("\n");
/*
for(z=0;z<9;z++){
printf("%s ",Classification[0][z]);
printf("%s \n",Classification[1][z]);
}
*/
printf("Halfway\n");
for(v=0;v<10;v++){AreaItems[random_number(0,8)][1]+=1;sleep(1);}
AreaItems[random_number(0,8)][10]+=1;sleep(1);
AreaItems[random_number(0,8)][6]+=1;sleep(1);
AreaItems[random_number(0,8)][2]+=1;sleep(1);
/*
for(x=0;x<9;x++){
for(z=0;z<12;z++){
printf("%d",AreaItems[x][z]);
}
printf("  (%d) \n",x);
}
*/

//Starting The Game
printf("Welcome to Survive\nThe goal of this game for now is to leave town\nThe controls are:\n(Search/S) to search the area\n(Inventory/I) for inventory\n(Exit/E) to leave the area\n(Map/M) to open up the map\n");
printf("Would you like to start?\n(Yes/No)");
scanf("%s",Input);
if (strncmp(Input,"Yes",3)==0){
while(Play == true){
	

//Creature Locations (¬°-°)¬ ≈('-')≈ <:3)~~
c = random_number(1,3);
sleep(1);
z = random_number(0,2);
if(NESW[CreatureLocation[z]][c]!=0){
CreatureLocation[z]=NESW[CreatureLocation[z]][c]-1;
}
/*
printf("\n%d",CreatureLocation[0]);
printf("%d",CreatureLocation[1]);
printf("%d\n",CreatureLocation[2]);
if(Location==CreatureLocation[0]){printf("(¬°-°)¬\n");}
if(Location==CreatureLocation[1]){printf("≈('-')≈\n");}
if(Location==CreatureLocation[2]){printf("<:3)~~\n");}
*/

//Running the game
bn++;
if(bn == 4){bn=1;}
Visit[Location]=true;
printf("%s",Phrases[bn]);
if(strncmp(Classification[0][Location], "A" ,1)==0 || strncmp(Classification[0][Location], "E" ,1)==0){printf("n ");}else{printf(" ");}
printf("%s %s \n",Classification[0][Location],Classification[1][Location]);


//Leaving Town Code
if(Location==6){
printf("There is a car outside; to start the car you need\n");
printf("%dx more Jerry cans\n%dx more Batteries\n%dx more Wire\n%dx Flashlight\n",1-Inventory[10],3-Inventory[1],1-Inventory[6],1-Inventory[2]);
}
if((1-Inventory[10])+(3-Inventory[1])+(1-Inventory[6])+(1-Inventory[2])<=0&&Location==6){
printf("Would you like to leave this town and go on to the next?\n");
scanf("%s",Input);
if(strncmp(Input, "Yes",3)==0){
Play=false;
Run=false;
}
}
if(Run==true){
printf("%d",Location);
scanf("%s", Input);



//Search Code
if (strncmp(Input, "Search",1)==0){
for(x=0;x<12;x++){
if(AreaItems[Location][x]>0){
Inventory[x]+=AreaItems[Location][x];
printf("You found a %s ",Items[1][x]);
printf("x%d \n",AreaItems[Location][x]);
}
else if(AreaItems[Location][x]==1){printf("\n");}
AreaItems[Location][x]=0;
}
}


//Inventory Code
if (strncmp(Input, "Inventory",1)==0){
printf("You have:\n\n");
z=0;
for(c=0;c<12;c++){
if(Inventory[c]>=1){
printf("x%d %s\n",Inventory[c],Items[1][c]);
}
}
}


//Map Code
if (strncmp(Input, "Map", 1)==0){
printf("\nHere is the Map\n");
v=0;
for (x=0;x<3;x++){
for (y=0;y<3;y++){
v++;
printf(" %d",v);
}
printf("\n");
}
for (x=0;x<9;x++){
printf("\n#%d-",x+1);
if (Visit[x]==true){
printf("%s  ",Classification[0][x]);
}else{
printf("???  ");
}
printf("%s",Classification[1][x]);
}
printf("\n");
}


//Travelling Code
if (strncmp(Input, "Exit",1)==0){
printf("Where would you like to go?\n");
if(NESW[Location][0]>0){printf("North\n");North=true;}
if(NESW[Location][1]>0){printf("East\n");East=true;}
if(NESW[Location][3]>0){printf("West\n");West=true;}
if(NESW[Location][2]>0){printf("South\n");South=true;}
}
if(North==true||East==true||South==true||West==true){
scanf("%s",Input);
if(strncmp(Input,"North",5)==0&&North==true){Location=NESW[Location][0]-1;}
if(strncmp(Input,"East",4)==0&&East==true){Location=NESW[Location][1]-1;}
if(strncmp(Input,"South",5)==0&&South==true){Location=NESW[Location][2]-1;}
if(strncmp(Input,"West",4)==0&&West==true){Location=NESW[Location][3]-1;}
}
North=false;East=false;South=false;West=false;
}
}
}else{printf("Fine be that way!\n");}
return 0;
}


//Randomizing Function
int random_number(int min_num, int max_num){
int result = 0, loWWnum = 0, hi_num = 0;
if (min_num < max_num)
{
loWWnum = min_num;
hi_num = max_num + 1;
}else{
loWWnum = max_num + 1;
hi_num = min_num;
}
srand(time(NULL));
result = (rand() % (hi_num - loWWnum)) + loWWnum;
return result;
}