! makemaze.inf, a maze generating program ! copyright 1998 by Ricardo Dague constant BUFFERLEN = 120; constant PARSELEN = 64; array buffer string BUFFERLEN; array parse string PARSELEN; global parsenw; constant MAXmaxm = 11; ! these can be any numbers >=1 constant MAXmaxn = 26; array maze -> MAXmaxm*MAXmaxn; global maxm; global maxn; global m; global n; global height; global width; [ Main m1 n1; style bold; print "^^^^MAKEMAZE -- a maze generator ^copyright 1998 by \ Ricardo Dague"; style roman; print "^^Everyone who loves adventure game mazes stand up and \ holler "; style bold; print "HOORAY!"; style roman; print "^^This program generates random mazes and prints out the \ Inform source code for them. They're rectangular and the \ dimensions are adjustable."; print "^^As an example, here's the instructions for making a \ simple game where the player is in a 4x5 maze:"; print "^^Start this program, type ~dim 4 5~ and keep typing ~n~ \ until a map is displayed that looks good to you. Type ~p~ \ and give ~mymaze.h~ as the script file name. After the code \ is printed type ~q~ to quit."; print "^^Then create the main source file for the game, which \ would be something like this"; style fixed; print "^^ constant STORY = ~Maze Game~;"; print "^ constant HEADLINE = ~ -- a wandering@@94~;"; print "^ constant MAX_SCORE = 1;"; print "^ include ~parser~;"; print "^ property desc;"; print "^ include ~verblib~;"; print "^ include ~mazeclas~;"; print "^ include ~mymaze~;"; print "^ object diamond ~DIAMOND~ maze19"; print "^ with name 'diamond',"; print "^ after [; Take: score++; deadflag = 2; ];"; print "^ [ Initialise;"; print "^ location = maze0;"; print "^ ~@@94@@94@@94@@94Let's see... Where did you \ drop that diamond?@@94~;"; print "^ ];"; print "^ include ~grammar~;"; style roman; print "^^Note that all the maze rooms are of class MazeClass for \ which I've made an example definition in the file \ mazeclas.h. The property desc is used by that class. And the \ room maze0 is the upper left (northwest) corner of the maze, \ maze4 is the upper right and maze19 is the lower right."; print "^^I hope you find this useful! Enjoy!"; PressKey(); height = $20->0; width = $21->0; maxm = (height-2)/2; if(maxm > MAXmaxm) maxm = MAXmaxm; maxn = (width-1)/3; if(maxn > MAXmaxn) maxn = MAXmaxn; m = maxm; n = maxn; gen(); for(::) { @split_window height; @set_window 1; @erase_window 1; pr(); @set_cursor 1 1; @erase_line 1; print "print, new, help, quit, or dim 1-",maxm," 1-",maxn,"?"; ! buffer->0 = BUFFERLEN; ! parse->0 = PARSELEN; read buffer parse; parsenw = parse->1; if(parsenw > 0) switch(WordNth(0)) { 'p//','print': prog(); gen(); 'q//','quit': quit; 'n//','new': gen(); 'd//','dim': if(parsenw >= 3) { m1 = NumberNth(1); n1 = NumberNth(2); if(1 <= m1 && m1 <= maxm && 1 <= n1 && n1 <= maxn) { m = m1; n = n1; gen(); } } 'h//','help': @split_window 0; @set_window 0; @erase_window 0; @set_cursor 1 1; print "^These commands can be abbreviated p, n, h, q \ and d."; print "^^PRINT: prints the Inform source code \ corresponding to the maze"; print "^^NEW: generates a new maze"; print "^^HELP: hm..."; print "^^QUIT: quits the program"; print "^^DIM Y X: where Y and X are numbers, generates \ a new maze with those dimensions"; PressKey(); } } ]; [ PressKey ch; print "^[press any key]^"; @read_char 1 -> ch; return ch; ]; [ WordAddr x; return buffer + (parse->(4*x+5)); ]; [ WordLen x; return parse->(4*x+4); ]; [ WordNth x; return parse-->(2*x+1); ]; [ WordStr x n i; n = WordLen(x); x = WordAddr(x); for(i = 0: i < n: i++) print (char)x->i; ]; [ NumberNth x n i y ch; n = WordLen(x); x = WordAddr(x); for(i = 0: i < n: i++) { if(y > 999) return 10000; ch = x->i; if(ch < '0' || '9' < ch) return -1; y = y*10 + ch - '0'; } return y; ]; [ gen ct adj i x; for(i = 0: i < m*n: i++) maze->i = 0; maze->((m/2)*n + n/2) = 4; for(ct = m*n-1: ct > 0: ct--) { do { do x = random(m*n) - 1; until(maze->x == 0); adj = 0; if(x >= n && maze->(x-n) ~= 0) adj = adj | 1; if(x < n*(m-1) && maze->(x+n) ~= 0) adj = adj | 2; if(x%n ~= 0 && maze->(x-1) ~= 0) adj = adj | 4; if(x%n ~= n-1 && maze->(x+1) ~= 0) adj = adj | 8; } until(adj ~= 0); do i = random(1,2,4,8); until(adj&i ~= 0); switch(i) { 1: maze->(x-n) = maze->(x-n) | 1; maze->x = maze->x | 4; 2: maze->x = maze->x | 1; 4: maze->(x-1) = maze->(x-1) | 2; maze->x = maze->x | 4; 8: maze->x = maze->x | 2; } } ]; [ pr i j; @set_cursor 2 1; print "+"; for(j = 0: j < n: j++) print "--+"; print "^"; for(i = 0: i < m: i++) { print "|"; for(j = 0: j < n: j++) { if(maze->(i*n+j) & 2) print " "; else print " |"; } print "^"; print "+"; for(j = 0: j < n: j++) { if(maze->(i*n+j) & 1) print " +"; else print "--+"; } print "^"; } ]; [ prog k; @split_window 0; @set_window 0; @erase_window 0; @output_stream 2; if(0-->8 & 1 == 0) { print "Unable to open script!"; PressKey(); return; } for(k = 0: k < m*n: k++) { print "object maze",k," ~maze",k,"~^"; print "class MazeClass^"; print "with^"; if(k >= n && maze->(k-n)&1) print "n_to maze",k-n,",^"; if(maze->k&1) print "s_to maze",k+n,",^"; if(k%n ~= 0 && maze->(k-1)&2) print "w_to maze",k-1,",^"; if(maze->k&2) print "e_to maze",k+1,",^"; print ";^^"; } @output_stream -2; ];