-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
48 lines (45 loc) · 1.25 KB
/
init.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
int getMapLineLength(int type) {
int line = 0;
int size = (sizeof(map[type]) / sizeof(map[type][0]));
while (map[type][line][0] != 0 && line < size) line++;
return line;
}
int getMapLineMaxBlocks(int type) {
int max = 0, i, j, k;
for (i = 0; i < mapSize[type]; ++i) {
j = 0;
while(map[type][i][j] != 0) j++;
if (j > max) max = j;
}
return max;
}
void clearUserMap() {
int i, j;
for (i = 0; i < 100; i++) {
for (j = 0; j < 100; j++) {
userMap[i][j] = 0;
}
}
}
void init() {
//int length = sizeof(maps) / sizeof(maps[0]);
srand((unsigned int)time(NULL) + (unsigned int)getpid());
//int mapId = rand() % length;
unsigned int mapId = rand() % (sizeof(maps) / sizeof(maps[0]));
mapId = 1; // 开发时以第二张地图进行测试
//printf("%d\n", id);
//map = maps[mapId];
memcpy(map, maps[mapId], sizeof(maps[mapId]));
mapSize[0] = getMapLineLength(0); // map 的行数
mapSize[1] = getMapLineLength(1); // map 的列数
mapMaxBlocks[0] = getMapLineMaxBlocks(0); // map 的行数
mapMaxBlocks[1] = getMapLineMaxBlocks(1); // map 的列数
//printf("%d %d\n", mapSize[0], mapSize[1]);
printf("%d %d\n", mapMaxBlocks[0], mapMaxBlocks[1]);
if (!firstRun) {
pointer[0] = pointer[1] = 0;
//printf("%d %d\n", pointer[0], pointer[1]);
clearUserMap();
firstRun = 1;
}
}