-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFight.c
More file actions
320 lines (280 loc) · 12.7 KB
/
Copy pathFight.c
File metadata and controls
320 lines (280 loc) · 12.7 KB
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
#include "Fight.h"
#include "Custom_structures.h"
#include "monster.h"
#if defined(_WIN32)
#include <windows.h>
#include <conio.h>
#endif
#include <time.h>
#include <stdio.h>
//#include<unistd.h>
/*************************************************************************/
/* FUNCTION NAME: Player_Choice */
/* DESCRIPTION: gets the player's choice */
/* ARGUMENT LIST: */
/* Argument Type IO Description */
/* _____________________ _________ ____ _________________________________*/
/* */
/* RETURN VALUE: int 1 for attack, 2 for dodge, 3 for heal */
/* CHANGES: - */
/*************************************************************************/
int Player_Choice(){
int p_choice;
printf("What do you want to do this round?\n1 -> attack\n2 -> dodge\n3 -> heal\n");
scanf("%d",&p_choice);
return p_choice;
}
/*************************************************************************/
/* FUNCTION NAME: The_Fight */
/* DESCRIPTION: emulates a fight with the monster */
/* ARGUMENT LIST: */
/* Argument Type IO Description */
/* _____________________ _________ ____ ________________________________*/
/* Player Character* I points to the variable that */
/* stores the player stats */
/* Monster Character I points to the variable that */
/* stores the monster stats */
/* round int I the round number */
/* level int I level */
/* RETURN VALUE: void */
/* CHANGES: - */
/*************************************************************************/
void The_Fight(Character *Player, Character *Monster, int round, int level){
Buff p,m;
p.attack = 0;
p.heal = 0;
p.protection = 0;
m.attack = 0;
m.heal = 0;
m.protection = 0;
char ASCII_minotaur2[] = "ASCII_minotaur2.txt";
rare_special_events(&p, round);
file_print(ASCII_minotaur2);
printf("\n\n");
int player_choice = Player_Choice();
//srand(time(NULL));
int monster_choice = MonsterChoice(level);
normal_special_events(monster_choice, &m, round, level);
if(monster_choice == 0)
printf("The monster missed!");
else if(monster_choice == 1)
{
if(player_choice == 2)
printf("The monster tried attack you!");
else
printf("The monster attacked you!");
}
else if(monster_choice == 3)
printf("The monster healed!");
else
printf("The monster dodged!");
//1-> attack 2->dodge 3->heal
switch (player_choice)
{
case 1:
{
Case_Attack(Player,Monster, monster_choice, p, m);
break;
}
case 2:
{
Case_Dodge(Player, Monster, monster_choice, p, m);
break;
}
case 3:
{
Case_Heal(Player, Monster, monster_choice, p, m);
break;
}
}
//free(monster_choice);
//sleep(5);
}
/*************************************************************************/
/* FUNCTION NAME: Display_Stats */
/* DESCRIPTION: distplays the stats of the player and monster */
/* ARGUMENT LIST: */
/* Argument Type IO Description */
/* _____________________ _________ ____ _________________________________*/
/* Player Character* I points to the variable that */
/* stores the player stats */
/* Monster Character I points to the variable that */
/* stores the monster stats */
/* RETURN VALUE: void */
/* CHANGES: - */
/*************************************************************************/
void Display_Stats(Character *Player, Character *Monster){
#if defined(_WIN32)
system("cls");
#else
system("clear");
#endif
printf("Your HP:%d \t\t\t\t\t\t\t\t\t\t\t\t Monster HP:%d\nYour attack:%d \t\t\t\t\t\t\t\t\t\t\t\t Monster attack:%d\nYour armor:%d \t\t\t\t\t\t\t\t\t\t\t\t Monster armor:%d\n", Player->life, Monster->life, Player->attack, Monster->attack, Player->armor, Monster->armor);
printf("---------------------------------------------------------------------------------------------------------------------------------------\n\n\n");
}
/*************************************************************************/
/* FUNCTION NAME: stop_fight */
/* DESCRIPTION: verifies if the fight can continue */
/* ARGUMENT LIST: */
/* Argument Type IO Description */
/* _____________________ _________ ____ _________________________________*/
/* Player Character* I points to the variable that */
/* stores the player stats */
/* Monster Character I points to the variable that */
/* stores the monster stats */
/* RETURN VALUE: int 0 for continue, 1 for stop */
/* CHANGES: - */
/*************************************************************************/
int stop_fight(Character *Player, Character *Monster){
if(Player->life<=0 || Monster->life<=0)
{
#if defined(_WIN32)
system("cls");
#else
system("clear");
#endif
printf("\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\tThe fight has ended!");
//sleep(3);
return 1;
}
return 0;
}
/*************************************************************************/
/* FUNCTION NAME: Case_Attack */
/* DESCRIPTION: posibilities if the player choses to attack */
/* ARGUMENT LIST: */
/* Argument Type IO Description */
/* _____________________ _________ ____ _________________________________*/
/* Player Character* I points to the variable that */
/* stores the player stats */
/* Monster Character I points to the variable that */
/* stores the monster stats */
/* monster_choice int I the choice of the monster */
/* p Buff I buffs for player */
/* m Buff I buffs for monster */
/* RETURN VALUE: void */
/* CHANGES: Player's and/or Monster HP */
/*************************************************************************/
void Case_Attack(Character *Player, Character *Monster, int monster_choice, Buff p, Buff m)
{
if(monster_choice == 0)
{
Monster->life -= Player->attack + p.attack - Monster->armor ;
MonsterLines(0);
}
if(monster_choice == 1)
{
Monster->life -= Player->attack + p.attack - Monster->armor - m.protection;
if(Player->armor + p.protection > Monster->attack + m.attack)
{
printf("\nYou are really protected!");
MonsterLines(0);
}
else
{
Player->life -= Monster->attack + m.attack - Player->armor -p.protection;
MonsterLines(1);
}
}
if(monster_choice == 2)
{
MonsterLines(2);
}
if(monster_choice == 3)
{
Monster->life -= Player->attack +p.attack - (Monster->armor + Monster->heal + m.heal +m.protection);
MonsterLines(3);
}
}
/*************************************************************************/
/* FUNCTION NAME: Case_Dodge */
/* DESCRIPTION: posibilities if the player choses to dodge */
/* ARGUMENT LIST: */
/* Argument Type IO Description */
/* _____________________ _________ ____ _________________________________*/
/* Player Character* I points to the variable that */
/* stores the player stats */
/* Monster Character I points to the variable that */
/* stores the monster stats */
/* monster_choice int I the choice of the monster */
/* p Buff I buffs for player */
/* m Buff I buffs for monster */
/* RETURN VALUE: void */
/* CHANGES: Player's and/or Monster HP */
/*************************************************************************/
void Case_Dodge(Character *Player, Character *Monster, int monster_choice, Buff p, Buff m)
{
if(monster_choice == 0)
{
printf("Nothing happened this round!\n");
}
if(monster_choice == 1)
{
//Monster->life -= Player->attack + p.attack - Monster->armor + m.protection;
//Player->life -= Monster->attack + m.attack - Player->armor +p.protection;
printf("You dodged the monster's attack!\n");
MonsterLines(0);
}
if(monster_choice == 2)
{
printf("Both tried to dodge.. nothing... nice!\n");
MonsterLines(2);
}
if(monster_choice == 3)
{
printf("Good job! You let the monster to heal in peace..");
Monster->life += Monster->heal + m.heal;
MonsterLines(3);
}
}
/*************************************************************************/
/* FUNCTION NAME: Case_Attack */
/* DESCRIPTION: posibilities if the player choses to heal */
/* ARGUMENT LIST: */
/* Argument Type IO Description */
/* _____________________ _________ ____ _________________________________*/
/* Player Character* I points to the variable that */
/* stores the player stats */
/* Monster Character I points to the variable that */
/* stores the monster stats */
/* monster_choice int I the choice of the monster */
/* p Buff I buffs for player */
/* m Buff I buffs for monster */
/* RETURN VALUE: void */
/* CHANGES: Player's and/or Monster HP */
/*************************************************************************/
void Case_Heal(Character *Player, Character *Monster, int monster_choice, Buff p, Buff m)
{
if(monster_choice == 0)
{
Player->life += Player->heal + p.heal;
MonsterLines(0);
}
if(monster_choice == 1)
{
if(Player->armor + p.protection + Player->heal + p.heal > Monster->attack + m.attack)
{
printf("\nYou are really protected!\n");
Player->life += Player->heal + p.heal;
MonsterLines(0);
}
else
{
Player->life -= Monster->attack + m.attack - Player->armor -p.protection;
Player->life += Player->heal + p.heal;
MonsterLines(1);
}
}
if(monster_choice == 2)
{
Player->life += Player->heal + p.heal;
MonsterLines(0);
}
if(monster_choice == 3)
{
printf("Selfcare time!");
Player->life += Player->heal + p.heal;
Monster->life += Monster->heal + m.heal;
MonsterLines(3);
}
}