… | |
… | |
12 | |
12 | |
13 | #include <global.h> |
13 | #include <global.h> |
14 | #include "random_map.h" |
14 | #include "random_map.h" |
15 | #include "rproto.h" |
15 | #include "rproto.h" |
16 | |
16 | |
17 | Maze |
17 | void |
18 | make_snake_layout (int xsize, int ysize, int options) |
18 | make_snake_layout (Layout maze, int options) |
19 | { |
19 | { |
20 | int i, j; |
20 | int i, j; |
21 | |
21 | |
22 | Maze maze (xsize, ysize); |
22 | maze->clear (); |
|
|
23 | maze->border (); |
23 | |
24 | |
24 | /* write the outer walls */ |
25 | int xsize = maze->w; |
25 | for (i = 0; i < xsize; i++) maze[i][0] = maze[i][ysize - 1] = '#'; |
26 | int ysize = maze->h; |
26 | for (j = 0; j < ysize; j++) maze[0][j] = maze[xsize - 1][j] = '#'; |
|
|
27 | |
27 | |
28 | /* Bail out if the size is too small to make a snake. */ |
28 | /* Bail out if the size is too small to make a snake. */ |
29 | if (xsize < 8 || ysize < 8) |
29 | if (xsize < 8 || ysize < 8) |
30 | return maze; |
30 | return; |
31 | |
31 | |
32 | /* decide snake orientation--vertical or horizontal , and |
32 | /* decide snake orientation--vertical or horizontal , and |
33 | make the walls and place the doors. */ |
33 | make the walls and place the doors. */ |
34 | |
34 | |
35 | if (rndm (2)) |
35 | if (rmg_rndm (2)) |
36 | { /* vertical orientation */ |
36 | { /* vertical orientation */ |
37 | int n_walls = rndm (xsize - 5) / 3 + 1; |
37 | int n_walls = rmg_rndm (xsize - 5) / 3 + 1; |
38 | int spacing = xsize / (n_walls + 1); |
38 | int spacing = xsize / (n_walls + 1); |
39 | int orientation = 1; |
39 | int orientation = 1; |
40 | |
40 | |
41 | for (i = spacing; i < xsize - 3; i += spacing) |
41 | for (i = spacing; i < xsize - 3; i += spacing) |
42 | { |
42 | { |
… | |
… | |
58 | orientation ^= 1; /* toggle the value of orientation */ |
58 | orientation ^= 1; /* toggle the value of orientation */ |
59 | } |
59 | } |
60 | } |
60 | } |
61 | else |
61 | else |
62 | { /* horizontal orientation */ |
62 | { /* horizontal orientation */ |
63 | int n_walls = rndm (ysize - 5) / 3 + 1; |
63 | int n_walls = rmg_rndm (ysize - 5) / 3 + 1; |
64 | int spacing = ysize / (n_walls + 1); |
64 | int spacing = ysize / (n_walls + 1); |
65 | int orientation = 1; |
65 | int orientation = 1; |
66 | |
66 | |
67 | for (i = spacing; i < ysize - 3; i += spacing) |
67 | for (i = spacing; i < ysize - 3; i += spacing) |
68 | { |
68 | { |
… | |
… | |
84 | orientation ^= 1; /* toggle the value of orientation */ |
84 | orientation ^= 1; /* toggle the value of orientation */ |
85 | } |
85 | } |
86 | } |
86 | } |
87 | |
87 | |
88 | /* place the exit up/down */ |
88 | /* place the exit up/down */ |
89 | if (rndm (2)) |
89 | if (rmg_rndm (2)) |
90 | { |
90 | { |
91 | maze[1][1] = '<'; |
91 | maze[1][1] = '<'; |
92 | maze[xsize - 2][ysize - 2] = '>'; |
92 | maze[xsize - 2][ysize - 2] = '>'; |
93 | } |
93 | } |
94 | else |
94 | else |
95 | { |
95 | { |
96 | maze[1][1] = '>'; |
96 | maze[1][1] = '>'; |
97 | maze[xsize - 2][ysize - 2] = '<'; |
97 | maze[xsize - 2][ysize - 2] = '<'; |
98 | } |
98 | } |
99 | |
|
|
100 | return maze; |
|
|
101 | } |
99 | } |
102 | |
100 | |