… | |
… | |
59 | it also starts from cx and cy. */ |
59 | it also starts from cx and cy. */ |
60 | |
60 | |
61 | void |
61 | void |
62 | find_top_left_corner (char **maze, int *cx, int *cy) |
62 | find_top_left_corner (char **maze, int *cx, int *cy) |
63 | { |
63 | { |
|
|
64 | --(*cy); |
64 | |
65 | |
65 | (*cy)--; |
|
|
66 | /* find the top wall. */ |
66 | /* find the top wall. */ |
67 | while (maze[*cx][*cy] == 0) |
67 | while (maze[*cx][*cy] == 0) |
68 | (*cy)--; |
68 | --(*cy); |
|
|
69 | |
69 | /* proceed right until a corner is detected */ |
70 | /* proceed right until a corner is detected */ |
70 | while (maze[*cx][*cy + 1] == 0) |
71 | while (maze[*cx][*cy + 1] == 0) |
71 | (*cx)++; |
72 | ++(*cx); |
72 | |
73 | |
73 | /* cx and cy should now be the top-right corner of the onion layer */ |
74 | /* cx and cy should now be the top-right corner of the onion layer */ |
74 | } |
75 | } |
75 | |
76 | |
76 | |
77 | |
… | |
… | |
87 | /* find the layout center. */ |
88 | /* find the layout center. */ |
88 | cx = 0; |
89 | cx = 0; |
89 | cy = 0; |
90 | cy = 0; |
90 | for (i = 0; i < xsize; i++) |
91 | for (i = 0; i < xsize; i++) |
91 | for (j = 0; j < ysize; j++) |
92 | for (j = 0; j < ysize; j++) |
92 | { |
|
|
93 | if (maze[i][j] == 'C') |
93 | if (maze[i][j] == 'C') |
94 | { |
94 | { |
95 | cx = i; |
95 | cx = i; |
96 | cy = j; |
96 | cy = j; |
97 | } |
97 | } |
98 | } |
98 | |
99 | tx = cx; |
99 | tx = cx; |
100 | ty = cy; |
100 | ty = cy; |
101 | while (1) |
101 | for (;;) |
102 | { |
102 | { |
103 | find_top_left_corner (maze, &tx, &ty); |
103 | find_top_left_corner (maze, &tx, &ty); |
104 | |
104 | |
105 | if (ty < 2 || tx < 2 || tx > xsize - 2 || ty > ysize - 2) |
105 | if (ty < 2 || tx < 2 || tx > xsize - 2 || ty > ysize - 2) |
106 | break; |
106 | break; |
|
|
107 | |
107 | make_wall (maze, tx, ty - 1, 1); /* make a vertical wall with a door */ |
108 | make_wall (maze, tx, ty - 1, 1); /* make a vertical wall with a door */ |
108 | |
109 | |
109 | maze[tx][ty - 1] = '#'; /* convert the door that make_wall puts here to a wall */ |
110 | maze[tx][ty - 1] = '#'; /* convert the door that make_wall puts here to a wall */ |
110 | maze[tx - 1][ty] = 'D'; /* make a doorway out of this layer */ |
111 | maze[tx - 1][ty] = 'D'; /* make a doorway out of this layer */ |
111 | |
112 | |
… | |
… | |
142 | maze[xsize - 2][1] = '>'; |
143 | maze[xsize - 2][1] = '>'; |
143 | } |
144 | } |
144 | |
145 | |
145 | return maze; |
146 | return maze; |
146 | } |
147 | } |
|
|
148 | |