-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobal.cpp
165 lines (153 loc) · 3.31 KB
/
Global.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
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
#include "Global.hpp"
#include <SWI-cpp.h>
#include <string.h>
int SW = 1400;
int SH = 1000;
int posInicialX = 0;
int posInicialY = 0;
int MyZeroX = 10;
int MyZeroY = 100 - (MyZeroX - 2);
int mapEdgeX = ((LN+1)*DFLTSIZE) + MyZeroX;
int mapEdgeY = ((LN+1)*DFLTSIZE) + MyZeroY;
char UltimaCasaAcessada = 0;
char CasaAtual = 0;
int NLoop = 0;
int GAME_STATE = 0;
int MESSAGE_STATE = 0;
static char mapa_global[LN][COL];
static char mapa_global_backup[LN][COL];
void retornaEvento(char ident, char* str) {
switch(ident) {
case 'P':
strcpy(str,"buraco"); break;
case 'T':
strcpy(str,"teleporter"); break;
case 'U':
strcpy(str,"powerUp"); break;
case 'O':
strcpy(str,"ouro"); break;
case 'D':
strcpy(str,"wumpus2"); break;
case 'd':
strcpy(str,"wumpus1"); break;
case 'E': case '.':
strcpy(str,"vazio"); break;
default:
printf("Desiste desse curso e vai fazer comunicacao\n\n"); exit(1);
}
}
void criaStringSala(char* str, int i, int j, char c) {
strcpy(str,"sala(");
char temp[15];
sprintf(temp,"%d", i+1);
strcat(str,temp);
strcat(str,",");
sprintf(temp,"%d", j+1);
strcat(str,temp);
strcat(str,",");
retornaEvento(c,temp);
strcat(str,temp);
strcat(str,")");
}
void le_mapa(void)
{
int i = 0;
int j = 0;
FILE *arq;
arq = fopen("mapa.txt", "r");
for(i=0; i<LN; i++)
{
for(j=0; j<COL; j++)
{
fscanf(arq," %c", &mapa_global[LN-(i+1)][j]);
//mapa_global[i][j] = '.';
//if(i==j) mapa_global[i][j] = 'T';
//mapa_global[i][j] = '.';
mapa_global_backup[LN-(i+1)][j]=mapa_global[LN-(i+1)][j];
}
}
for (i = 0; i < LN; i++)
for (j = 0; j < COL; j++) {
char minhaLindaString[30];
PlTermv assertArg(1);
criaStringSala(minhaLindaString,i,j,mapa_global[i][j]);
assertArg[0] = PlCompound(minhaLindaString);
//printf("%s\n", minhaLindaString);
PlQuery assert("assert",assertArg);
assert.next_solution();
}
{
PlTermv salaArg(3);
PlQuery sala("sala",salaArg);
while(sala.next_solution()) {
printf("sala(%d,%d,%s)\n",(int)salaArg[0],(int)salaArg[1],(char*)salaArg[2]);
}
}
{
PlTermv NoArg(0);
PlQuery iniciar("iniciar",NoArg);
iniciar.next_solution();
}
mapa_global[LN-(j+1)][i] = 'E';
fclose(arq);
}
void passa_mapa(char matriz[LN][COL])
{
int i = 0;
int j = 0;
for(i=0; i<LN; i++)
{
for(j=0; j<LN; j++)
{
matriz[i][j] = mapa_global[i][j];
}
}
}
void deleta_ponto(int x, int y)
{
mapa_global[x][y] = CasaVazia;
}
void passa_backup(char matriz[LN][COL])
{
int i = 0;
int j = 0;
for(i=0; i<LN; i++)
{
for(j=0; j<LN; j++)
{
matriz[i][j] = mapa_global_backup[i][j];
}
}
}
int in_range(int time, int min, int max)
{
if(time >= min && time <= max)
{
return 1;
}
return 0;
}
int get_range(int duration, int nframes)
{
int value;
value = (duration/nframes);
return value;
}
void adjust_scale(float scale, int tile_size, int* x, int *y, int *size)
{
float posfixer;
posfixer = ( (1.f - scale)/2.f )* (float)tile_size;
*x = *x + (int)posfixer;
*y = *y + (int)posfixer;
*size = (int)((float)(*size) * scale);
}
int in_range_delayed(int _time, int prop, int acclrt)
{
int time;
time = (_time / acclrt)%100;
if(time <= (prop/acclrt))
{
return 1;
}
return 0;
}