ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/random_maps/snake.C
(Generate patch)

Comparing deliantra/server/random_maps/snake.C (file contents):
Revision 1.6 by root, Sat Jan 27 02:19:37 2007 UTC vs.
Revision 1.7 by root, Fri Apr 11 21:09:53 2008 UTC

8a char value of 0 represents a blank space: a '#' is 8a char value of 0 represents a blank space: a '#' is
9a wall. 9a wall.
10 10
11*/ 11*/
12 12
13#include <global.h>
14#include "random_map.h"
15#include "rproto.h"
13 16
14#include <stdio.h> 17Maze
15#include <global.h>
16#include <time.h>
17
18
19
20
21char **
22make_snake_layout (int xsize, int ysize, int options) 18make_snake_layout (int xsize, int ysize, int options)
23{ 19{
24 int i, j; 20 int i, j;
25 21
26 /* allocate that array, set it up */ 22 Maze maze (xsize, ysize);
27 char **maze = (char **) calloc (sizeof (char *), xsize);
28
29 for (i = 0; i < xsize; i++)
30 {
31 maze[i] = (char *) calloc (sizeof (char), ysize);
32 }
33 23
34 /* write the outer walls */ 24 /* write the outer walls */
35 for (i = 0; i < xsize; i++) 25 for (i = 0; i < xsize; i++) maze[i][0] = maze[i][ysize - 1] = '#';
36 maze[i][0] = maze[i][ysize - 1] = '#'; 26 for (j = 0; j < ysize; j++) maze[0][j] = maze[xsize - 1][j] = '#';
37 for (j = 0; j < ysize; j++)
38 maze[0][j] = maze[xsize - 1][j] = '#';
39 27
40 /* 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. */
41 if (xsize < 8 || ysize < 8) 29 if (xsize < 8 || ysize < 8)
42 return maze; 30 return maze;
43 31
53 for (i = spacing; i < xsize - 3; i += spacing) 41 for (i = spacing; i < xsize - 3; i += spacing)
54 { 42 {
55 if (orientation) 43 if (orientation)
56 { 44 {
57 for (j = 1; j < ysize - 2; j++) 45 for (j = 1; j < ysize - 2; j++)
58 {
59 maze[i][j] = '#'; 46 maze[i][j] = '#';
60 } 47
61 maze[i][j] = 'D'; 48 maze[i][j] = 'D';
62 } 49 }
63 else 50 else
64 { 51 {
65 for (j = 2; j < ysize; j++) 52 for (j = 2; j < ysize; j++)
66 {
67 maze[i][j] = '#'; 53 maze[i][j] = '#';
68 } 54
69 maze[i][1] = 'D'; 55 maze[i][1] = 'D';
70 } 56 }
57
71 orientation ^= 1; /* toggle the value of orientation */ 58 orientation ^= 1; /* toggle the value of orientation */
72 } 59 }
73 } 60 }
74 else 61 else
75 { /* horizontal orientation */ 62 { /* horizontal orientation */
80 for (i = spacing; i < ysize - 3; i += spacing) 67 for (i = spacing; i < ysize - 3; i += spacing)
81 { 68 {
82 if (orientation) 69 if (orientation)
83 { 70 {
84 for (j = 1; j < xsize - 2; j++) 71 for (j = 1; j < xsize - 2; j++)
85 {
86 maze[j][i] = '#'; 72 maze[j][i] = '#';
87 } 73
88 maze[j][i] = 'D'; 74 maze[j][i] = 'D';
89 } 75 }
90 else 76 else
91 { 77 {
92 for (j = 2; j < xsize; j++) 78 for (j = 2; j < xsize; j++)
93 {
94 maze[j][i] = '#'; 79 maze[j][i] = '#';
95 } 80
96 maze[1][i] = 'D'; 81 maze[1][i] = 'D';
97 } 82 }
83
98 orientation ^= 1; /* toggle the value of orientation */ 84 orientation ^= 1; /* toggle the value of orientation */
99 } 85 }
100 } 86 }
101 87
102 /* place the exit up/down */ 88 /* place the exit up/down */
109 { 95 {
110 maze[1][1] = '>'; 96 maze[1][1] = '>';
111 maze[xsize - 2][ysize - 2] = '<'; 97 maze[xsize - 2][ysize - 2] = '<';
112 } 98 }
113 99
114
115 return maze; 100 return maze;
116} 101}
102

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines