-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.c
88 lines (70 loc) · 2.35 KB
/
log.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
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "log.h"
void show_log(lList* log_list) {
int i, round = 0;
t_log* log;
printf("\nA guerra até aqui:\n");
for (i = 0; i < log_list->size; i++) {
log = (t_log*) getDadoAtIndex(log_list, i);
if (log->round != round) {
printLog(log, true); /* o booleano aqui diz se devemos imprimir antes em que round estamos ou não */
round = log->round;
} else {
printLog(log, false);
}
}
if (round != TREE_MAX_LEVEL) {
printf("\nÉ uma pena que você não pode ver como isso acaba.\nAdeus...\n");
}
}
/*-----------------------------------------------------------------------------*/
t_log* create_log(Character* player1, Character* player2, int round, Stat used_attr) {
t_log* log = (t_log*) malloc(sizeof(t_log));
if (!log) {
printf("\nERRO: falha na alocacao de memoria em create_log()...");
exit(-1);
}
log->player1 = player1;
log->player2 = player2;
log->round = round;
log->used_attr = used_attr;
return log;
}
/*-----------------------------------------------------------------------------*/
void printLog(t_log* log, bool printRound) {
if (printRound)
printf("\nROUND %d:\n", log->round);
int stat1, stat2;
char* stat = (char*) malloc(20 * sizeof(char));
switch (log->used_attr) {
case AGILITY:
strcpy(stat, "agility");
stat1 = log->player1->agility;
stat2 = log->player2->agility;
break;
case STRENGTH:
strcpy(stat, "strength");
stat1 = log->player1->strength;
stat2 = log->player2->strength;
break;
case INTELLIGENCE:
strcpy(stat, "intelligence");
stat1 = log->player1->intelligence;
stat2 = log->player2->intelligence;
break;
case HEALTH:
strcpy(stat, "health");
stat1 = log->player1->health;
stat2 = log->player2->health;
break;
}
printf("%s (%d %s) vs. %s (%d %s)\n", log->player1->name, stat1,
stat, log->player2->name, stat2, stat);
free(stat);
}
/*-----------------------------------------------------------------------------*/
void log_free(t_log* fight_log) {
free(fight_log);
}