Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- #include <string.h>
- int mapid, maxa, maxb, a, b;
- int pa, pb, paa, pbb;
- int over = 0;
- int map[35][21][20];
- int wall_list[21][20];
- int road_list[210];
- int enemy_list[35][150];
- int road_count = 0;
- int designed_map[8][21][20] =
- {
- {
- {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,1200,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,1200,0,0,0,0,0,0,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1},
- {1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1},
- {1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1},
- {1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
- {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
- }
- };
- // 미로 생성 관련 함수 :
- // int mapprnt(), int mapprnt_p(), int wall_check(int a, int b, int type)
- // int outer_check(int a, int b), int road(int a, int b), int mazegen(int ma, int mb)
- int mapprnt(int id)
- // map[mapid][a][b] 에 대한 전체 맵 출력.
- {
- int a,b;
- for (a = 1 ; a < sizeof(map[0]) / sizeof(map[0][0]) ; a++)
- { // 헤더 부분을 출력하지 않도록 a = 1 로 설정
- for (b = 0; b < sizeof(map[0][0]) / sizeof(map[0][0][0]) ; b++)
- {
- switch (map[id][a][b])
- {
- case 0 : printf (" "); break;
- case 1 : printf ("[]"); break;
- case 2 : printf ("M "); break;
- case 3 : printf ("UP"); break;
- case 4 : printf ("DN"); break;
- case 8 : printf ("# "); break;
- default :
- if (map[id][a][b] >= 100 && map[id][a][b] < 200)
- {
- printf ("@ ");
- }
- if (map[id][a][b] >= 1000)
- {
- printf ("%% ");
- }
- break;
- }
- }
- printf ("\n");
- }
- printf ("\n");
- return 0;
- }
- int mapprnt_p(int id)
- // map[mapid][a][b] 에 대한 전체 맵 출력. 플레이어 4방향 3칸까지만 보이게 출력.
- // 나머지 보이지 않는 영역은 || 로 표시한다.
- {
- int a,b;
- for (a = 1 ; a < sizeof(map[0]) / sizeof(map[0][0]) ; a++)
- { // 헤더 부분을 출력하지 않도록 a = 1 로 설정
- for (b = 0; b < sizeof(map[0][0]) / sizeof(map[0][0][0]) ; b++)
- {
- if (a >= pa-3 && a <= pa+3 && b >= pb-3 && b <= pb+3)
- {
- switch (map[id][a][b])
- {
- case 0 : printf (" "); break;
- case 1 : printf ("[]"); break;
- case 2 : printf ("M "); break;
- case 3 : printf ("UP"); break;
- case 4 : printf ("DN"); break;
- case 8 : printf ("# "); break;
- default :
- if (map[id][a][b] >= 100 && map[id][a][b] < 200)
- {
- printf ("@ ");
- }
- if (map[id][a][b] >= 1000)
- {
- printf ("%% ");
- }
- break;
- }
- }
- else
- {
- printf ("||");
- }
- }
- printf ("\n");
- }
- printf ("\n");
- return 0;
- }
- int mapprnt_s(int id, int a, int b, int sight)
- // map[mapid][a][b] 에 대해 (a,b) 좌표 주변 4방향 7칸까지만 보이게 출력.
- // 배열에 포함되지 않는 부분은 안보임 표시로 출력함.
- // 시야 시스템 추가. (원형 : sight가 반지름)
- {
- int i,j;
- for (i = a-6 ; i <= a+8 ; i++)
- { // 헤더 부분을 출력하지 않도록 a = 1 로 설정
- for (j = b-7; j <= b+7 ; j++)
- {
- if (i >= 1 && i < sizeof(map[0]) / sizeof(map[0][0]) && j >= 0 && j < sizeof(map[0][0]) / sizeof(map[0][0][0]))
- {
- if (((i-a) * (i-a)) + ((j-b) * (j-b)) <= (sight * sight))
- {
- switch (map[id][i][j])
- {
- case 0 : printf ("::"); break;
- case 1 : printf ("[]"); break;
- case 2 : printf ("M "); break;
- case 3 : printf ("UP"); break;
- case 4 : printf ("DN"); break;
- case 8 : printf ("# "); break;
- default :
- if (map[id][i][j] >= 100 && map[id][i][j] < 200)
- {
- printf ("@ ");
- }
- if (map[id][i][j] >= 1000)
- {
- printf ("%% ");
- }
- break;
- }
- }
- else
- {
- printf ("##");
- }
- }
- else
- {
- printf ("##");
- }
- }
- printf ("\n");
- }
- printf ("\n");
- return 0;
- }
- int mapp (int id, int sight)
- {
- switch (sight)
- {
- case 0 : mapprnt_p(id); break;
- case 1 : mapprnt(id); break;
- }
- return 0;
- }
- int wall_check(int id, int a, int b, int type)
- // 선택된 좌표 a,b 의 주변 벽이 몇 개인지 세어 그 수를 반환함.
- // type = 1이면 주변 벽들을 벽 리스트에 저장함.
- // type = 2이면 외곽 벽의 개수를 반환함.
- {
- if (type != 2)
- {
- int count = 0;
- if (map[id][a][b+1] == 1)
- {
- count++;
- if (type == 1 && wall_list[a][b+1] != 2)
- {
- wall_list[a][b+1] = 1;
- }
- }
- if (map[id][a][b-1] == 1)
- {
- count++;
- if (type == 1 && wall_list[a][b-1] != 2)
- {
- wall_list[a][b-1] = 1;
- }
- }
- if (map[id][a+1][b] == 1)
- {
- count++;
- if (type == 1 && wall_list[a+1][b] != 2)
- {
- wall_list[a+1][b] = 1;
- }
- }
- if (map[id][a-1][b] == 1)
- {
- count++;
- if (type == 1 && wall_list[a-1][b] != 2)
- {
- wall_list[a-1][b] = 1;
- }
- }
- return count;
- }
- else if (type == 2)
- {
- int outer_count = 0;
- if (wall_list[a][b+1] == 2)
- {
- outer_count++;
- }
- if (wall_list[a][b-1] == 2)
- {
- outer_count++;
- }
- if (wall_list[a+1][b] == 2)
- {
- outer_count++;
- }
- if (wall_list[a-1][b] == 2)
- {
- outer_count++;
- }
- return outer_count;
- }
- }
- int road(int id, int a, int b)
- // 현 좌표가 길이면 길 리스트에 저장함.
- // (a, b) 를 a*100 + b 형태로 저장한다. [(2,3) 의 경우 203으로 저장됨]
- {
- if (map[id][a][b] == 0)
- {
- road_list[road_count] = a*100 + b;
- }
- road_count++;
- }
- int mazegen(int id, int ma, int mb)
- // 미로 생성 함수. Prim's Algorithm 에 의해 미로를 랜덤으로 생성한다.
- {
- int temp_a, temp_b, done, s_i, s_j, s_k, s_l;
- map[id][0][0] = 1; // 맵 헤더의 랜덤 생성 여부에 체크
- do
- {
- done = 0;
- switch (rand() % 4)
- {
- case 0 : temp_a = ma-1; temp_b = mb; s_i = 1; break;
- case 1 : temp_a = ma; temp_b = mb+1; s_l = 1; break;
- case 2 : temp_a = ma+1; temp_b = mb; s_k = 1; break;
- case 3 : temp_a = ma; temp_b = mb-1; s_j = 1; break;
- }
- if (map[id][temp_a][temp_b] == 1 && wall_list[temp_a][temp_b] != 2)
- {
- if (wall_check(id, temp_a, temp_b, 0) == 3)
- {
- map[id][temp_a][temp_b] = 0;
- wall_list[temp_a][temp_b] = 0;
- ma = temp_a; mb = temp_b;
- wall_check(id,ma,mb,1);
- road (id,ma,mb);
- s_i = 0; s_l = 0; s_k = 0; s_j = 0;
- }
- }
- else if (temp_a != ma && temp_b != mb)
- {
- temp_a = ma; temp_b = mb;
- }
- else
- {
- }
- if (s_i == 1 && s_j == 1 && s_k == 1 && s_l == 1)
- {
- done = 1;
- }
- if (wall_check(id, temp_a, temp_b, 2) != 0)
- {
- done = 1;
- }
- } while (done == 0);
- return 0;
- }
- int move()
- // 플레이어 캐릭터 (@) 의 이동 관련 함수.
- // i : UP, j : LEFT, k : DOWN, l : RIGHT, Q : QUIT 에 대응.
- // 여기선 getch() 를 쓸 수 없으니 scanf("%c", &key); 로 대신한다.
- {
- char key;
- scanf("%c", &key);
- switch ((int)key)
- {
- case 105 :
- paa = pa-1; pbb = pb; break;
- case 106 :
- paa = pa; pbb = pb-1; break;
- case 107 :
- paa = pa+1; pbb = pb; break;
- case 108 :
- paa = pa; pbb = pb+1; break;
- case 81 :
- printf ("Quit\n"); over = 1; break;
- }
- if (map[mapid][paa][pbb] != 1 && paa >= 1 && paa < sizeof(map[0]) / sizeof(map[0][0]) && pbb >= 0 && pbb < sizeof(map[0][0]) / sizeof(map[0][0][0]))
- {
- if (pa != paa || pb != pbb)
- {
- map[mapid][paa][pbb] += 100;
- map[mapid][pa][pb] = map[mapid][pa][pb] % 100;
- }
- pa = paa; pb = pbb;
- }
- else
- {
- printf ("* : can't move\n");
- paa = pa; pbb = pb;
- }
- mapprnt(mapid);
- return 0;
- }
- int enemygen(int id)
- {
- int i, e_pos;
- for (i = 1 ; i < (id + rand() % 4) / 2 ; i++)
- {
- e_pos = road_list[rand() % road_count];
- enemy_list[id][i * 3 - 2] = 1000 + ((id / 2) + (rand() % 3)) * 100; // enemy level
- enemy_list[id][i * 3 - 1] = e_pos / 100;
- enemy_list[id][i * 3 - 0] = e_pos % 100;
- map[id][enemy_list[id][i * 3 - 1]][enemy_list[id][i * 3 - 0]] = enemy_list[id][i * 3 - 2];
- enemy_list[id][0]++;
- }
- return 0;
- }
- int mapgen()
- { // 전체 맵에 대한 생성함수
- int i,j,k;
- int w_i, w_k;
- int m,n;
- int ra, rb;
- int up, dn;
- int up_a, up_b, dn_a, dn_b;
- int mazegen_count;
- int rndmap;
- int totalgen = 0;
- int dmap_id;
- for (i = 0 ; i < sizeof(map) / sizeof(map[0]) ; i++)
- { // 한 개의 맵
- dmap_id = rand() % 8;
- rndmap = rand() % 100;
- for (m = 0 ; m < sizeof(wall_list) / sizeof(wall_list[0]) ; m++)
- {
- for (n = 0 ; n < sizeof(wall_list[0]) / sizeof(wall_list[0][0]) ; n++)
- {
- wall_list[m][n] = 0;
- }
- }
- mazegen_count = 0;
- road_count = 0;
- memset(road_list, 0, sizeof(road_list) / sizeof(road_list[0]));
- if (rndmap < 70)
- {
- for (j = 0 ; j < sizeof(map[0]) / sizeof(map[0][0]) ; j++)
- {
- for (k = 0 ; k < sizeof(map[0][0]) / sizeof(map[0][0][0]) ; k++)
- {
- if (j == 0)
- {
- map[i][j][k] = 0;
- }
- else
- {
- map[i][j][k] = 1;
- }
- }
- }
- maxa = (sizeof(map[0]) / sizeof(map[0][0])) - 1;
- maxb = sizeof(map[0][0]) / sizeof(map[0][0][0]);
- int wmaxa = (sizeof(wall_list) / sizeof(wall_list[0]));
- int wmaxb = sizeof(wall_list[0]) / sizeof(wall_list[0][0]);
- // outer wall을 2로 하여 wall_list에 저장 {
- for (w_k=0 ; w_k<wmaxb ; w_k++)
- {
- wall_list[1][w_k] = 2;
- }
- for (w_i=0 ; w_i<wmaxa ; w_i++)
- {
- wall_list[w_i][0] = 2;
- }
- for (w_k=0 ; w_k<wmaxb ; w_k++)
- {
- wall_list[wmaxa-1][w_k] = 2;
- }
- for (w_i=0 ; w_i<wmaxa ; w_i++)
- {
- wall_list[w_i][wmaxb-1] = 2;
- }
- //}
- ra = rand() % (maxa - 4); rb = rand() % (maxb - 4);
- map[i][ra+2][rb+2] = 0;
- a = ra+2; b = rb+2;
- wall_check(i,a,b,1);
- road(i,a,b);
- mazegen(i,a,b);
- while (road_count < ((maxa-2) * (maxb-2) + 4) / 2 || mazegen_count < (maxa-2 * maxb-2) / 2)
- {
- mazegen(i, road_list[rand() % road_count] / 100, road_list[rand() % road_count] % 100);
- mazegen_count++;
- }
- up = road_list[rand() % road_count];
- dn = road_list[rand() % road_count];
- up_a = up / 100;
- up_b = up % 100;
- dn_a = dn / 100;
- dn_b = dn % 100;
- map[i][up_a][up_b] = 3;
- map[i][dn_a][dn_b] = 4;
- map[i][0][0] = 0;
- map[i][0][1] = dn_a;
- map[i][0][2] = dn_b;
- map[i][0][3] = up_a;
- map[i][0][4] = up_b;
- enemygen(i);
- }
- else if (rndmap >= 70)
- {
- for (j = 0 ; j < sizeof(map[0]) / sizeof(map[0][0]) ; j++)
- {
- for (k = 0 ; k < sizeof(map[0][0]) / sizeof(map[0][0][0]) ; k++)
- {
- map[i][j][k] = designed_map[dmap_id][j][k];
- }
- }
- map[i][0][0] = dmap_id + 1;
- }
- /*printf ("mapid : %d\n", i);
- printf ("road_count : %d\n", road_count);
- totalgen += mazegen_count;
- printf ("totalgen : %d\n", totalgen);
- printf("%d %d %d %d %d\n", map[i][0][0], map[i][0][1], map[i][0][2], map[i][0][3], map[i][0][4]);
- mapp(i,1);*/
- }
- return 0;
- }
- int main(void) {
- srand(time(NULL));
- printf ("== generating map.. == \n");
- mapgen();
- printf ("== complete! == \n");
- mapprnt_s(33,7,7,8);
- mapprnt_s(33,7,7,7);
- mapprnt_s(33,7,9,7);
- mapprnt_s(33,7,13,7);
- mapprnt_s(33,7,16,7);
- mapprnt_s(33,7,18,7);
- mapprnt_s(33,7,18,4);
- mapprnt_s(33,7,18,2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement